styimat 8.3.0 → 8.4.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/bin/cli.js +3 -5
- package/bin/cli.min.js +20 -0
- package/package.json +5 -4
package/bin/cli.js
CHANGED
|
@@ -136,23 +136,22 @@ async function interactiveMode() {
|
|
|
136
136
|
console.log('styimat 交互模式');
|
|
137
137
|
console.log('请输入 CSS 代码,按 Ctrl+D (Unix) 或 Ctrl+Z (Windows) 提交转换');
|
|
138
138
|
console.log('按 Ctrl+C 退出交互模式');
|
|
139
|
-
console.log('='.repeat(50));
|
|
140
139
|
|
|
141
140
|
let sessionCount = 0;
|
|
142
141
|
|
|
143
142
|
while (true) {
|
|
144
143
|
sessionCount++;
|
|
144
|
+
process.stderr.write('styimat>');
|
|
145
|
+
|
|
145
146
|
try {
|
|
146
147
|
// 使用 fs.createReadStream 读取输入
|
|
147
148
|
const input = await readFromStdin();
|
|
148
149
|
|
|
149
150
|
if (input === null) {
|
|
150
|
-
console.log('检测到退出信号');
|
|
151
151
|
break;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
if (input.trim() === '') {
|
|
155
|
-
console.log('输入为空,跳过');
|
|
156
155
|
continue;
|
|
157
156
|
}
|
|
158
157
|
|
|
@@ -182,11 +181,10 @@ function readFromStdin() {
|
|
|
182
181
|
highWaterMark: 1024 // 每次读取 1KB
|
|
183
182
|
});
|
|
184
183
|
|
|
185
|
-
|
|
186
184
|
stream.on('data', (chunk) => {
|
|
187
185
|
chunks.push(chunk);
|
|
188
186
|
totalBytes += chunk.length;
|
|
189
|
-
process.stderr.write('
|
|
187
|
+
process.stderr.write('........'); // 显示正在读取的指示
|
|
190
188
|
});
|
|
191
189
|
|
|
192
190
|
stream.on('end', () => {
|
package/bin/cli.min.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs=require("fs"),path=require("path"),chokidar=require("chokidar");async function main(){const s=process.argv.slice(2);let e="",t=null,i=!1,o=null;for(let r=0;r<s.length;r++){const n=s[r];if(n==="--watch"||n==="-w")i=!0;else if(n==="--interactive"||n==="-i"){interactiveMode();return}else n==="--help"||n==="-h"?(c(),process.exit(0)):n.startsWith("-")?(console.error(`\u9519\u8BEF: \u672A\u77E5\u9009\u9879 ${n}`),c(),process.exit(1)):o?t?(console.error("\u9519\u8BEF: \u53C2\u6570\u8FC7\u591A"),c(),process.exit(1)):t=n:o=n}function c(){console.log(`
|
|
3
|
+
\u7528\u6CD5: styimat [\u9009\u9879] [\u8F93\u5165\u6587\u4EF6] [\u8F93\u51FA\u6587\u4EF6]
|
|
4
|
+
|
|
5
|
+
\u9009\u9879:
|
|
6
|
+
-w, --watch \u76D1\u63A7\u8F93\u5165\u6587\u4EF6\u53D8\u5316\u5E76\u81EA\u52A8\u8F6C\u6362
|
|
7
|
+
-h, --help \u663E\u793A\u5E2E\u52A9\u4FE1\u606F
|
|
8
|
+
-i, --interactive \u8FDB\u5165\u4EA4\u4E92\u6A21\u5F0F
|
|
9
|
+
|
|
10
|
+
\u793A\u4F8B:
|
|
11
|
+
styimat # \u4ECE stdin \u8BFB\u53D6\uFF0C\u8F93\u51FA\u5230 stdout
|
|
12
|
+
styimat input.css # \u4ECE\u6587\u4EF6\u8BFB\u53D6\uFF0C\u8F93\u51FA\u5230 stdout
|
|
13
|
+
styimat input.css output.css # \u4ECE\u6587\u4EF6\u8BFB\u53D6\uFF0C\u8F93\u51FA\u5230\u6587\u4EF6
|
|
14
|
+
styimat -w input.css output.css # \u76D1\u63A7\u5E76\u81EA\u52A8\u8F6C\u6362
|
|
15
|
+
styimat -i # \u8FDB\u5165\u4EA4\u4E92\u6A21\u5F0F
|
|
16
|
+
`)}if(!o){i&&(console.error("\u9519\u8BEF: \u76D1\u63A7\u6A21\u5F0F\u9700\u8981\u6307\u5B9A\u8F93\u5165\u6587\u4EF6"),process.exit(1)),e=fs.readFileSync(0,"utf8"),await convertAndOutput(e,null);return}if(fs.existsSync(o)||(console.error(`\u9519\u8BEF: \u8F93\u5165\u6587\u4EF6 "${o}" \u4E0D\u5B58\u5728`),process.exit(1)),i){t||(console.error("\u9519\u8BEF: \u76D1\u63A7\u6A21\u5F0F\u9700\u8981\u6307\u5B9A\u8F93\u51FA\u6587\u4EF6"),process.exit(1)),console.log(`\u76D1\u63A7\u6A21\u5F0F\u5DF2\u542F\u52A8: ${o} -> ${t}`),console.log("\u6309 Ctrl+C \u9000\u51FA"),await convertFile(o,t);const r=chokidar.watch(o,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:200,pollInterval:100}});r.on("change",async n=>{console.log(`${new Date().toLocaleTimeString()} - \u68C0\u6D4B\u5230\u53D8\u5316: ${n}`),await convertFile(n,t)}).on("error",n=>{console.error(`\u76D1\u63A7\u9519\u8BEF: ${n.message}`)}),process.on("SIGINT",()=>{console.log("\u505C\u6B62\u76D1\u63A7..."),r.close(),process.exit(0)})}else e=fs.readFileSync(o,"utf8"),await convertAndOutput(e,t)}async function convertFile(s,e){try{const t=fs.readFileSync(s,"utf8"),i=await convertStyimat(t);fs.writeFileSync(e,i,"utf8"),console.log(`${new Date().toLocaleTimeString()} - \u8F6C\u6362\u5B8C\u6210: ${s} -> ${e}`)}catch(t){console.error(`${new Date().toLocaleTimeString()} - \u8F6C\u6362\u9519\u8BEF: ${t.message}`)}}async function interactiveMode(){console.log("styimat \u4EA4\u4E92\u6A21\u5F0F"),console.log("\u8BF7\u8F93\u5165 CSS \u4EE3\u7801\uFF0C\u6309 Ctrl+D (Unix) \u6216 Ctrl+Z (Windows) \u63D0\u4EA4\u8F6C\u6362"),console.log("\u6309 Ctrl+C \u9000\u51FA\u4EA4\u4E92\u6A21\u5F0F");let s=0;for(;;){s++,process.stderr.write("styimat>");try{const e=await readFromStdin();if(e===null)break;if(e.trim()==="")continue;const t=await convertStyimat(e);console.log(`
|
|
17
|
+
\u8F6C\u6362\u7ED3\u679C:`),console.log(t)}catch(e){console.error("\u8F6C\u6362\u9519\u8BEF:",e.message),console.log("\u8BF7\u91CD\u8BD5...")}}console.log(`
|
|
18
|
+
\u518D\u89C1\uFF01`)}function readFromStdin(){return new Promise((s,e)=>{const t=[];let i=0;const o=fs.createReadStream("/dev/stdin",{encoding:"utf8",highWaterMark:1024});o.on("data",r=>{t.push(r),i+=r.length,process.stderr.write("........")}),o.on("end",()=>{if(process.stderr.write(`
|
|
19
|
+
`),t.length===0)s(null);else{const r=t.join("");s(r)}}),o.on("error",r=>{e(r)});const c=setTimeout(()=>{o.destroy(),console.log(`
|
|
20
|
+
\u8BFB\u53D6\u8D85\u65F6`),s(null)},3e4);o.on("end",()=>{clearTimeout(c)})})}async function convertAndOutput(s,e){try{const t=await convertStyimat(s);e?fs.writeFileSync(e,t,"utf8"):process.stdout.write(t)}catch(t){console.error("\u8F6C\u6362\u9519\u8BEF:",t.message),process.exit(1)}}async function convertStyimat(s){const e=[path.join(path.dirname(__dirname),"dist","styimat.js"),path.join(process.cwd(),"dist","styimat.js"),path.join(process.cwd(),"node_modules","styimat","dist","styimat.js")];let t=null;for(const o of e)try{if(fs.existsSync(o)){t=require(o);break}}catch{}if(!t)throw new Error("\u627E\u4E0D\u5230 styimat.js \u6A21\u5757");const i=t.styimat||t;if(typeof i.convert!="function")throw new Error("styimat.convert \u4E0D\u662F\u51FD\u6570");return await i.convert(s)}main().catch(s=>{console.error("\u7A0B\u5E8F\u9519\u8BEF:",s.message),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "styimat",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "一个高效的CSS变量预处理库,支持Lab/LCH颜色空间自动转换、嵌套选择器和Display P3广色域,让现代CSS开发更简洁强大。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -43,10 +43,11 @@
|
|
|
43
43
|
"dist/styimat.min.mjs",
|
|
44
44
|
"LICENSE",
|
|
45
45
|
"README.md",
|
|
46
|
-
"bin/cli.js"
|
|
46
|
+
"bin/cli.js",
|
|
47
|
+
"bin/cli.min.js"
|
|
47
48
|
],
|
|
48
49
|
"bin": {
|
|
49
|
-
"styimat": "bin/cli.js"
|
|
50
|
+
"styimat": "bin/cli.min.js"
|
|
50
51
|
},
|
|
51
52
|
"repository": {
|
|
52
53
|
"type": "git",
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
"homepage": "https://gitee.com/wxy6987/styimat#readme",
|
|
59
60
|
"scripts": {
|
|
60
61
|
"test": "echo \"No tests yet\" && exit 0",
|
|
61
|
-
"build:min": "npx esbuild dist/styimat.js --minify --outfile=dist/styimat.min.js && node build.js && npx esbuild dist/styimat.mjs --minify --outfile=dist/styimat.min.mjs",
|
|
62
|
+
"build:min": "npx esbuild dist/styimat.js --minify --outfile=dist/styimat.min.js && node build.js && npx esbuild dist/styimat.mjs --minify --outfile=dist/styimat.min.mjs && npx esbuild bin/cli.js --minify --outfile=bin/cli.min.js",
|
|
62
63
|
"prepare": "npm run build:min",
|
|
63
64
|
"prepublishOnly": "npm run build:min",
|
|
64
65
|
"postpublish": "npm run git:auto-commit && npm run git:auto-tag",
|