@nsis/dent-cli 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Jan T. Sott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @nsis/dent-cli
2
+
3
+ > An opinionated code formatter for NSIS scripts
4
+
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)
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
+
9
+ ## Prerequisites
10
+
11
+ This is a TypeScript applicaiton that dependes on a [NodeJS](https://nodejs.org) runtime installed on your computer.
12
+
13
+ ## Usage
14
+
15
+ ### Installation
16
+
17
+ You could install the `dent` CLI globally
18
+
19
+ ```sh
20
+ $ npm install --global @nsis/dent-cli`
21
+ $ dent --help
22
+ ```
23
+
24
+ ### Single use
25
+
26
+ Download and execute the latest version using [`npx`](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b).
27
+
28
+ ```sh
29
+ $ npx dent --help
30
+ ```
31
+
32
+ ## Related
33
+
34
+ - [`dent` Library](https://www.npmjs.com/package/@nsis/dent)
35
+
36
+ ## License
37
+
38
+ This work is licensed under [The MIT License](LICENSE)
39
+
package/bin/cli.mjs ADDED
@@ -0,0 +1,88 @@
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
+ }
package/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import './bin/cli.mjs';
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@nsis/dent-cli",
3
+ "version": "0.1.0",
4
+ "description": "An opinionated code formatter for NSIS scripts",
5
+ "license": "MIT",
6
+ "scripts": {
7
+ "build": "rollup --config",
8
+ "dev": "npm run start",
9
+ "fix": "eslint --fix ./src",
10
+ "lint:json": "eslint ./*.json --ignore-path .gitignore",
11
+ "lint:ts": "eslint ./src --ignore-path .gitignore",
12
+ "lint": "npm-run-all --parallel lint:*",
13
+ "prepack": "npm run build",
14
+ "start": "npm run build -- --watch",
15
+ "prepare": "husky install"
16
+ },
17
+ "files": [
18
+ "bin/",
19
+ "LICENSE",
20
+ "README.md"
21
+ ],
22
+ "type": "module",
23
+ "bin": {
24
+ "dent": "index.mjs"
25
+ },
26
+ "engines": {
27
+ "node": "^14.13.1 || >=16.0.0"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/idleberg/node-dent.git"
32
+ },
33
+ "keywords": [
34
+ "nsis",
35
+ "formatter"
36
+ ],
37
+ "dependencies": {
38
+ "@nsis/dent": "^0.2.0",
39
+ "commander": "^10.0.1",
40
+ "glob": "^10.2.6",
41
+ "log-symbols": "^5.1.0",
42
+ "picocolors": "^1.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@rollup/plugin-commonjs": "^25.0.0",
46
+ "@rollup/plugin-json": "^6.0.0",
47
+ "@rollup/plugin-typescript": "^11.1.1",
48
+ "@types/node": "^20.2.3",
49
+ "@typescript-eslint/eslint-plugin": "^5.59.6",
50
+ "@typescript-eslint/parser": "^5.59.6",
51
+ "eslint": "^8.41.0",
52
+ "eslint-plugin-json": "^3.1.0",
53
+ "husky": "^8.0.3",
54
+ "lint-staged": "^13.2.2",
55
+ "npm-run-all2": "^6.0.5",
56
+ "rollup": "^3.23.0",
57
+ "tslib": "^2.5.2",
58
+ "typescript": "^5.0.4"
59
+ },
60
+ "lint-staged": {
61
+ "*.(json|ts)": "eslint --cache --fix"
62
+ }
63
+ }