Comparing version 2.0.0 to 2.1.0
46
cli.js
@@ -5,11 +5,22 @@ #!/usr/bin/env node | ||
const { load } = require("./index.js"); | ||
const { load, watch } = require("./index.js"); | ||
const { inspect } = require("util"); | ||
const { stdout } = process; | ||
function print(config) { | ||
stdout.write( | ||
inspect(config, { | ||
colors: true, | ||
depth: Infinity, | ||
sorted: true, | ||
}) | ||
); | ||
stdout.write("\n"); | ||
} | ||
async function main(args) { | ||
const { stdout } = process; | ||
if (args.length === 0 || args.some((_) => _ === "-h" || _ === "--help")) { | ||
const { name, version } = require("./package.json"); | ||
return stdout.write(`Usage: ${name} <appName> [<appDir>] | ||
return stdout.write(`Usage: ${name} [--watch | -w] <appName> [<appDir>] | ||
@@ -20,13 +31,24 @@ ${name} v${version} | ||
const watchChanges = args[0] === "--watch" || args[0] === "-w"; | ||
if (watchChanges) { | ||
args.shift(); | ||
} | ||
const [appName, appDir] = args; | ||
stdout.write( | ||
inspect(await load(appName, { appDir, ignoreUnknownFormats: true }), { | ||
colors: true, | ||
depth: Infinity, | ||
sorted: true, | ||
}) | ||
); | ||
stdout.write("\n"); | ||
const opts = { appDir, appName, ignoreUnknownFormats: true }; | ||
if (watchChanges) { | ||
await watch(opts, (error, config) => { | ||
console.log("--", new Date()); | ||
if (error !== undefined) { | ||
console.warn(error); | ||
return; | ||
} | ||
print(config); | ||
}); | ||
} else { | ||
print(await load(appName, opts)); | ||
} | ||
} | ||
main(process.argv.slice(2)).catch(console.error.bind(console, "FATAL:")); |
@@ -96,2 +96,10 @@ "use strict"; | ||
entries.forEach((entry) => { | ||
// vendor config should not change and is therefore not watched | ||
// | ||
// otherwise it could interfere if the program is running during | ||
// uninstall/reinstall | ||
if (entry.name === "vendor") { | ||
return; | ||
} | ||
const dirFn = entry.dir; | ||
@@ -98,0 +106,0 @@ const dir = typeof dirFn === "function" ? dirFn(entryOpts) : dirFn; |
{ | ||
"name": "app-conf", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"license": "ISC", | ||
@@ -5,0 +5,0 @@ "author": "Julien Fontanet <julien.fontanet@isonoe.net> (http://julien.isonoe.net/)", |
@@ -28,2 +28,5 @@ # app-conf | ||
// equivalent of `__dirname` for ECMAScript Modules: | ||
//appDir: new URL('.', import.meta.url).pathname, | ||
// default config values | ||
@@ -87,2 +90,4 @@ defaults: {}, | ||
> Note: the vendor config IS NOT watched, but it's loaded as expected. | ||
### CLI | ||
@@ -94,3 +99,3 @@ | ||
> ./node_modules/.bin/app-conf | ||
Usage: app-conf <appName> [<appDir>] | ||
Usage: app-conf [--watch | -w] <appName> [<appDir>] | ||
@@ -97,0 +102,0 @@ app-conf v1.0.0 |
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
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
16831
374
119