@node-minify/cli 7.1.0 → 8.0.1-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,132 @@
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
+ */
132
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/compress.ts","../src/spinner.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2022 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport chalk from 'chalk';\nimport { compress } from './compress';\nimport { spinnerStart, spinnerStop, spinnerError } from './spinner';\nimport { Settings, Result } from '@node-minify/types';\n\n// export interface Options {\n// compressorLabel: string | Function;\n// compressor: Function;\n// input: string | string[];\n// output: string;\n// options?: string;\n// }\n\n// interface Option {}\n\n// interface Cli {\n// compressor: string | Function;\n// input: string;\n// output: string;\n// // option: Options;\n// option: string;\n// silence?: boolean;\n// }\n\n// export interface Result {\n// compressor?: string | Function;\n// compressorLabel: string | Function;\n// size: number;\n// sizeGzip: number;\n// }\n\n/**\n * Module variables.\n */\nlet silence = false;\n\n/**\n * Run one compressor.\n */\nconst runOne = (cli: Settings): Promise<Result> => {\n return new Promise<Result>((resolve, reject) => {\n const compressor =\n typeof cli.compressor === 'string' ? require(`@node-minify/${cli.compressor}`).default : cli.compressor;\n\n const options: Settings = {\n compressorLabel: cli.compressor,\n compressor,\n input: typeof cli.input === 'string' ? cli.input.split(',') : '',\n output: cli.output\n };\n\n if (cli.option) {\n options.options = JSON.parse(cli.option);\n }\n\n if (!silence) {\n spinnerStart(options);\n }\n\n return compress(options)\n .then((result: Result) => {\n if (!silence) {\n spinnerStop(result);\n }\n resolve(result);\n })\n .catch((err: Error) => {\n if (!silence) {\n spinnerError(options);\n }\n reject(err);\n });\n });\n};\n\n/**\n * Run cli.\n */\nconst run = (cli: Settings) => {\n silence = !!cli.silence;\n\n if (!silence) {\n console.log('');\n console.log(chalk.bgBlue.black(' INFO '), 'Starting compression...');\n console.log('');\n }\n\n return new Promise((resolve, reject) => {\n runOne(cli)\n .then(() => {\n if (!silence) {\n console.log('');\n console.log(chalk.bgGreen.black(' DONE '), chalk.green('Done!'));\n console.log('');\n }\n })\n .then(resolve)\n .catch(reject);\n });\n};\n\n/**\n * Expose `run()`.\n */\nexport { run };\n","/*!\n * node-minify\n * Copyright(c) 2011-2022 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport minify from '@node-minify/core';\nimport { utils } from '@node-minify/utils';\nimport { Settings, Result } from '@node-minify/types';\n\n/**\n * Run compression.\n *\n * @param {Object} options\n */\nconst compress = (options: Settings): Promise<Result> => {\n return new Promise<Result>((resolve, reject) => {\n minify(options)\n .then(() => {\n if (options.output.includes('$1')) {\n // TODO handle $1 output\n // npx node-minify --compressor uglify-js --input 'source/**/*.js' --output 'source/$1.min.js' --option '{\"warnings\": true, \"mangle\": false}'\n return resolve({\n compressorLabel: options.compressorLabel,\n compressor: options.compressor,\n size: 0,\n sizeGzip: 0\n });\n }\n utils\n .getFilesizeGzippedInBytes(options.output)\n .then((sizeGzip: number) => {\n resolve({\n compressorLabel: options.compressorLabel,\n compressor: options.compressor,\n size: utils.getFilesizeInBytes(options.output),\n sizeGzip: sizeGzip\n });\n })\n .catch(reject);\n })\n .catch(reject);\n });\n};\n\n/**\n * Expose `compress()`.\n */\nexport { compress };\n","/*!\n * node-minify\n * Copyright(c) 2011-2022 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport chalk from 'chalk';\nimport ora from 'ora';\nimport { Settings, Result } from '@node-minify/types';\n\nconst spinner = ora();\n\n/**\n * Start spinner.\n *\n * @param {Object} options\n */\nconst start = (options: Settings) => {\n spinner.text = 'Compressing file(s) with ' + chalk.green(options.compressorLabel) + '...';\n spinner.start();\n};\n\n/**\n * Stop spinner.\n *\n * @param {Object} result\n */\nconst stop = (result: Result) => {\n spinner.text =\n 'File(s) compressed successfully with ' +\n chalk.green(result.compressorLabel) +\n ' (' +\n chalk.green(result.size) +\n ' minified, ' +\n chalk.green(result.sizeGzip) +\n ' gzipped)';\n spinner.succeed();\n};\n\n/**\n * Mark spinner as failed.\n *\n * @param {Object} options\n */\nconst error = (options: Settings) => {\n spinner.text = 'Error - file(s) not compressed with ' + chalk.red(options.compressorLabel);\n spinner.fail();\n};\n\n/**\n * Expose `start(), stop() and error()`.\n */\nexport { start as spinnerStart, stop as spinnerStop, error as spinnerError };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,IAAAA,gBAAkB;;;ACAlB,kBAAmB;AACnB,mBAAsB;AAQtB,IAAM,WAAW,CAAC,YAAuC;AACvD,SAAO,IAAI,QAAgB,CAAC,SAAS,WAAW;AAC9C,oBAAAC,SAAO,OAAO,EACX,KAAK,MAAM;AACV,UAAI,QAAQ,OAAO,SAAS,IAAI,GAAG;AAGjC,eAAO,QAAQ;AAAA,UACb,iBAAiB,QAAQ;AAAA,UACzB,YAAY,QAAQ;AAAA,UACpB,MAAM;AAAA,UACN,UAAU;AAAA,QACZ,CAAC;AAAA,MACH;AACA,yBACG,0BAA0B,QAAQ,MAAM,EACxC,KAAK,CAAC,aAAqB;AAC1B,gB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AAS,OAAO,EACpB,KAAK,CAAC,WAAmB;AACxB,UAAI,CAAC,SAAS;AACZ,aAAY,MAAM;AAAA,MACpB;AACA,cAAQ,MAAM;AAAA,IAChB,CAAC,EACA,MAAM,CAAC,QAAe;AACrB,UAAI,CAAC,SAAS;AACZ,cAAa,OAAO;AAAA,MACtB;AACA,aAAO,GAAG;AAAA,IACZ,CAAC;AAAA,EACL,CAAC;AACH;AAKA,IAAM,MAAM,CAAC,QAAkB;AAC7B,YAAU,CAAC,CAAC,IAAI;AAEhB,MAAI,CAAC,SAAS;AACZ,YAAQ,IAAI,EAAE;AACd,YAAQ,IAAI,cAAAC,QAAM,OAAO,MAAM,QAAQ,GAAG,yBAAyB;AACnE,YAAQ,IAAI,EAAE;AAAA,EAChB;AAEA,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,WAAO,GAAG,EACP,KAAK,MAAM;AACV,UAAI,CAAC,SAAS;AACZ,gBAAQ,IAAI,EAAE;AACd,gBAAQ,IAAI,cAAAA,QAAM,QAAQ,MAAM,QAAQ,GAAG,cAAAA,QAAM,MAAM,OAAO,CAAC;AAC/D,gBAAQ,IAAI,EAAE;AAAA,MAChB;AAAA,IACF,CAAC,EACA,KAAK,OAAO,EACZ,MAAM,MAAM;AAAA,EACjB,CAAC;AACH;","names":["import_chalk","minify","ora","chalk","chalk"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,110 @@
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
+ */
110
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/compress.ts","../src/spinner.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2022 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport chalk from 'chalk';\nimport { compress } from './compress';\nimport { spinnerStart, spinnerStop, spinnerError } from './spinner';\nimport { Settings, Result } from '@node-minify/types';\n\n// export interface Options {\n// compressorLabel: string | Function;\n// compressor: Function;\n// input: string | string[];\n// output: string;\n// options?: string;\n// }\n\n// interface Option {}\n\n// interface Cli {\n// compressor: string | Function;\n// input: string;\n// output: string;\n// // option: Options;\n// option: string;\n// silence?: boolean;\n// }\n\n// export interface Result {\n// compressor?: string | Function;\n// compressorLabel: string | Function;\n// size: number;\n// sizeGzip: number;\n// }\n\n/**\n * Module variables.\n */\nlet silence = false;\n\n/**\n * Run one compressor.\n */\nconst runOne = (cli: Settings): Promise<Result> => {\n return new Promise<Result>((resolve, reject) => {\n const compressor =\n typeof cli.compressor === 'string' ? require(`@node-minify/${cli.compressor}`).default : cli.compressor;\n\n const options: Settings = {\n compressorLabel: cli.compressor,\n compressor,\n input: typeof cli.input === 'string' ? cli.input.split(',') : '',\n output: cli.output\n };\n\n if (cli.option) {\n options.options = JSON.parse(cli.option);\n }\n\n if (!silence) {\n spinnerStart(options);\n }\n\n return compress(options)\n .then((result: Result) => {\n if (!silence) {\n spinnerStop(result);\n }\n resolve(result);\n })\n .catch((err: Error) => {\n if (!silence) {\n spinnerError(options);\n }\n reject(err);\n });\n });\n};\n\n/**\n * Run cli.\n */\nconst run = (cli: Settings) => {\n silence = !!cli.silence;\n\n if (!silence) {\n console.log('');\n console.log(chalk.bgBlue.black(' INFO '), 'Starting compression...');\n console.log('');\n }\n\n return new Promise((resolve, reject) => {\n runOne(cli)\n .then(() => {\n if (!silence) {\n console.log('');\n console.log(chalk.bgGreen.black(' DONE '), chalk.green('Done!'));\n console.log('');\n }\n })\n .then(resolve)\n .catch(reject);\n });\n};\n\n/**\n * Expose `run()`.\n */\nexport { run };\n","/*!\n * node-minify\n * Copyright(c) 2011-2022 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport minify from '@node-minify/core';\nimport { utils } from '@node-minify/utils';\nimport { Settings, Result } from '@node-minify/types';\n\n/**\n * Run compression.\n *\n * @param {Object} options\n */\nconst compress = (options: Settings): Promise<Result> => {\n return new Promise<Result>((resolve, reject) => {\n minify(options)\n .then(() => {\n if (options.output.includes('$1')) {\n // TODO handle $1 output\n // npx node-minify --compressor uglify-js --input 'source/**/*.js' --output 'source/$1.min.js' --option '{\"warnings\": true, \"mangle\": false}'\n return resolve({\n compressorLabel: options.compressorLabel,\n compressor: options.compressor,\n size: 0,\n sizeGzip: 0\n });\n }\n utils\n .getFilesizeGzippedInBytes(options.output)\n .then((sizeGzip: number) => {\n resolve({\n compressorLabel: options.compressorLabel,\n compressor: options.compressor,\n size: utils.getFilesizeInBytes(options.output),\n sizeGzip: sizeGzip\n });\n })\n .catch(reject);\n })\n .catch(reject);\n });\n};\n\n/**\n * Expose `compress()`.\n */\nexport { compress };\n","/*!\n * node-minify\n * Copyright(c) 2011-2022 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Module dependencies.\n */\nimport chalk from 'chalk';\nimport ora from 'ora';\nimport { Settings, Result } from '@node-minify/types';\n\nconst spinner = ora();\n\n/**\n * Start spinner.\n *\n * @param {Object} options\n */\nconst start = (options: Settings) => {\n spinner.text = 'Compressing file(s) with ' + chalk.green(options.compressorLabel) + '...';\n spinner.start();\n};\n\n/**\n * Stop spinner.\n *\n * @param {Object} result\n */\nconst stop = (result: Result) => {\n spinner.text =\n 'File(s) compressed successfully with ' +\n chalk.green(result.compressorLabel) +\n ' (' +\n chalk.green(result.size) +\n ' minified, ' +\n chalk.green(result.sizeGzip) +\n ' gzipped)';\n spinner.succeed();\n};\n\n/**\n * Mark spinner as failed.\n *\n * @param {Object} options\n */\nconst error = (options: Settings) => {\n spinner.text = 'Error - file(s) not compressed with ' + chalk.red(options.compressorLabel);\n spinner.fail();\n};\n\n/**\n * Expose `start(), stop() and error()`.\n */\nexport { start as spinnerStart, stop as spinnerStop, error as spinnerError };\n"],"mappings":";;;;;;;;;AASA,OAAOA,YAAW;;;ACAlB,OAAO,YAAY;AACnB,SAAS,aAAa;AAQtB,IAAM,WAAW,CAAC,YAAuC;AACvD,SAAO,IAAI,QAAgB,CAAC,SAAS,WAAW;AAC9C,WAAO,OAAO,EACX,KAAK,MAAM;AACV,UAAI,QAAQ,OAAO,SAAS,IAAI,GAAG;AAGjC,eAAO,QAAQ;AAAA,UACb,iBAAiB,QAAQ;AAAA,UACzB,YAAY,QAAQ;AAAA,UACpB,MAAM;AAAA,UACN,UAAU;AAAA,QACZ,CAAC;AAAA,MACH;AACA,YACG,0BAA0B,QAAQ,MAAM,EACxC,KAAK,CAAC,aAAqB;AAC1B,gBAAQ;AAAA,UACN,iBAAiB,QAAQ;AAAA,UACzB,YAAY,QAAQ;AAAA,UACpB,MAAM,MAAM,mBAAmB,QAAQ,MAAM;AAAA,UAC7C;AAAA,QACF,CAAC;AAAA,MACH,CAAC,EACA,MAAM,MAAM;AAAA,IACjB,CAAC,EACA,MAAM,MAAM;AAAA,EACjB,CAAC;AACH;;;ACrCA,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MAAM,CAAC,QAAkB;AAC7B,YAAU,CAAC,CAAC,IAAI;AAEhB,MAAI,CAAC,SAAS;AACZ,YAAQ,IAAI,EAAE;AACd,YAAQ,IAAIC,OAAM,OAAO,MAAM,QAAQ,GAAG,yBAAyB;AACnE,YAAQ,IAAI,EAAE;AAAA,EAChB;AAEA,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,WAAO,GAAG,EACP,KAAK,MAAM;AACV,UAAI,CAAC,SAAS;AACZ,gBAAQ,IAAI,EAAE;AACd,gBAAQ,IAAIA,OAAM,QAAQ,MAAM,QAAQ,GAAGA,OAAM,MAAM,OAAO,CAAC;AAC/D,gBAAQ,IAAI,EAAE;AAAA,MAChB;AAAA,IACF,CAAC,EACA,KAAK,OAAO,EACZ,MAAM,MAAM;AAAA,EACjB,CAAC;AACH;","names":["chalk","chalk"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/cli",
3
- "version": "7.1.0",
3
+ "version": "8.0.1-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 --sourcemap",
48
+ "prepublishOnly": "npm run build"
49
+ },
38
50
  "dependencies": {
39
- "@node-minify/core": "^7.1.0",
40
- "@node-minify/utils": "^7.1.0",
51
+ "@node-minify/core": "8.0.1-beta.0",
52
+ "@node-minify/utils": "8.0.1-beta.0",
41
53
  "chalk": "4.1.2",
42
54
  "commander": "9.4.1",
43
55
  "ora": "5.4.1",
44
56
  "update-notifier": "6.0.2"
45
57
  },
