@ispriter/cli 2.0.1 → 2.0.2
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/dist/index.js +60 -14
- package/package.json +9 -9
- package/LICENSE +0 -21
package/dist/index.js
CHANGED
|
@@ -7,16 +7,26 @@ import { parseConfig } from "@ispriter/core";
|
|
|
7
7
|
import { readFile, writeFile, mkdir, glob } from "fs/promises";
|
|
8
8
|
import path from "path";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
|
+
import { createRequire } from "module";
|
|
10
11
|
var __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
var require2 = createRequire(import.meta.url);
|
|
13
|
+
var pkg = require2("../package.json");
|
|
11
14
|
var program = new Command();
|
|
12
|
-
program.name("ispriter").description("CSS sprite generator").version(
|
|
15
|
+
program.name("ispriter").description("CSS sprite generator").version(pkg.version);
|
|
13
16
|
function createRunAction() {
|
|
14
17
|
return async (opts) => {
|
|
15
18
|
try {
|
|
16
19
|
const config = await resolveConfig(opts);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
if (opts.dryRun && opts.watch) {
|
|
21
|
+
console.warn("\u26A0\uFE0F --dry-run and --watch are mutually exclusive. Running dry-run only.");
|
|
22
|
+
}
|
|
23
|
+
if (opts.dryRun) {
|
|
24
|
+
await runSpriterDry(config);
|
|
25
|
+
} else {
|
|
26
|
+
await runSpriter(config);
|
|
27
|
+
if (opts.watch) {
|
|
28
|
+
await startWatch(config);
|
|
29
|
+
}
|
|
20
30
|
}
|
|
21
31
|
} catch (e) {
|
|
22
32
|
if (e.name === "IspriterError") {
|
|
@@ -27,8 +37,7 @@ function createRunAction() {
|
|
|
27
37
|
}
|
|
28
38
|
};
|
|
29
39
|
}
|
|
30
|
-
program.command("run").description("Generate sprites from CSS files").option("-c, --config <path>", "config file path (JSON)").option("-f, --files <paths>", "CSS files (comma separated)").option("-o, --output <path>", "CSS output directory").option("--watch", "watch
|
|
31
|
-
program.option("-c, --config <path>", "config file path (JSON)").option("-f, --files <paths>", "CSS files (comma separated)").option("-o, --output <path>", "CSS output directory").option("--watch", "watch for file changes and regenerate").action(createRunAction());
|
|
40
|
+
program.command("run", { isDefault: true }).description("Generate sprites from CSS files").option("-c, --config <path>", "config file path (JSON)").option("-f, --files <paths>", "CSS files (comma separated)").option("-o, --output <path>", "CSS output directory").option("--watch", "watch for file changes and regenerate").option("--dry-run", "preview what would be sprited without writing files").action(createRunAction());
|
|
32
41
|
async function resolveConfig(opts) {
|
|
33
42
|
if (opts.config) {
|
|
34
43
|
const configPath = path.resolve(opts.config);
|
|
@@ -46,9 +55,10 @@ async function resolveConfig(opts) {
|
|
|
46
55
|
output: { cssDist: opts.output || "./sprite/css/" }
|
|
47
56
|
};
|
|
48
57
|
}
|
|
49
|
-
|
|
58
|
+
program.help();
|
|
59
|
+
return {};
|
|
50
60
|
}
|
|
51
|
-
async function
|
|
61
|
+
async function collectInputs(config) {
|
|
52
62
|
const resolved = parseConfig(config);
|
|
53
63
|
const workspace = path.resolve(resolved.workspace);
|
|
54
64
|
const cssSource = Array.isArray(resolved.input.cssSource) ? resolved.input.cssSource : [resolved.input.cssSource];
|
|
@@ -64,7 +74,7 @@ async function runSpriter(config) {
|
|
|
64
74
|
}
|
|
65
75
|
if (cssFiles.size === 0) {
|
|
66
76
|
console.warn("\u26A0\uFE0F No CSS files found");
|
|
67
|
-
return;
|
|
77
|
+
return null;
|
|
68
78
|
}
|
|
69
79
|
const images = /* @__PURE__ */ new Map();
|
|
70
80
|
const allUrls = [];
|
|
@@ -91,11 +101,29 @@ async function runSpriter(config) {
|
|
|
91
101
|
}
|
|
92
102
|
}
|
|
93
103
|
}
|
|
104
|
+
return { resolved, workspace, cssFiles, images };
|
|
105
|
+
}
|
|
106
|
+
async function runSpriter(config) {
|
|
107
|
+
const inputs = await collectInputs(config);
|
|
108
|
+
if (!inputs) return;
|
|
109
|
+
const { resolved, workspace, cssFiles, images } = inputs;
|
|
94
110
|
console.log(`\u{1F4E6} Processing ${cssFiles.size} CSS files with ${images.size} images...`);
|
|
95
111
|
const spriter = new Spriter(config);
|
|
96
112
|
const result = await spriter.run({ css: cssFiles, images, cssBaseDir: workspace });
|
|
97
113
|
const cssDist = path.resolve(workspace, resolved.output.cssDist);
|
|
114
|
+
if (!cssDist.startsWith(workspace)) {
|
|
115
|
+
console.error(
|
|
116
|
+
`\u274C output.cssDist must be inside workspace: "${resolved.output.cssDist}" resolves outside`
|
|
117
|
+
);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
98
120
|
const imgDist = path.resolve(cssDist, resolved.output.imageDist);
|
|
121
|
+
if (!imgDist.startsWith(workspace)) {
|
|
122
|
+
console.error(
|
|
123
|
+
`\u274C output.imageDist must be inside workspace: "${resolved.output.imageDist}" resolves outside`
|
|
124
|
+
);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
99
127
|
await mkdir(imgDist, { recursive: true });
|
|
100
128
|
for (const [name, buf] of result.spriteImages) {
|
|
101
129
|
await writeFile(path.join(imgDist, name), buf);
|
|
@@ -104,9 +132,24 @@ async function runSpriter(config) {
|
|
|
104
132
|
const outName = path.basename(name);
|
|
105
133
|
await writeFile(path.join(cssDist, outName), content);
|
|
106
134
|
}
|
|
107
|
-
console.log(
|
|
135
|
+
console.log(
|
|
136
|
+
`\u2705 Generated ${result.spriteImages.size} sprite(s), updated ${result.cssFiles.size} CSS file(s)`
|
|
137
|
+
);
|
|
108
138
|
if (result.skippedImages.length > 0) {
|
|
109
|
-
console.warn(
|
|
139
|
+
console.warn(
|
|
140
|
+
`\u26A0\uFE0F Skipped ${result.skippedImages.length} image(s): ${result.skippedImages.join(", ")}`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function runSpriterDry(config) {
|
|
145
|
+
const inputs = await collectInputs(config);
|
|
146
|
+
if (!inputs) return;
|
|
147
|
+
const { workspace, cssFiles, images } = inputs;
|
|
148
|
+
console.log(`\u{1F4E6} Dry-run: analyzing ${cssFiles.size} CSS files with ${images.size} images...`);
|
|
149
|
+
const spriter = new Spriter(config);
|
|
150
|
+
const result = await spriter.run({ css: cssFiles, images, cssBaseDir: workspace, dryRun: true });
|
|
151
|
+
if (result.dryRunReport) {
|
|
152
|
+
console.log(result.dryRunReport);
|
|
110
153
|
}
|
|
111
154
|
}
|
|
112
155
|
async function startWatch(config) {
|
|
@@ -115,9 +158,12 @@ async function startWatch(config) {
|
|
|
115
158
|
const workspace = path.resolve(resolved.workspace);
|
|
116
159
|
console.log("\u{1F440} Watching for changes...");
|
|
117
160
|
const cssPatterns = Array.isArray(resolved.input.cssSource) ? resolved.input.cssSource : [resolved.input.cssSource];
|
|
118
|
-
const watcher = watch(
|
|
119
|
-
|
|
120
|
-
|
|
161
|
+
const watcher = watch(
|
|
162
|
+
cssPatterns.map((p) => path.resolve(workspace, p)),
|
|
163
|
+
{
|
|
164
|
+
ignoreInitial: true
|
|
165
|
+
}
|
|
166
|
+
);
|
|
121
167
|
watcher.on("change", async (file) => {
|
|
122
168
|
console.log(`\u{1F4DD} ${file} changed, regenerating...`);
|
|
123
169
|
try {
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ispriter/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"ispriter": "./dist/index.js"
|
|
7
7
|
},
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsup",
|
|
12
|
+
"dev": "tsup --watch"
|
|
13
|
+
},
|
|
10
14
|
"dependencies": {
|
|
15
|
+
"@ispriter/core": "workspace:*",
|
|
16
|
+
"@ispriter/shared": "workspace:*",
|
|
11
17
|
"chokidar": "^5.0.0",
|
|
12
|
-
"commander": "^12.1.0"
|
|
13
|
-
"@ispriter/core": "2.0.1",
|
|
14
|
-
"@ispriter/shared": "2.0.1"
|
|
18
|
+
"commander": "^12.1.0"
|
|
15
19
|
},
|
|
16
20
|
"devDependencies": {
|
|
17
21
|
"@types/node": "^22.10.0",
|
|
@@ -27,9 +31,5 @@
|
|
|
27
31
|
},
|
|
28
32
|
"publishConfig": {
|
|
29
33
|
"access": "public"
|
|
30
|
-
},
|
|
31
|
-
"scripts": {
|
|
32
|
-
"build": "tsup",
|
|
33
|
-
"dev": "tsup --watch"
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014 iazrael.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a
|
|
6
|
-
copy of this software and associated documentation files (the "Software"),
|
|
7
|
-
to deal in the Software without restriction, including without limitation
|
|
8
|
-
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
9
|
-
and/or sell copies of the Software, and to permit persons to whom the
|
|
10
|
-
Software is 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
|
|
20
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
21
|
-
DEALINGS IN THE SOFTWARE.
|