@node-minify/cli 7.0.0 → 8.0.0-beta.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.
@@ -0,0 +1,14 @@
1
+ import { Settings } from '@node-minify/types';
2
+
3
+ /*!
4
+ * node-minify
5
+ * Copyright(c) 2011-2022 Rodolphe Stoclin
6
+ * MIT Licensed
7
+ */
8
+
9
+ /**
10
+ * Run cli.
11
+ */
12
+ declare const run: (cli: Settings) => Promise<unknown>;
13
+
14
+ export { run };
package/dist/index.js ADDED
@@ -0,0 +1,131 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+
25
+ // src/index.ts
26
+ var src_exports = {};
27
+ __export(src_exports, {
28
+ run: () => run
29
+ });
30
+ module.exports = __toCommonJS(src_exports);
31
+ var import_chalk2 = __toESM(require("chalk"));
32
+
33
+ // src/compress.ts
34
+ var import_core = __toESM(require("@node-minify/core"));
35
+ var import_utils = require("@node-minify/utils");
36
+ var compress = (options) => {
37
+ return new Promise((resolve, reject) => {
38
+ (0, import_core.default)(options).then(() => {
39
+ if (options.output.includes("$1")) {
40
+ return resolve({
41
+ compressorLabel: options.compressorLabel,
42
+ compressor: options.compressor,
43
+ size: 0,
44
+ sizeGzip: 0
45
+ });
46
+ }
47
+ import_utils.utils.getFilesizeGzippedInBytes(options.output).then((sizeGzip) => {
48
+ resolve({
49
+ compressorLabel: options.compressorLabel,
50
+ compressor: options.compressor,
51
+ size: import_utils.utils.getFilesizeInBytes(options.output),
52
+ sizeGzip
53
+ });
54
+ }).catch(reject);
55
+ }).catch(reject);
56
+ });
57
+ };
58
+
59
+ // src/spinner.ts
60
+ var import_chalk = __toESM(require("chalk"));
61
+ var import_ora = __toESM(require("ora"));
62
+ var spinner = (0, import_ora.default)();
63
+ var start = (options) => {
64
+ spinner.text = "Compressing file(s) with " + import_chalk.default.green(options.compressorLabel) + "...";
65
+ spinner.start();
66
+ };
67
+ var stop = (result) => {
68
+ spinner.text = "File(s) compressed successfully with " + import_chalk.default.green(result.compressorLabel) + " (" + import_chalk.default.green(result.size) + " minified, " + import_chalk.default.green(result.sizeGzip) + " gzipped)";
69
+ spinner.succeed();
70
+ };
71
+ var error = (options) => {
72
+ spinner.text = "Error - file(s) not compressed with " + import_chalk.default.red(options.compressorLabel);
73
+ spinner.fail();
74
+ };
75
+
76
+ // src/index.ts
77
+ var silence = false;
78
+ var runOne = (cli) => {
79
+ return new Promise((resolve, reject) => {
80
+ const compressor = typeof cli.compressor === "string" ? require(`@node-minify/${cli.compressor}`).default : cli.compressor;
81
+ const options = {
82
+ compressorLabel: cli.compressor,
83
+ compressor,
84
+ input: typeof cli.input === "string" ? cli.input.split(",") : "",
85
+ output: cli.output
86
+ };
87
+ if (cli.option) {
88
+ options.options = JSON.parse(cli.option);
89
+ }
90
+ if (!silence) {
91
+ start(options);
92
+ }
93
+ return compress(options).then((result) => {
94
+ if (!silence) {
95
+ stop(result);
96
+ }
97
+ resolve(result);
98
+ }).catch((err) => {
99
+ if (!silence) {
100
+ error(options);
101
+ }
102
+ reject(err);
103
+ });
104
+ });
105
+ };
106
+ var run = (cli) => {
107
+ silence = !!cli.silence;
108
+ if (!silence) {
109
+ console.log("");
110
+ console.log(import_chalk2.default.bgBlue.black(" INFO "), "Starting compression...");
111
+ console.log("");
112
+ }
113
+ return new Promise((resolve, reject) => {
114
+ runOne(cli).then(() => {
115
+ if (!silence) {
116
+ console.log("");
117
+ console.log(import_chalk2.default.bgGreen.black(" DONE "), import_chalk2.default.green("Done!"));
118
+ console.log("");
119
+ }
120
+ }).then(resolve).catch(reject);
121
+ });
122
+ };
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ run
126
+ });
127
+ /*!
128
+ * node-minify
129
+ * Copyright(c) 2011-2022 Rodolphe Stoclin
130
+ * MIT Licensed
131
+ */
package/dist/index.mjs ADDED
@@ -0,0 +1,109 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw new Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // src/index.ts
10
+ import chalk2 from "chalk";
11
+
12
+ // src/compress.ts
13
+ import minify from "@node-minify/core";
14
+ import { utils } from "@node-minify/utils";
15
+ var compress = (options) => {
16
+ return new Promise((resolve, reject) => {
17
+ minify(options).then(() => {
18
+ if (options.output.includes("$1")) {
19
+ return resolve({
20
+ compressorLabel: options.compressorLabel,
21
+ compressor: options.compressor,
22
+ size: 0,
23
+ sizeGzip: 0
24
+ });
25
+ }
26
+ utils.getFilesizeGzippedInBytes(options.output).then((sizeGzip) => {
27
+ resolve({
28
+ compressorLabel: options.compressorLabel,
29
+ compressor: options.compressor,
30
+ size: utils.getFilesizeInBytes(options.output),
31
+ sizeGzip
32
+ });
33
+ }).catch(reject);
34
+ }).catch(reject);
35
+ });
36
+ };
37
+
38
+ // src/spinner.ts
39
+ import chalk from "chalk";
40
+ import ora from "ora";
41
+ var spinner = ora();
42
+ var start = (options) => {
43
+ spinner.text = "Compressing file(s) with " + chalk.green(options.compressorLabel) + "...";
44
+ spinner.start();
45
+ };
46
+ var stop = (result) => {
47
+ spinner.text = "File(s) compressed successfully with " + chalk.green(result.compressorLabel) + " (" + chalk.green(result.size) + " minified, " + chalk.green(result.sizeGzip) + " gzipped)";
48
+ spinner.succeed();
49
+ };
50
+ var error = (options) => {
51
+ spinner.text = "Error - file(s) not compressed with " + chalk.red(options.compressorLabel);
52
+ spinner.fail();
53
+ };
54
+
55
+ // src/index.ts
56
+ var silence = false;
57
+ var runOne = (cli) => {
58
+ return new Promise((resolve, reject) => {
59
+ const compressor = typeof cli.compressor === "string" ? __require(`@node-minify/${cli.compressor}`).default : cli.compressor;
60
+ const options = {
61
+ compressorLabel: cli.compressor,
62
+ compressor,
63
+ input: typeof cli.input === "string" ? cli.input.split(",") : "",
64
+ output: cli.output
65
+ };
66
+ if (cli.option) {
67
+ options.options = JSON.parse(cli.option);
68
+ }
69
+ if (!silence) {
70
+ start(options);
71
+ }
72
+ return compress(options).then((result) => {
73
+ if (!silence) {
74
+ stop(result);
75
+ }
76
+ resolve(result);
77
+ }).catch((err) => {
78
+ if (!silence) {
79
+ error(options);
80
+ }
81
+ reject(err);
82
+ });
83
+ });
84
+ };
85
+ var run = (cli) => {
86
+ silence = !!cli.silence;
87
+ if (!silence) {
88
+ console.log("");
89
+ console.log(chalk2.bgBlue.black(" INFO "), "Starting compression...");
90
+ console.log("");
91
+ }
92
+ return new Promise((resolve, reject) => {
93
+ runOne(cli).then(() => {
94
+ if (!silence) {
95
+ console.log("");
96
+ console.log(chalk2.bgGreen.black(" DONE "), chalk2.green("Done!"));
97
+ console.log("");
98
+ }
99
+ }).then(resolve).catch(reject);
100
+ });
101
+ };
102
+ export {
103
+ run
104
+ };
105
+ /*!
106
+ * node-minify
107
+ * Copyright(c) 2011-2022 Rodolphe Stoclin
108
+ * MIT Licensed
109
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/cli",
3
- "version": "7.0.0",
3
+ "version": "8.0.0-beta.0",
4
4
  "description": "CLI - command line interface for @node-minify",
5
5
  "keywords": [
6
6
  "compressor",
@@ -13,17 +13,24 @@
13
13
  "bin": {
14
14
  "node-minify": "bin/cli.js"
15
15
  },
16
- "main": "lib/cli.js",
17
16
  "engines": {
18
17
  "node": ">=14.0.0"
19
18
  },
20
19
  "directories": {
21
- "lib": "lib",
20
+ "lib": "dist",
22
21
  "test": "__tests__"
23
22
  },
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.mjs",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ "require": "./dist/index.js",
28
+ "import": "./dist/index.mjs",
29
+ "types": "./dist/index.d.ts"
30
+ },
24
31
  "files": [
25
32
  "bin",
26
- "lib"
33
+ "dist/**/*"
27
34
  ],
