@nsis/dent-cli 0.1.1 → 0.2.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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > An opinionated code formatter for NSIS scripts
4
4
 
5
5
  [![License](https://img.shields.io/github/license/idleberg/node-dent-cli?color=blue&style=for-the-badge)](https://github.com/idleberg/node-dent-cli/blob/main/LICENSE)
6
- [![npm](https://img.shields.io/npm/v/@nsis/dent-cli?style=for-the-badge)](https://www.npmjs.org/package/@nsis/dent-cli)
6
+ [![Version](https://img.shields.io/npm/v/@nsis/dent-cli?style=for-the-badge)](https://www.npmjs.org/package/@nsis/dent-cli)
7
7
  [![Build](https://img.shields.io/github/actions/workflow/status/idleberg/node-dent-cli/default.yml?style=for-the-badge)](https://github.com/idleberg/node-dent-cli/actions)
8
8
 
9
9
  ## Prerequisites
package/bin/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/bin/cli.js ADDED
@@ -0,0 +1,15 @@
1
+ import { Command } from 'commander';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { dirname, resolve } from 'node:path';
4
+ import { promises } from 'node:fs';
5
+ import { createFormatter } from '@nsis/dent';
6
+ import { glob } from 'glob';
7
+ import l from 'log-symbols';
8
+ import r from 'picocolors';
9
+
10
+ await C();async function C(){let t=new Command,n=await S();t.version(n).description("CLI tool to format NSIS scripts").arguments("<file...>").option('--eol <"crlf"|"lf">',"control how line-breaks are represented",o=>["crlf","lf"].includes(o)).option("-i, --indent-size <number>","number of units per indentation level",o=>parseInt(o,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 e=t.opts(),i=Array.isArray(t.args)?t.args:[t.args];i.length||t.help(),e.debug&&console.log(`
11
+ CLI parameters:`,{args:i,options:e});let f=createFormatter({endOfLines:e.eol,indentSize:e.indent,trimEmptyLines:e.trim,useTabs:!e.useSpaces}),d=await glob(i),s=e.write&&!e.quiet;s&&!e.debug&&console.log(),console.time(`
12
+ Completed`),await Promise.all(d.map(async o=>{s&&console.time(`${l.success} ${r.blue(o)}`);let p=(await promises.readFile(o)).toString(),a=f(p);if(e.debug&&console.log(`
13
+ Conversion:`,{raw:p,formatted:a}),e.write)try{await promises.writeFile(o,a,{encoding:"utf-8"}),s&&console.timeEnd(`${l.success} ${r.blue(o)}`);}catch(m){s&&console.error(`${l.error} ${r.blue(o)}
14
+ ${r.dim(m instanceof Error?m.message:m)}`);}else console.log(a);})),s&&console.timeEnd(`
15
+ Completed`);}async function S(){let t=fileURLToPath(import.meta.url),n=dirname(t),{version:e}=JSON.parse(await promises.readFile(resolve(n,"../package.json"),"utf8"));return e||"dev"}
package/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import './bin/cli.mjs';
3
+ import './bin/cli.js';
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@nsis/dent-cli",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "An opinionated code formatter for NSIS scripts",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
- "build": "rollup --config",
7
+ "build": "tsup",
8
8
  "dev": "npm run start",
9
9
  "fix": "eslint --fix ./src",
10
10
  "lint:json": "eslint ./*.json --ignore-path .gitignore",
@@ -21,11 +21,12 @@
21
21
  "README.md"
22
22
  ],
23
23
  "type": "module",
24
+ "typings": "bin/cli.d.ts",
24
25
  "bin": {
25
26
  "dent": "index.mjs"
26
27
  },
27
28
  "engines": {
28
- "node": "^14.13.1 || >=16.0.0"
29
+ "node": ">=18.0.0"
29
30
  },
30
31
  "repository": {
31
32
  "type": "git",
@@ -36,27 +37,24 @@
36
37
  "formatter"
37
38
  ],
38
39
  "dependencies": {
39
- "@nsis/dent": "^0.2.2",
40
- "commander": "^10.0.1",
41
- "glob": "^10.2.6",
42
- "log-symbols": "^5.1.0",
40
+ "@nsis/dent": "^0.4.1",
41
+ "commander": "^11.1.0",
42
+ "glob": "^10.3.10",
43
+ "log-symbols": "^6.0.0",
43
44
  "picocolors": "^1.0.0"
44
45
  },
45
46
  "devDependencies": {
46
- "@rollup/plugin-commonjs": "^25.0.0",
47
- "@rollup/plugin-json": "^6.0.0",
48
- "@rollup/plugin-typescript": "^11.1.1",
49
- "@types/node": "^20.2.3",
50
- "@typescript-eslint/eslint-plugin": "^5.59.6",
51
- "@typescript-eslint/parser": "^5.59.6",
52
- "eslint": "^8.41.0",
47
+ "@types/node": "^18.19.3",
48
+ "@typescript-eslint/eslint-plugin": "^6.16.0",
49
+ "@typescript-eslint/parser": "^6.16.0",
50
+ "eslint": "^8.56.0",
53
51
  "eslint-plugin-json": "^3.1.0",
54
52
  "husky": "^8.0.3",
55
- "lint-staged": "^13.2.2",
56
- "npm-run-all2": "^6.0.5",
57
- "rollup": "^3.23.0",
58
- "tslib": "^2.5.2",
59
- "typescript": "^5.0.4"
53
+ "lint-staged": "^15.2.0",
54
+ "npm-run-all2": "^6.1.1",
55
+ "tslib": "^2.6.2",
56
+ "tsup": "^8.0.1",
57
+ "typescript": "^5.3.3"
60
58
  },
61
59
  "lint-staged": {
62
60
  "*.(json|ts)": "eslint --cache --fix"
package/bin/cli.mjs DELETED
@@ -1,88 +0,0 @@
1
- import { Command } from 'commander';
2
- import { fileURLToPath } from 'node:url';
3
- import { dirname, resolve } from 'node:path';
4
- import { promises } from 'node:fs';
5
- import { Dent } from '@nsis/dent';
6
- import { glob } from 'glob';
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 dent = new Dent({
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 = dent.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
- }