@terrazzo/cli 0.0.12 → 0.0.14

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @terrazzo/cli
2
2
 
3
+ ## 0.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - [#289](https://github.com/terrazzoapp/terrazzo/pull/289) [`0fc9738`](https://github.com/terrazzoapp/terrazzo/commit/0fc9738bb3dfecb680d225e4bd3970f21cfe8079) Thanks [@drwpow](https://github.com/drwpow)! - Add YAML support
8
+
9
+ - Updated dependencies [[`0fc9738`](https://github.com/terrazzoapp/terrazzo/commit/0fc9738bb3dfecb680d225e4bd3970f21cfe8079), [`6a875b1`](https://github.com/terrazzoapp/terrazzo/commit/6a875b163539dba8111911851a7819732056b3aa)]:
10
+ - @terrazzo/parser@0.0.13
11
+
3
12
  ## 0.0.12
4
13
 
5
14
  ### Patch Changes
package/bin/cli.js CHANGED
@@ -23,19 +23,24 @@
23
23
  * SOFTWARE.
24
24
  */
25
25
 
26
- import { parse, build, defineConfig } from '@terrazzo/parser';
26
+ import { parse, build, defineConfig, Logger } from '@terrazzo/parser';
27
27
  import chokidar from 'chokidar';
28
28
  import dotenv from 'dotenv';
29
29
  import fs from 'node:fs';
30
30
  import path from 'node:path';
31
31
  import { fileURLToPath } from 'node:url';
32
32
  import pc from 'picocolors';
33
+ import yamlToMomoa from 'yaml-to-momoa';
33
34
  import parser from 'yargs-parser';
34
35
 
35
36
  dotenv.config();
36
37
 
37
38
  const [, , cmd, ...args] = process.argv;
38
39
  const cwd = new URL(`file://${process.cwd()}/`);
40
+ const PKG_ROOT = new URL('../', import.meta.url);
41
+ const logger = new Logger(
42
+ // TODO: listen for env vars for debugging, log level, etc
43
+ );
39
44
 
40
45
  const GREEN_CHECK = pc.green('✔');
41
46
 
@@ -64,7 +69,7 @@ export default async function main() {
64
69
 
65
70
  // --version
66
71
  if (flags.version) {
67
- const { version } = parseJSON(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
72
+ const { version } = parseJSON(fs.readFileSync(new URL('./package.json', PKG_ROOT), 'utf8'));
68
73
  console.log(version);
69
74
  process.exit(0);
70
75
  }
@@ -88,11 +93,11 @@ export default async function main() {
88
93
  const mod = await import(resolvedConfigPath);
89
94
  if (!mod.default) {
90
95
  printErrors(
91
- `No default export found in ${path.relative(fileURLToPath(cwd), resolvedConfigPath)}. See https://terrazzo.dev/docs/cli for instructions.`,
96
+ `No default export found in ${path.relative(cwd.href, resolvedConfigPath)}. See https://terrazzo.dev/docs/cli for instructions.`,
92
97
  );
93
98
  process.exit(1);
94
99
  }
95
- config = defineConfig(mod.default, { cwd });
100
+ config = defineConfig(mod.default, { cwd, logger });
96
101
  } catch (err) {
97
102
  printErrors(err.message || err);
98
103
  process.exit(1);
@@ -113,8 +118,8 @@ export default async function main() {
113
118
 
114
119
  const watch = args.includes('-w') || args.includes('--watch');
115
120
 
116
- let { tokens, ast } = await parse(rawSchemas, { config });
117
- let result = await build(tokens, { ast, config });
121
+ let { tokens, ast } = await parse(rawSchemas, { config, logger, yamlToMomoa });
122
+ let result = await build(tokens, { ast, config, logger });
118
123
  writeFiles(result, config);
119
124
 
120
125
  printErrors(result.errors);
@@ -129,10 +134,10 @@ export default async function main() {
129
134
  tokenWatcher.on('change', async (filename) => {
130
135
  try {
131
136
  rawSchemas = await loadTokens(config.tokens);
132
- const parseResult = await parse(rawSchemas, { config });
137
+ const parseResult = await parse(rawSchemas, { config, logger, yamlToMomoa });
133
138
  tokens = parseResult.tokens;
134
139
  ast = parseResult.ast;
135
- result = await build(tokens, { ast, config });
140
+ result = await build(tokens, { ast, config, logger });
136
141
  console.log(
137
142
  `${pc.dim(dt.format(new Date()))} ${pc.green('Tz')}} ${pc.yellow(filename)} updated ${GREEN_CHECK}`,
138
143
  );
@@ -148,10 +153,10 @@ export default async function main() {
148
153
  );
149
154
  config = (await import(filename)).default;
150
155
  rawSchema = await loadTokens(config.tokens);
151
- const parseResult = await parse(tokens, { config });
156
+ const parseResult = await parse(tokens, { config, logger, yamlToMomoa });
152
157
  tokens = parseResult.tokens;
153
158
  ast = parseResult.ast;
154
- result = await build(tokens, { ast, config });
159
+ result = await build(tokens, { ast, config, logger });
155
160
  writeFiles(result, config);
156
161
  } catch (err) {
157
162
  printErrors([err.message || err]);
@@ -170,19 +175,18 @@ export default async function main() {
170
175
  case 'check': {
171
176
  const rawSchemas = await loadTokens(flags._[0] ? [resolveTokenPath(flags._[0])] : config.tokens);
172
177
  const filename = flags._[0] || config.tokens[0];
173
- console.log(pc.underline(filename.protocol === 'file:' ? fileURLToPath(filename) : filename));
174
- await parse(rawSchemas, { config, continueOnError: true }); // will throw if errors
178
+ console.log(pc.underline(filename.protocol === 'file:' ? filename.href : filename));
179
+ await parse(rawSchemas, { config, continueOnError: true, logger, yamlToMomoa }); // will throw if errors
175
180
  printSuccess(`No errors ${time(start)}`);
176
181
  break;
177
182
  }
178
183
  case 'lint': {
179
184
  if (!Array.isArray(config.plugins) || !config.plugins.length) {
180
185
  printErrors(`No plugins defined! Add some in ${configPath || 'tokens.config.js'}`);
181
- process.exit(1);
182
186
  }
183
187
 
184
188
  const rawSchema = await loadTokens(flags._[0] ? [resolveTokenPath(flags._[0])] : config.tokens);
185
- const parseResult = await parse(rawSchema, { config, continueOnError: true }); // will throw if errors
189
+ const parseResult = await parse(rawSchema, { config, continueOnError: true, logger, yamlToMomoa }); // will throw if errors
186
190
 
187
191
  // TODO
188
192
 
@@ -194,11 +198,11 @@ export default async function main() {
194
198
  !fs.existsSync(new URL('./terrazzo.config.mjs', cwd)) &&
195
199
  !fs.existsSync(new URL('./terrazzo.config.cjs', cwd))
196
200
  ) {
197
- fs.cpSync(new URL('../terrazzo.config.js', import.meta.url), new URL('./terrazzo.config.js', cwd));
201
+ fs.cpSync(new URL('./terrazzo.config.js', PKG_ROOT), new URL('./terrazzo.config.js', cwd));
198
202
  printSuccess('terrazzo.config.js created');
199
203
  }
200
204
  if (!fs.existsSync(config.tokens[0])) {
201
- fs.cpSync(new URL('../tokens-example.json', import.meta.url), new URL(config?.tokens, cwd));
205
+ fs.cpSync(new URL('./tokens-example.json', PKG_ROOT), new URL(config?.tokens, cwd));
202
206
  printSuccess(`${config.tokens} created ${time(start)}`);
203
207
  }
204
208
  break;
@@ -245,6 +249,21 @@ async function loadTokens(tokenPaths) {
245
249
  process.exit(1);
246
250
  }
247
251
 
252
+ // if this is the default value, also check for tokens.yaml
253
+ if (tokenPaths.length === 1 && tokenPaths[0].href === new URL('./tokens.json', cwd).href) {
254
+ if (!fs.existsSync(tokenPaths[0])) {
255
+ const yamlPath = new URL('./tokens.yaml', cwd);
256
+ if (fs.existsSync(yamlPath)) {
257
+ tokenPaths[0] = yamlPath;
258
+ } else {
259
+ printErrors(
260
+ `Could not locate ${path.relative(cwd.href, tokenPaths[0].href)}. To create one, run \`npx tz init\`.`,
261
+ );
262
+ process.exit(1);
263
+ }
264
+ }
265
+ }
266
+
248
267
  // download/read
249
268
  for (let i = 0; i < tokenPaths.length; i++) {
250
269
  const filename = tokenPaths[i];
@@ -300,9 +319,7 @@ async function loadTokens(tokenPaths) {
300
319
  if (fs.existsSync(filename)) {
301
320
  allTokens.push({ filename, src: fs.readFileSync(filename, 'utf8') });
302
321
  } else {
303
- printErrors(
304
- `Could not locate ${path.relative(fileURLToPath(cwd), fileURLToPath(filename))}. To create one, run \`npx tz init\`.`,
305
- );
322
+ printErrors(`Could not locate ${path.relative(cwd.href, filename.href)}. To create one, run \`npx tz init\`.`);
306
323
  process.exit(1);
307
324
  }
308
325
  }
@@ -320,16 +337,19 @@ function resolveConfig(filename) {
320
337
  if (filename) {
321
338
  const configPath = new URL(filename, cwd);
322
339
  if (fs.existsSync(configPath)) {
323
- return fileURLToPath(configPath);
340
+ return configPath.href; // ⚠️ ESM wants "file://..." URLs on Windows & Unix.
324
341
  }
325
342
  return undefined;
326
343
  }
327
344
 
328
345
  // default: terrazzo.config.js
329
- for (const defaultFilename of ['./terrazzo.config.js', './terrazzo.config.mjs']) {
346
+ for (const defaultFilename of [
347
+ './terrazzo.config.mjs', // .mjs takes precedence (it suggestes .js is CJS)
348
+ './terrazzo.config.js',
349
+ ]) {
330
350
  const configPath = new URL(defaultFilename, cwd);
331
351
  if (fs.existsSync(configPath)) {
332
- return fileURLToPath(configPath);
352
+ return configPath.href; // ⚠️ ESM wants "file://..." URLs on Windows & Unix.
333
353
  }
334
354
  }
335
355
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terrazzo/cli",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
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": {
@@ -36,12 +36,13 @@
36
36
  "dotenv": "^16.4.5",
37
37
  "merge-anything": "^5.1.7",
38
38
  "picocolors": "^1.0.1",
39
+ "yaml-to-momoa": "^0.0.1",
39
40
  "yargs-parser": "^21.1.1",
40
- "@terrazzo/parser": "^0.0.12",
41
- "@terrazzo/token-tools": "^0.0.6"
41
+ "@terrazzo/parser": "^0.0.14",
42
+ "@terrazzo/token-tools": "^0.0.7"
42
43
  },
43
44
  "devDependencies": {
44
- "typescript": "^5.5.3"
45
+ "typescript": "^5.5.4"
45
46
  },
46
47
  "scripts": {
47
48
  "build": "pnpm run build:clean && pnpm run build:ts",
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { type Config, type ConfigInit } from '@terrazzo/parser';
2
- export declare function defineConfig(config: Config): ConfigInit;
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- import { defineConfig as defineConfigCore } from '@terrazzo/parser';
2
- export function defineConfig(config) {
3
- return defineConfigCore(config, { cwd: new URL(`file://${process.cwd()}/`) });
4
- }
5
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,IAAI,gBAAgB,EAAmB,MAAM,kBAAkB,CAAC;AAElG,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,gBAAgB,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,UAAU,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC"}