28
35
  "publishConfig": {
29
36
  "access": "public"
@@ -35,13 +42,23 @@
35
42
  "bugs": {
36
43
  "url": "https://github.com/srod/node-minify/issues"
37
44
  },
45
+ "scripts": {
46
+ "clean": "pnpm dlx rimraf dist",
47
+ "build": "npm run clean && tsup src/index.ts --format cjs,esm --dts --clean",
48
+ "prepublishOnly": "npm run build"
49
+ },
38
50
  "dependencies": {
39
- "@node-minify/core": "^7.0.0",
40
- "@node-minify/utils": "^7.0.0",
51
+ "@node-minify/core": "8.0.0-beta.0",
52
+ "@node-minify/utils": "8.0.0-beta.0",
41
53
  "chalk": "4.1.2",
42
- "commander": "9.4.0",
54
+ "commander": "9.4.1",
43
55
  "ora": "5.4.1",
44
56
  "update-notifier": "6.0.2"
45
57
  },
46
- "gitHead": "8b5bda6f1ac9fe7180006f2a19ec3253e8fff4ec"
58
+ "devDependencies": {
59
+ "@node-minify/types": "8.0.0-beta.0",
60
+ "@types/chalk": "^2.2.0",
61
+ "@types/ora": "^3.2.0"
62
+ },
63
+ "gitHead": "0507c6190577e1939997a8231b07952ba167a780"
47
64
  }
