@terrazzo/cli 0.0.9 → 0.0.11
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/README.md +1 -1
- package/bin/cli.js +34 -16
- package/package.json +3 -4
package/README.md
CHANGED
package/bin/cli.js
CHANGED
|
@@ -23,10 +23,11 @@
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import { parse, build } from '@terrazzo/parser';
|
|
26
|
+
import { parse, build, defineConfig } from '@terrazzo/parser';
|
|
27
27
|
import chokidar from 'chokidar';
|
|
28
28
|
import dotenv from 'dotenv';
|
|
29
29
|
import fs from 'node:fs';
|
|
30
|
+
import path from 'node:path';
|
|
30
31
|
import { fileURLToPath } from 'node:url';
|
|
31
32
|
import pc from 'picocolors';
|
|
32
33
|
import parser from 'yargs-parser';
|
|
@@ -84,7 +85,14 @@ export default async function main() {
|
|
|
84
85
|
const resolvedConfigPath = resolveConfig(configPath);
|
|
85
86
|
if (resolvedConfigPath) {
|
|
86
87
|
try {
|
|
87
|
-
|
|
88
|
+
const mod = await import(resolvedConfigPath);
|
|
89
|
+
if (!mod.default) {
|
|
90
|
+
printErrors(
|
|
91
|
+
`No default export found in ${path.relative(fileURLToPath(cwd), resolvedConfigPath)}. See https://terrazzo.dev/docs/cli for instructions.`,
|
|
92
|
+
);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
config = defineConfig(mod.default, { cwd });
|
|
88
96
|
} catch (err) {
|
|
89
97
|
printErrors(err.message || err);
|
|
90
98
|
process.exit(1);
|
|
@@ -103,10 +111,6 @@ export default async function main() {
|
|
|
103
111
|
|
|
104
112
|
let rawSchema = await loadTokens(config.tokens);
|
|
105
113
|
|
|
106
|
-
const dt = new Intl.DateTimeFormat('en-us', {
|
|
107
|
-
hour: '2-digit',
|
|
108
|
-
minute: '2-digit',
|
|
109
|
-
});
|
|
110
114
|
const watch = args.includes('-w') || args.includes('--watch');
|
|
111
115
|
|
|
112
116
|
let { tokens, ast } = await parse(rawSchema, { config });
|
|
@@ -117,6 +121,10 @@ export default async function main() {
|
|
|
117
121
|
printWarnings(result.warnings);
|
|
118
122
|
|
|
119
123
|
if (watch) {
|
|
124
|
+
const dt = new Intl.DateTimeFormat('en-us', {
|
|
125
|
+
hour: '2-digit',
|
|
126
|
+
minute: '2-digit',
|
|
127
|
+
});
|
|
120
128
|
const tokenWatcher = chokidar.watch(config.tokens.map((filepath) => fileURLToPath(filepath)));
|
|
121
129
|
tokenWatcher.on('change', async (filePath) => {
|
|
122
130
|
try {
|
|
@@ -132,7 +140,7 @@ export default async function main() {
|
|
|
132
140
|
printErrors([err.message || err]);
|
|
133
141
|
}
|
|
134
142
|
});
|
|
135
|
-
const configWatcher = chokidar.watch(
|
|
143
|
+
const configWatcher = chokidar.watch(resolveConfig(configPath));
|
|
136
144
|
configWatcher.on('change', async (filePath) => {
|
|
137
145
|
try {
|
|
138
146
|
console.log(
|
|
@@ -163,7 +171,7 @@ export default async function main() {
|
|
|
163
171
|
const rawSchema = await loadTokens(flags._[0] ? [resolveTokenPath(flags._[0])] : config.tokens);
|
|
164
172
|
const filepath = flags._[0] || config.tokens[0];
|
|
165
173
|
console.log(pc.underline(filepath.protocol === 'file:' ? fileURLToPath(filepath) : filepath));
|
|
166
|
-
await parse(rawSchema, { config }); // will throw if errors
|
|
174
|
+
await parse(rawSchema, { config, continueOnError: true }); // will throw if errors
|
|
167
175
|
printSuccess(`No errors ${time(start)}`);
|
|
168
176
|
break;
|
|
169
177
|
}
|
|
@@ -174,7 +182,7 @@ export default async function main() {
|
|
|
174
182
|
}
|
|
175
183
|
|
|
176
184
|
const rawSchema = await loadTokens(flags._[0] ? [resolveTokenPath(flags._[0])] : config.tokens);
|
|
177
|
-
const parseResult = await parse(rawSchema, { config }); // will throw if errors
|
|
185
|
+
const parseResult = await parse(rawSchema, { config, continueOnError: true }); // will throw if errors
|
|
178
186
|
|
|
179
187
|
// TODO
|
|
180
188
|
|
|
@@ -230,10 +238,13 @@ function showHelp() {
|
|
|
230
238
|
|
|
231
239
|
/** load tokens */
|
|
232
240
|
async function loadTokens(tokenPaths) {
|
|
233
|
-
// TODO:
|
|
241
|
+
// TODO: merge tokens
|
|
242
|
+
|
|
243
|
+
const allTokens = [];
|
|
234
244
|
|
|
235
245
|
// download/read
|
|
236
|
-
for (
|
|
246
|
+
for (let i = 0; i < tokenPaths.length; i++) {
|
|
247
|
+
const filepath = tokenPaths[i];
|
|
237
248
|
if (filepath.protocol === 'http:' || filepath.protocol === 'https:') {
|
|
238
249
|
try {
|
|
239
250
|
// if Figma URL
|
|
@@ -259,7 +270,7 @@ async function loadTokens(tokenPaths) {
|
|
|
259
270
|
headers,
|
|
260
271
|
});
|
|
261
272
|
if (res.ok) {
|
|
262
|
-
|
|
273
|
+
allTokens.push(await res.text());
|
|
263
274
|
}
|
|
264
275
|
const message = res.status !== 404 ? JSON.stringify(await res.json(), undefined, 2) : '';
|
|
265
276
|
printErrors(`Figma responded with ${res.status}${message ? `:\n${message}` : ''}`);
|
|
@@ -272,22 +283,29 @@ async function loadTokens(tokenPaths) {
|
|
|
272
283
|
method: 'GET',
|
|
273
284
|
headers: { Accept: '*/*', 'User-Agent': 'Mozilla/5.0 Gecko/20100101 Firefox/123.0' },
|
|
274
285
|
});
|
|
275
|
-
|
|
286
|
+
allTokens.push(await res.text());
|
|
276
287
|
} catch (err) {
|
|
277
288
|
printErrors(`${filepath.href}: ${err}`);
|
|
278
289
|
}
|
|
279
290
|
} else {
|
|
280
291
|
if (fs.existsSync(filepath)) {
|
|
281
|
-
|
|
292
|
+
allTokens.push(fs.readFileSync(filepath, 'utf8'));
|
|
282
293
|
} else {
|
|
283
|
-
printErrors(
|
|
294
|
+
printErrors(
|
|
295
|
+
`Could not locate ${path.relative(fileURLToPath(cwd), fileURLToPath(filepath))}. To create one, run \`npx tz init\`.`,
|
|
296
|
+
);
|
|
284
297
|
process.exit(1);
|
|
285
298
|
}
|
|
286
299
|
}
|
|
287
300
|
}
|
|
301
|
+
|
|
302
|
+
return allTokens[0];
|
|
288
303
|
}
|
|
289
304
|
|
|
290
|
-
/**
|
|
305
|
+
/**
|
|
306
|
+
* resolve config
|
|
307
|
+
* @return {string | undefined} resolvedPath
|
|
308
|
+
*/
|
|
291
309
|
function resolveConfig(filename) {
|
|
292
310
|
// --config [configpath]
|
|
293
311
|
if (filename) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrazzo/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "CLI for managing design tokens using the Design Tokens Community Group (DTCG) standard and generating code for any platform via plugins.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -37,11 +37,10 @@
|
|
|
37
37
|
"merge-anything": "^5.1.7",
|
|
38
38
|
"picocolors": "^1.0.1",
|
|
39
39
|
"yargs-parser": "^21.1.1",
|
|
40
|
-
"@terrazzo/parser": "^0.0.
|
|
40
|
+
"@terrazzo/parser": "^0.0.11",
|
|
41
41
|
"@terrazzo/token-tools": "^0.0.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"execa": "^9.3.0",
|
|
45
44
|
"typescript": "^5.5.3"
|
|
46
45
|
},
|
|
47
46
|
"scripts": {
|
|
@@ -50,7 +49,7 @@
|
|
|
50
49
|
"build:ts": "tsc -p tsconfig.build.json",
|
|
51
50
|
"dev": "tsc -p tsconfig.build.json -w",
|
|
52
51
|
"lint": "biome check .",
|
|
53
|
-
"test": "pnpm run \"/^test:.*/\"",
|
|
52
|
+
"test": "pnpm --filter @terrazzo/cli run \"/^test:.*/\"",
|
|
54
53
|
"test:js": "vitest run",
|
|
55
54
|
"test:ts": "tsc --noEmit"
|
|
56
55
|
}
|