@aomex/console
Advanced tools
Comparing version 0.0.16 to 0.0.17
# @aomex/console | ||
## 0.0.17 | ||
### Patch Changes | ||
- [`eb6b156`](https://github.com/aomex/aomex/commit/eb6b156f19ee59f94cab8f2e364abc7af84524b2) Thanks [@geekact](https://github.com/geekact)! - feat(console)!: load cli entry from aomex.json | ||
## 0.0.16 | ||
@@ -4,0 +10,0 @@ |
@@ -1,1 +0,1 @@ | ||
#!/usr/bin/env -S ts-node-esm --transpileOnly --experimentalSpecifierResolution=node | ||
#!/usr/bin/env node |
@@ -1,11 +0,14 @@ | ||
#!/usr/bin/env -S ts-node-esm --transpileOnly --experimentalSpecifierResolution=node | ||
#!/usr/bin/env node | ||
// src/bin.ts | ||
import path from "node:path"; | ||
import { pathToFileURL } from "node:url"; | ||
import { existsSync, statSync, writeFileSync } from "node:fs"; | ||
import path, { basename } from "node:path"; | ||
import { fileURLToPath, pathToFileURL } from "node:url"; | ||
import { existsSync, readFileSync, statSync, writeFileSync } from "node:fs"; | ||
import { hideBin } from "yargs/helpers"; | ||
import { chalk, fileToModules, pathToFiles } from "@aomex/utility"; | ||
import { chalk } from "@aomex/utility"; | ||
import { spawnSync } from "node:child_process"; | ||
var configFile = path.resolve("aomex.json"); | ||
{ | ||
const defaultConfig = { | ||
$schema: "./node_modules/@aomex/console/config.json", | ||
cliEntry: { | ||
@@ -18,4 +21,3 @@ production: "./src/cli.js", | ||
if (args.length === 1 && args[0] === "--init") { | ||
const file = path.resolve("aomex.config.ts"); | ||
if (existsSync(file)) { | ||
if (existsSync(configFile)) { | ||
console.warn( | ||
@@ -26,11 +28,5 @@ chalk.yellow("Your configuration file had been generated already!") | ||
} | ||
writeFileSync( | ||
file, | ||
`import { defineConfig } from '@aomex/console'; | ||
export default defineConfig(${JSON.stringify(defaultConfig, null, 2)}); | ||
` | ||
); | ||
writeFileSync(configFile, JSON.stringify(defaultConfig, null, 2) + "\n"); | ||
console.info( | ||
"Configuration file has been generated successfully: " + chalk.blueBright(file) | ||
"Configuration file has been generated successfully: " + chalk.blueBright(configFile) | ||
); | ||
@@ -40,27 +36,7 @@ process.exit(0); | ||
} | ||
var env = process.env["NODE_ENV"] || "development"; | ||
var parseEnv = (config2) => { | ||
if (!config2) | ||
return null; | ||
if (Object.hasOwn(config2, env)) | ||
return config2[env]; | ||
if (Object.hasOwn(config2, "default")) | ||
return config2["default"]; | ||
return null; | ||
}; | ||
var files = await pathToFiles("./aomex.config{.ts,.js}"); | ||
var config; | ||
for (const file of files) { | ||
const configs = await fileToModules( | ||
[file], | ||
(item) => typeof item === "object" | ||
); | ||
if (configs.length) { | ||
config = configs[0]; | ||
break; | ||
} | ||
} | ||
if (!config) { | ||
if (!existsSync(configFile)) { | ||
console.error( | ||
`Aomex doesn't find a configuration file matched pattern "aomex.config.{ts|js}", would you please execute the initialize command below at first? | ||
`Unable to find configuration file "${chalk.bold( | ||
basename(configFile) | ||
)}", consider to execute the command below to initialize it. | ||
@@ -74,11 +50,43 @@ ${chalk.greenBright( | ||
} | ||
var config = JSON.parse(readFileSync(configFile, "utf8")); | ||
var env = process.env["NODE_ENV"] || "development"; | ||
var parseEnv = (sub) => { | ||
if (!sub) | ||
return null; | ||
if (Object.hasOwn(sub, env)) | ||
return sub[env]; | ||
if (Object.hasOwn(sub, "default")) | ||
return sub["default"]; | ||
return null; | ||
}; | ||
var cliEntry = parseEnv(config.cliEntry) || ""; | ||
if (cliEntry) { | ||
cliEntry = path.resolve(cliEntry); | ||
} | ||
cliEntry &&= path.resolve(cliEntry); | ||
if (!cliEntry || !statSync(cliEntry).isFile()) { | ||
console.error(`The given entry file "${cliEntry}" is not found`); | ||
console.error(`Given entry file "${cliEntry}" is empty or not a file.`); | ||
process.exit(1); | ||
} | ||
await import(pathToFileURL(cliEntry).toString()); | ||
if (cliEntry.endsWith("js")) { | ||
await import(pathToFileURL(cliEntry).toString()); | ||
} else { | ||
const tsNodeEsm = path.join( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
"../node_modules/ts-node/esm/transpile-only.mjs" | ||
); | ||
spawnSync( | ||
process.argv0, | ||
[ | ||
"--experimental-specifier-resolution", | ||
"node", | ||
"--loader", | ||
tsNodeEsm, | ||
"--no-warnings", | ||
cliEntry, | ||
...hideBin(process.argv) | ||
], | ||
{ | ||
stdio: "inherit", | ||
env: process.env | ||
} | ||
); | ||
} | ||
//# sourceMappingURL=bin.js.map |
@@ -135,18 +135,2 @@ import { Chain, PureMiddlewareToken, Next, Middleware, Validator } from '@aomex/core'; | ||
interface Config { | ||
cliEntry: { | ||
/** | ||
* Entry file by each environment | ||
* @see process.env.NODE_ENV | ||
*/ | ||
[NODE_ENV: string]: string | undefined; | ||
/** | ||
* Fallback to `default` if NODE_ENV doesn't match specific file. | ||
* @see process.env.NODE_ENV | ||
*/ | ||
default?: string; | ||
}; | ||
} | ||
declare const defineConfig: (config: Config) => Config; | ||
export { Config, ConsoleApp, ConsoleAppOption, ConsoleChain, ConsoleContext, ConsoleMiddleware, ConsoleMiddlewareToken, ConsoleOptionMiddleware, ConsoleRequest, ConsoleResponse, HelpMiddleware, YargsInstance, defineConfig, options, scriptName, version }; | ||
export { ConsoleApp, ConsoleAppOption, ConsoleChain, ConsoleContext, ConsoleMiddleware, ConsoleMiddlewareToken, ConsoleOptionMiddleware, ConsoleRequest, ConsoleResponse, HelpMiddleware, YargsInstance, options, scriptName, version }; |
@@ -10,3 +10,3 @@ // src/override/middleware.ts | ||
// src/meta.ts | ||
var version = "0.0.16"; | ||
var version = "0.0.17"; | ||
var scriptName = "aomex"; | ||
@@ -254,5 +254,2 @@ | ||
var options = (fields, alias) => new ConsoleOptionMiddleware(fields, alias); | ||
// src/define-config.ts | ||
var defineConfig = (config) => config; | ||
export { | ||
@@ -267,3 +264,2 @@ ConsoleApp, | ||
HelpMiddleware, | ||
defineConfig, | ||
options, | ||
@@ -270,0 +266,0 @@ scriptName, |
{ | ||
"name": "@aomex/console", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "", | ||
@@ -22,2 +22,3 @@ "type": "module", | ||
"dist", | ||
"config.json", | ||
"LICENSE", | ||
@@ -24,0 +25,0 @@ "package.json", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11
41035
512
4