@terrazzo/cli 0.0.7 → 0.0.8
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/LICENSE +2 -2
- package/bin/cli.js +47 -42
- package/package.json +13 -12
- package/terrazzo.config.js +11 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Drew Powers
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/bin/cli.js
CHANGED
|
@@ -80,11 +80,17 @@ export default async function main() {
|
|
|
80
80
|
}
|
|
81
81
|
configPath = resolveConfig(flags.config);
|
|
82
82
|
}
|
|
83
|
-
let config;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
let config = { tokens: [new URL('./tokens.json', cwd)], outDir: new URL('./tokens/', cwd), plugins: [] };
|
|
84
|
+
const resolvedConfigPath = resolveConfig(configPath);
|
|
85
|
+
if (resolvedConfigPath) {
|
|
86
|
+
try {
|
|
87
|
+
config = (await import(resolvedConfigPath)).default;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
printErrors(err.message || err);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
} else if (cmd !== 'init' && cmd !== 'check') {
|
|
93
|
+
printErrors('No config file found. Create one with `npx terrazzo init`.');
|
|
88
94
|
process.exit(1);
|
|
89
95
|
}
|
|
90
96
|
|
|
@@ -154,54 +160,39 @@ export default async function main() {
|
|
|
154
160
|
break;
|
|
155
161
|
}
|
|
156
162
|
case 'check': {
|
|
157
|
-
const rawSchema = await loadTokens(config.tokens);
|
|
158
|
-
const filepath = config.tokens[0];
|
|
163
|
+
const rawSchema = await loadTokens(flags._[0] ? [resolveTokenPath(flags._[0])] : config.tokens);
|
|
164
|
+
const filepath = flags._[0] || config.tokens[0];
|
|
159
165
|
console.log(pc.underline(filepath.protocol === 'file:' ? fileURLToPath(filepath) : filepath));
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
printErrors(errors);
|
|
163
|
-
printWarnings(warnings);
|
|
164
|
-
process.exit(1);
|
|
165
|
-
}
|
|
166
|
-
printSuccess(`no errors ${time(start)}`);
|
|
166
|
+
await parse(rawSchema, { config }); // will throw if errors
|
|
167
|
+
printSuccess(`No errors ${time(start)}`);
|
|
167
168
|
break;
|
|
168
169
|
}
|
|
169
170
|
case 'lint': {
|
|
170
171
|
if (!Array.isArray(config.plugins) || !config.plugins.length) {
|
|
171
|
-
printErrors(
|
|
172
|
+
printErrors(`No plugins defined! Add some in ${configPath || 'tokens.config.js'}`);
|
|
172
173
|
process.exit(1);
|
|
173
174
|
}
|
|
174
175
|
|
|
175
|
-
const rawSchema = await loadTokens(config.tokens);
|
|
176
|
-
const parseResult = parse(rawSchema, config); // will throw if errors
|
|
176
|
+
const rawSchema = await loadTokens(flags._[0] ? [resolveTokenPath(flags._[0])] : config.tokens);
|
|
177
|
+
const parseResult = await parse(rawSchema, { config }); // will throw if errors
|
|
178
|
+
|
|
179
|
+
// TODO
|
|
177
180
|
|
|
178
|
-
if (parseResult.errors) {
|
|
179
|
-
printErrors(parseResult.errors);
|
|
180
|
-
printWarnings(parseResult.warnings);
|
|
181
|
-
process.exit(1);
|
|
182
|
-
}
|
|
183
|
-
if (parseResult.warnings) {
|
|
184
|
-
printWarnings(parseResult.warnings);
|
|
185
|
-
}
|
|
186
|
-
const lintResult = await lint({ config, tokens: parseResult.result.tokens, rawSchema, warnIfNoPlugins: true });
|
|
187
|
-
if (lintResult.errors) {
|
|
188
|
-
printErrors(lintResult.errors);
|
|
189
|
-
printWarnings(lintResult.warnings);
|
|
190
|
-
process.exit(1);
|
|
191
|
-
}
|
|
192
|
-
if (lintResult.warnings) {
|
|
193
|
-
printWarnings(lintResult.warnings);
|
|
194
|
-
} else {
|
|
195
|
-
printSuccess(`all checks passed ${time(start)}`);
|
|
196
|
-
}
|
|
197
181
|
break;
|
|
198
182
|
}
|
|
199
183
|
case 'init': {
|
|
200
|
-
if (
|
|
201
|
-
|
|
184
|
+
if (
|
|
185
|
+
!fs.existsSync(new URL('./terrazzo.config.js', cwd)) &&
|
|
186
|
+
!fs.existsSync(new URL('./terrazzo.config.mjs', cwd)) &&
|
|
187
|
+
!fs.existsSync(new URL('./terrazzo.config.cjs', cwd))
|
|
188
|
+
) {
|
|
189
|
+
fs.cpSync(new URL('../terrazzo.config.js', import.meta.url), new URL('./terrazzo.config.js', cwd));
|
|
190
|
+
printSuccess('terrazzo.config.js created');
|
|
191
|
+
}
|
|
192
|
+
if (!fs.existsSync(config.tokens[0])) {
|
|
193
|
+
fs.cpSync(new URL('../tokens-example.json', import.meta.url), new URL(config?.tokens, cwd));
|
|
194
|
+
printSuccess(`${config.tokens} created ${time(start)}`);
|
|
202
195
|
}
|
|
203
|
-
fs.cpSync(new URL('../tokens-example.json', import.meta.url), new URL(config.tokens, cwd));
|
|
204
|
-
printSuccess(`${config.tokens} created ${time(start)}`);
|
|
205
196
|
break;
|
|
206
197
|
}
|
|
207
198
|
default: {
|
|
@@ -232,8 +223,8 @@ function showHelp() {
|
|
|
232
223
|
--out [path] Specify converted tokens.json output
|
|
233
224
|
|
|
234
225
|
[options]
|
|
235
|
-
--help
|
|
236
|
-
--config, -c
|
|
226
|
+
--help Show this message
|
|
227
|
+
--config, -c Path to config (default: ./tokens.config.js)
|
|
237
228
|
`);
|
|
238
229
|
}
|
|
239
230
|
|
|
@@ -317,6 +308,20 @@ function resolveConfig(filename) {
|
|
|
317
308
|
}
|
|
318
309
|
}
|
|
319
310
|
|
|
311
|
+
/** Resolve tokens.json path (for lint command) */
|
|
312
|
+
function resolveTokenPath(filepath) {
|
|
313
|
+
const tokensPath = new URL(filepath, cwd);
|
|
314
|
+
if (!fs.existsSync(tokensPath)) {
|
|
315
|
+
printErrors(`Could not locate ${filepath}. Does the file exist?`);
|
|
316
|
+
process.exit(1);
|
|
317
|
+
}
|
|
318
|
+
if (!fs.statSync(tokensPath).isFile()) {
|
|
319
|
+
printErrors(`Expected JSON or YAML file, received ${filepath}.`);
|
|
320
|
+
process.exit(1);
|
|
321
|
+
}
|
|
322
|
+
return tokensPath;
|
|
323
|
+
}
|
|
324
|
+
|
|
320
325
|
/** Print time elapsed */
|
|
321
326
|
function time(start) {
|
|
322
327
|
const diff = performance.now() - start;
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrazzo/cli",
|
|
3
|
+
"version": "0.0.8",
|
|
3
4
|
"description": "CLI for managing design tokens using the Design Tokens Community Group (DTCG) standard and generating code for any platform via plugins.",
|
|
4
|
-
"
|
|
5
|
+
"type": "module",
|
|
5
6
|
"author": {
|
|
6
7
|
"name": "Drew Powers",
|
|
7
8
|
"email": "drew@pow.rs"
|
|
8
9
|
},
|
|
9
10
|
"keywords": [
|
|
10
11
|
"design tokens",
|
|
11
|
-
"design tokens community group",
|
|
12
|
-
"design tokens format module",
|
|
13
12
|
"dtcg",
|
|
14
13
|
"cli",
|
|
15
|
-
"w3c
|
|
14
|
+
"w3c",
|
|
16
15
|
"design system",
|
|
17
16
|
"typescript",
|
|
18
17
|
"sass",
|
|
@@ -20,12 +19,14 @@
|
|
|
20
19
|
"style tokens",
|
|
21
20
|
"style system"
|
|
22
21
|
],
|
|
23
|
-
"
|
|
24
|
-
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"homepage": "https://terrazzoapp.com/docs/cli",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/terrazzoapp/terrazzo.git",
|
|
27
|
+
"directory": "./packages/cli/"
|
|
25
28
|
},
|
|
26
29
|
"license": "MIT",
|
|
27
|
-
"type": "module",
|
|
28
|
-
"main": "./dist/index.js",
|
|
29
30
|
"bin": {
|
|
30
31
|
"tz": "bin/cli.js",
|
|
31
32
|
"terrazzo": "bin/cli.js"
|
|
@@ -36,12 +37,12 @@
|
|
|
36
37
|
"merge-anything": "^5.1.7",
|
|
37
38
|
"picocolors": "^1.0.1",
|
|
38
39
|
"yargs-parser": "^21.1.1",
|
|
39
|
-
"@terrazzo/parser": "^0.0.
|
|
40
|
-
"@terrazzo/token-tools": "^0.0.
|
|
40
|
+
"@terrazzo/parser": "^0.0.8",
|
|
41
|
+
"@terrazzo/token-tools": "^0.0.4"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@types/node": "^20.14.
|
|
44
|
-
"execa": "^
|
|
44
|
+
"@types/node": "^20.14.9",
|
|
45
|
+
"execa": "^9.3.0"
|
|
45
46
|
},
|
|
46
47
|
"scripts": {
|
|
47
48
|
"build": "pnpm run build:clean && pnpm run build:ts",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @type {import('@terrazzo/cli').Config} */
|
|
2
|
+
export default {
|
|
3
|
+
tokens: ['tokens.json'],
|
|
4
|
+
outDir: './tokens/',
|
|
5
|
+
plugins: [
|
|
6
|
+
/** @see https://terrazzo.app/docs/cli/integrations */
|
|
7
|
+
],
|
|
8
|
+
lint: {
|
|
9
|
+
/** @see https://terrazzo.app/docs/cli/linting */
|
|
10
|
+
},
|
|
11
|
+
};
|