46
- "gitHead": "94cef2d5d653c3bddc3e603b4e25c135b0b6f4b3"
58
+ "devDependencies": {
59
+ "@node-minify/types": "8.0.1-beta.0",
60
+ "@types/chalk": "^2.2.0",
61
+ "@types/ora": "^3.2.0"
62
+ },
63
+ "gitHead": "35a8a41ec86a11cbec05d8a7db9113475ece2cef"
47
64
  }
package/lib/cli.js DELETED
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.run = void 0;
7
- var _chalk = _interopRequireDefault(require("chalk"));
8
- var _compress = require("./compress");
9
- var _spinner = require("./spinner");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- /*!
12
- * node-minify
13
- * Copyright(c) 2011-2022 Rodolphe Stoclin
14
- * MIT Licensed
15
- */
16
-
17
- /**
18
- * Module dependencies.
19
- */
20
-
21
- /**
22
- * Module variables.
23
- */
24
- let silence = false;
25
-
26
- /**
27
- * Run one compressor.
28
- */
29
- const runOne = cli => {
30
- return new Promise((resolve, reject) => {
31
- const compressor = typeof cli.compressor === 'string' ? require(`@node-minify/${cli.compressor}`) : cli.compressor;
32
- const options = {
33
- compressorLabel: cli.compressor,
34
- compressor,
35
- input: cli.input.split(','),
36
- output: cli.output
37
- };
38
- if (cli.option) {
39
- options.options = JSON.parse(cli.option);
40
- }
41
- if (!silence) {
42
- (0, _spinner.spinnerStart)(options);
43
- }
44
- return (0, _compress.compress)(options).then(result => {
45
- if (!silence) {
46
- (0, _spinner.spinnerStop)(result);
47
- }
48
- resolve(result);
49
- }).catch(err => {
50
- if (!silence) {
51
- (0, _spinner.spinnerError)(options);
52
- }
53
- reject(err);
54
- });
55
- });
56
- };
57
-
58
- /**
59
- * Run cli.
60
- */
61
- const run = cli => {
62
- silence = !!cli.silence;
63
- if (!silence) {
64
- console.log('');
65
- console.log(_chalk.default.bgBlue.black(' INFO '), 'Starting compression...');
66
- console.log('');
67
- }
68
- return new Promise((resolve, reject) => {
69
- runOne(cli).then(() => {
70
- if (!silence) {
71
- console.log('');
72
- console.log(_chalk.default.bgGreen.black(' DONE '), _chalk.default.green('Done!'));
73
- console.log('');
74
- }
75
- }).then(resolve).catch(reject);
76
- });
77
- };
78
-
79
- /**
80
- * Expose `run()`.
81
- */
82
- exports.run = run;
package/lib/compress.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.compress = void 0;
7
- var _core = _interopRequireDefault(require("@node-minify/core"));
8
- var _utils = require("@node-minify/utils");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- /*!
11
- * node-minify
12
- * Copyright(c) 2011-2022 Rodolphe Stoclin
13
- * MIT Licensed
14
- */
15
-
16
- /**
17
- * Module dependencies.
18
- */
19
-
20
- /**
21
- * Run compression.
22
- *
23
- * @param {Object} options
24
- */
25
- const compress = options => {
26
- return new Promise((resolve, reject) => {
27
- (0, _core.default)(options).then(() => {
28
- if (options.output.includes('$1')) {
29
- // TODO handle $1 output
30
- // npx node-minify --compressor uglify-js --input 'source/**/*.js' --output 'source/$1.min.js' --option '{"warnings": true, "mangle": false}'
31
- return resolve({
32
- compressorLabel: options.compressorLabel,
33
- compressor: options.compressor,
34
- size: 0,
35
- sizeGzip: 0
36
- });
37
- }
38
- _utils.utils.getFilesizeGzippedInBytes(options.output).then(sizeGzip => {
39
- resolve({
40
- compressorLabel: options.compressorLabel,
41
- compressor: options.compressor,
42
- size: _utils.utils.getFilesizeInBytes(options.output),
43
- sizeGzip: sizeGzip
44
- });
45
- }).catch(reject);
46
- }).catch(reject);
47
- });
48
- };
49
-
50
- /**
51
- * Expose `compress()`.
52
- */
53
- exports.compress = compress;
package/lib/spinner.js DELETED
@@ -1,57 +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
- var _chalk = _interopRequireDefault(require("chalk"));
8
- var _ora = _interopRequireDefault(require("ora"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- /*!
11
- * node-minify
12
- * Copyright(c) 2011-2022 Rodolphe Stoclin
13
- * MIT Licensed
14
- */
15
-
16
- /**
17
- * Module dependencies.
18
- */
19
-
20
- const spinner = (0, _ora.default)();
21
-
22
- /**
23
- * Start spinner.
24
- *
25
- * @param {Object} options
26
- */
27
- const start = options => {
28
- spinner.text = 'Compressing file(s) with ' + _chalk.default.green(options.compressorLabel) + '...';
29
- spinner.start();
30
- };
31
-
32
- /**
33
- * Stop spinner.
34
- *
35
- * @param {Object} result
36
- */
37
- exports.spinnerStart = start;
38
- const stop = result => {
39
- spinner.text = 'File(s) compressed successfully with ' + _chalk.default.green(result.compressorLabel) + ' (' + _chalk.default.green(result.size) + ' minified, ' + _chalk.default.green(result.sizeGzip) + ' gzipped)';
40
- spinner.succeed();
41
- };
42
-
43
- /**
44
- * Mark spinner as failed.
45
- *
46
- * @param {Object} options
47
- */
48
- exports.spinnerStop = stop;
49
- const error = options => {
50
- spinner.text = 'Error - file(s) not compressed with ' + _chalk.default.red(options.compressorLabel);
51
- spinner.fail();
52
- };
53
-
54
- /**
55
- * Expose `start(), stop() and error()`.
56
- */
57
- exports.spinnerError = error;