package/lib/cli.js DELETED
@@ -1,96 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.run = void 0;
7
-
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
- var _compress = require("./compress");
11
-
12
- var _spinner = require("./spinner");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- /*!
17
- * node-minify
18
- * Copyright(c) 2011-2022 Rodolphe Stoclin
19
- * MIT Licensed
20
- */
21
-
22
- /**
23
- * Module dependencies.
24
- */
25
-
26
- /**
27
- * Module variables.
28
- */
29
- let silence = false;
30
- /**
31
- * Run one compressor.
32
- */
33
-
34
- const runOne = cli => {
35
- return new Promise((resolve, reject) => {
36
- const compressor = typeof cli.compressor === 'string' ? require(`@node-minify/${cli.compressor}`) : cli.compressor;
37
- const options = {
38
- compressorLabel: cli.compressor,
39
- compressor,
40
- input: cli.input.split(','),
41
- output: cli.output
42
- };
43
-
44
- if (cli.option) {
45
- options.options = JSON.parse(cli.option);
46
- }
47
-
48
- if (!silence) {
49
- (0, _spinner.spinnerStart)(options);
50
- }
51
-
52
- return (0, _compress.compress)(options).then(result => {
53
- if (!silence) {
54
- (0, _spinner.spinnerStop)(result);
55
- }
56
-
57
- resolve(result);
58
- }).catch(err => {
59
- if (!silence) {
60
- (0, _spinner.spinnerError)(options);
61
- }
62
-
63
- reject(err);
64
- });
65
- });
66
- };
67
- /**
68
- * Run cli.
69
- */
70
-
71
-
72
- const run = cli => {
73
- silence = !!cli.silence;
74
-
75
- if (!silence) {
76
- console.log('');
77
- console.log(_chalk.default.bgBlue.black(' INFO '), 'Starting compression...');
78
- console.log('');
79
- }
80
-
81
- return new Promise((resolve, reject) => {
82
- runOne(cli).then(() => {
83
- if (!silence) {
84
- console.log('');
85
- console.log(_chalk.default.bgGreen.black(' DONE '), _chalk.default.green('Done!'));
86
- console.log('');
87
- }
88
- }).then(resolve).catch(reject);
89
- });
90
- };
91
- /**
92
- * Expose `run()`.
93
- */
94
-
95
-
96
- exports.run = run;
package/lib/compress.js DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.compress = void 0;
7
-
8
- var _core = _interopRequireDefault(require("@node-minify/core"));
9
-
10
- var _utils = require("@node-minify/utils");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /*!
15
- * node-minify
16
- * Copyright(c) 2011-2022 Rodolphe Stoclin
17
- * MIT Licensed
18
- */
19
-
20
- /**
21
- * Module dependencies.
22
- */
23
-
24
- /**
25
- * Run compression.
26
- *
27
- * @param {Object} options
28
- */
29
- const compress = options => {
30
- return new Promise((resolve, reject) => {
31
- (0, _core.default)(options).then(() => {
32
- if (options.output.includes('$1')) {
33
- // TODO handle $1 output
34
- // npx node-minify --compressor uglify-js --input 'source/**/*.js' --output 'source/$1.min.js' --option '{"warnings": true, "mangle": false}'
35
- return resolve({
36
- compressorLabel: options.compressorLabel,
37
- compressor: options.compressor,
38
- size: 0,
39
- sizeGzip: 0
40
- });
41
- }
42
-
43
- _utils.utils.getFilesizeGzippedInBytes(options.output).then(sizeGzip => {
44
- resolve({
45
- compressorLabel: options.compressorLabel,
46
- compressor: options.compressor,
47
- size: _utils.utils.getFilesizeInBytes(options.output),
48
- sizeGzip: sizeGzip
49
- });
50
- }).catch(reject);
51
- }).catch(reject);
52
- });
53
- };
54
- /**
55
- * Expose `compress()`.
56
- */
57
-
58
-
59
- exports.compress = compress;
package/lib/spinner.js DELETED
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.spinnerStop = exports.spinnerStart = exports.spinnerError = void 0;
7
-
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
- var _ora = _interopRequireDefault(require("ora"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /*!
15
- * node-minify
16
- * Copyright(c) 2011-2022 Rodolphe Stoclin
17
- * MIT Licensed
18
- */
19
-
20
- /**
21
- * Module dependencies.
22
- */
23
- const spinner = (0, _ora.default)();
24
- /**
25
- * Start spinner.
26
- *
27
- * @param {Object} options
28
- */
29
-
30
- const start = options => {
31
- spinner.text = 'Compressing file(s) with ' + _chalk.default.green(options.compressorLabel) + '...';
32
- spinner.start();
33
- };
34
- /**
35
- * Stop spinner.
36
- *
37
- * @param {Object} result
38
- */
39
-
40
-
41
- exports.spinnerStart = start;
42
-
43
- const stop = result => {
44
- spinner.text = 'File(s) compressed successfully with ' + _chalk.default.green(result.compressorLabel) + ' (' + _chalk.default.green(result.size) + ' minified, ' + _chalk.default.green(result.sizeGzip) + ' gzipped)';
45
- spinner.succeed();
46
- };
47
- /**
48
- * Mark spinner as failed.
49
- *
50
- * @param {Object} options
51
- */
52
-
53
-
54
- exports.spinnerStop = stop;
55
-
56
- const error = options => {
57
- spinner.text = 'Error - file(s) not compressed with ' + _chalk.default.red(options.compressorLabel);
58
- spinner.fail();
59
- };
60
- /**
61
- * Expose `start(), stop() and error()`.
62
- */
63
-
64
-
65
- exports.spinnerError = error;