@nsis/dent-cli 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/bin/cli.d.mts +1 -0
- package/bin/cli.mjs +6 -88
- package/package.json +51 -62
- package/index.mjs +0 -3
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
> An opinionated code formatter for NSIS scripts
|
|
4
4
|
|
|
5
5
|
[](https://github.com/idleberg/node-dent-cli/blob/main/LICENSE)
|
|
6
|
-
[](https://www.npmjs.org/package/@nsis/dent-cli)
|
|
7
7
|
[](https://github.com/idleberg/node-dent-cli/actions)
|
|
8
8
|
|
|
9
9
|
## Prerequisites
|
|
10
10
|
|
|
11
|
-
This is a TypeScript
|
|
11
|
+
This is a TypeScript application that depends on a [NodeJS](https://nodejs.org) runtime installed on your computer.
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
package/bin/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/bin/cli.mjs
CHANGED
|
@@ -1,88 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { fileURLToPath }
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import logSymbols from 'log-symbols';
|
|
8
|
-
import colors from 'picocolors';
|
|
9
|
-
|
|
10
|
-
await main();
|
|
11
|
-
async function main() {
|
|
12
|
-
const program = new Command();
|
|
13
|
-
const version = await getVersion();
|
|
14
|
-
program
|
|
15
|
-
.version(version)
|
|
16
|
-
.description('CLI tool to format NSIS scripts')
|
|
17
|
-
.arguments('<file...>')
|
|
18
|
-
.option('--eol <"crlf"|"lf">', 'control how line-breaks are represented', value => ['crlf', 'lf'].includes(value))
|
|
19
|
-
.option('-i, --indent-size <number>', 'number of units per indentation level', value => parseInt(value, 10), 2)
|
|
20
|
-
.option('-s, --use-spaces', 'indent with spaces instead of tabs', false)
|
|
21
|
-
.option('--trim', 'trim empty lines', true)
|
|
22
|
-
.option('--write', 'edit files in-place', false)
|
|
23
|
-
.option('--quiet', 'suppress output', false)
|
|
24
|
-
.option('--debug', 'prints additional debug messages', false)
|
|
25
|
-
.parse(process.argv);
|
|
26
|
-
const options = program.opts();
|
|
27
|
-
const args = Array.isArray(program.args)
|
|
28
|
-
? program.args
|
|
29
|
-
: [program.args];
|
|
30
|
-
if (!args.length) {
|
|
31
|
-
program.help();
|
|
32
|
-
}
|
|
33
|
-
if (options.debug) {
|
|
34
|
-
console.log('\nCLI parameters:', { args, options });
|
|
35
|
-
}
|
|
36
|
-
const format = createFormatter({
|
|
37
|
-
endOfLines: options.eol,
|
|
38
|
-
indentSize: options.indent,
|
|
39
|
-
trimEmptyLines: options.trim,
|
|
40
|
-
useTabs: !options.useSpaces
|
|
41
|
-
});
|
|
42
|
-
const files = await glob(args);
|
|
43
|
-
const isVerbose = options.write && !options.quiet;
|
|
44
|
-
if (isVerbose && !options.debug) {
|
|
45
|
-
console.log( /* let it breathe */);
|
|
46
|
-
}
|
|
47
|
-
console.time('\nCompleted');
|
|
48
|
-
await Promise.all(files.map(async (file) => {
|
|
49
|
-
if (isVerbose) {
|
|
50
|
-
console.time(`${logSymbols.success} ${colors.blue(file)}`);
|
|
51
|
-
}
|
|
52
|
-
const rawContents = (await promises.readFile(file)).toString();
|
|
53
|
-
const formattedContents = format(rawContents);
|
|
54
|
-
if (options.debug) {
|
|
55
|
-
console.log('\nConversion:', {
|
|
56
|
-
raw: rawContents,
|
|
57
|
-
formatted: formattedContents
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (options.write) {
|
|
61
|
-
try {
|
|
62
|
-
await promises.writeFile(file, formattedContents, {
|
|
63
|
-
encoding: 'utf-8'
|
|
64
|
-
});
|
|
65
|
-
if (isVerbose) {
|
|
66
|
-
console.timeEnd(`${logSymbols.success} ${colors.blue(file)}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
if (isVerbose) {
|
|
71
|
-
console.error(`${logSymbols.error} ${colors.blue(file)}\n${colors.dim(error instanceof Error ? error.message : error)}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
console.log(formattedContents);
|
|
77
|
-
}
|
|
78
|
-
}));
|
|
79
|
-
if (isVerbose) {
|
|
80
|
-
console.timeEnd(`\nCompleted`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async function getVersion() {
|
|
84
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
85
|
-
const __dirname = dirname(__filename);
|
|
86
|
-
const { version } = JSON.parse(await promises.readFile(resolve(__dirname, '../package.json'), 'utf8'));
|
|
87
|
-
return version || 'dev';
|
|
88
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{promises as e}from"node:fs";import{dirname as t,resolve as n}from"node:path";import{fileURLToPath as r}from"node:url";import{createFormatter as i}from"@nsis/dent";import{Command as a}from"commander";import{glob as o}from"glob";import s from"log-symbols";import c from"picocolors";await l();async function l(){let t=new a,n=await u();t.version(n).description(`CLI tool to format NSIS scripts`).arguments(`<file...>`).option(`--eol <"crlf"|"lf">`,`control how line-breaks are represented`,e=>{if(![`crlf`,`lf`].includes(e))throw Error(`Invalid value for --eol: "${e}". Expected "crlf" or "lf".`);return e}).option(`-i, --indent-size <number>`,`number of units per indentation level`,e=>Number.parseInt(e,10),2).option(`-s, --use-spaces`,`indent with spaces instead of tabs`,!1).option(`--trim`,`trim empty lines`,!0).option(`--write`,`edit files in-place`,!1).option(`--quiet`,`suppress output`,!1).option(`--debug`,`prints additional debug messages`,!1).parse(process.argv);let r=t.opts(),l=Array.isArray(t.args)?t.args:[t.args];l.length||t.help(),r.debug&&console.log(`
|
|
3
|
+
CLI parameters:`,{args:l,options:r});let d=i({endOfLines:r.eol,indentSize:r.indentSize,trimEmptyLines:r.trim,useTabs:!r.useSpaces}),f=await o(l),p=r.write&&!r.quiet;p&&!r.debug&&console.log(),console.time(`
|
|
4
|
+
Completed`),await Promise.all(f.map(async t=>{p&&console.time(`${s.success} ${c.blue(t)}`);let n=(await e.readFile(t)).toString(),i=d(n);if(r.debug&&console.log(`
|
|
5
|
+
Conversion:`,{raw:n,formatted:i}),r.write)try{await e.writeFile(t,i,{encoding:`utf-8`}),p&&console.timeEnd(`${s.success} ${c.blue(t)}`)}catch(e){p&&console.error(`${s.error} ${c.blue(t)} ${e instanceof Error?e.message:String(e)}`)}else console.log(i)})),p&&console.timeEnd(`
|
|
6
|
+
Completed`)}async function u(){let i=t(r(import.meta.url)),{version:a}=JSON.parse(await e.readFile(n(i,`../package.json`),`utf8`));return a||`dev`}export{};
|
package/package.json
CHANGED
|
@@ -1,63 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"husky": "^8.0.3",
|
|
54
|
-
"lint-staged": "^13.2.3",
|
|
55
|
-
"npm-run-all2": "^6.0.6",
|
|
56
|
-
"rollup": "^3.26.2",
|
|
57
|
-
"tslib": "^2.6.0",
|
|
58
|
-
"typescript": "^5.1.6"
|
|
59
|
-
},
|
|
60
|
-
"lint-staged": {
|
|
61
|
-
"*.(json|ts)": "eslint --cache --fix"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
2
|
+
"name": "@nsis/dent-cli",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "An opinionated code formatter for NSIS scripts",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"bin/",
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"bin": {
|
|
13
|
+
"dent": "./bin/cli.mjs"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20.0.0"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/idleberg/node-dent-cli.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"nsis",
|
|
24
|
+
"formatter"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@nsis/dent": "^0.4.1",
|
|
28
|
+
"commander": "^14.0.3",
|
|
29
|
+
"glob": "^13.0.6",
|
|
30
|
+
"log-symbols": "^7.0.1",
|
|
31
|
+
"picocolors": "^1.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@idleberg/configs": "^0.4.2",
|
|
35
|
+
"@types/node": "^18.19.3",
|
|
36
|
+
"concurrently": "^9.2.1",
|
|
37
|
+
"np": "^11.0.2",
|
|
38
|
+
"tsdown": "^0.20.3",
|
|
39
|
+
"typescript": "^5.3.3"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsdown",
|
|
43
|
+
"dev": "tsdown --watch",
|
|
44
|
+
"lint": "concurrently --prefix-colors blue,green,magenta npm:lint:*",
|
|
45
|
+
"lint:biome": "biome check",
|
|
46
|
+
"lint:e18e": "e18e-cli analyze",
|
|
47
|
+
"publish:jsr": "deno publish",
|
|
48
|
+
"publish:npm": "np",
|
|
49
|
+
"start": "npm run build -- --watch",
|
|
50
|
+
"test": "echo \"Tests pending\" && exit 0"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/index.mjs
DELETED