@terrazzo/cli 0.7.3 → 0.8.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/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/bin/cli.js +1 -8
- package/dist/index.d.ts +148 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +723 -26
- package/dist/index.js.map +1 -1
- package/dist/lab/assets/{index-HP_WOzzC.js → index-CAePl8SC.js} +10 -10
- package/dist/lab/assets/{index-HP_WOzzC.js.map → index-CAePl8SC.js.map} +1 -1
- package/dist/lab/index.html +1 -1
- package/package.json +8 -13
- package/rolldown.config.ts +32 -0
- package/dist/build.d.ts +0 -16
- package/dist/build.d.ts.map +0 -1
- package/dist/build.js +0 -93
- package/dist/build.js.map +0 -1
- package/dist/check.d.ts +0 -10
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js +0 -24
- package/dist/check.js.map +0 -1
- package/dist/help.d.ts +0 -3
- package/dist/help.d.ts.map +0 -1
- package/dist/help.js +0 -19
- package/dist/help.js.map +0 -1
- package/dist/init.d.ts +0 -6
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -224
- package/dist/init.js.map +0 -1
- package/dist/lab.d.ts +0 -11
- package/dist/lab.d.ts.map +0 -1
- package/dist/lab.js +0 -74
- package/dist/lab.js.map +0 -1
- package/dist/normalize.d.ts +0 -7
- package/dist/normalize.d.ts.map +0 -1
- package/dist/normalize.js +0 -77
- package/dist/normalize.js.map +0 -1
- package/dist/shared.d.ts +0 -48
- package/dist/shared.d.ts.map +0 -1
- package/dist/shared.js +0 -190
- package/dist/shared.js.map +0 -1
- package/dist/version.d.ts +0 -2
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js +0 -6
- package/dist/version.js.map +0 -1
package/dist/lab/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Terrazzo Token Lab</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-CAePl8SC.js"></script>
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
|
10
10
|
<div id="app"></div>
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrazzo/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
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
|
+
"license": "MIT",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"author": {
|
|
7
8
|
"name": "Drew Powers",
|
|
@@ -21,11 +22,7 @@
|
|
|
21
22
|
],
|
|
22
23
|
"main": "./dist/index.js",
|
|
23
24
|
"exports": {
|
|
24
|
-
".":
|
|
25
|
-
"import": "./dist/index.js",
|
|
26
|
-
"types": "./dist/index.d.ts"
|
|
27
|
-
},
|
|
28
|
-
"./README.md": "./README.md",
|
|
25
|
+
".": "./dist/index.js",
|
|
29
26
|
"./package.json": "./package.json"
|
|
30
27
|
},
|
|
31
28
|
"homepage": "https://terrazzo.app/docs/cli",
|
|
@@ -34,7 +31,6 @@
|
|
|
34
31
|
"url": "https://github.com/terrazzoapp/terrazzo.git",
|
|
35
32
|
"directory": "./packages/cli/"
|
|
36
33
|
},
|
|
37
|
-
"license": "MIT",
|
|
38
34
|
"bin": {
|
|
39
35
|
"tz": "bin/cli.js",
|
|
40
36
|
"terrazzo": "bin/cli.js"
|
|
@@ -53,8 +49,8 @@
|
|
|
53
49
|
"mime": "^4.0.7",
|
|
54
50
|
"picocolors": "^1.1.1",
|
|
55
51
|
"yaml-to-momoa": "^0.0.6",
|
|
56
|
-
"@terrazzo/parser": "^0.
|
|
57
|
-
"@terrazzo/token-tools": "^0.
|
|
52
|
+
"@terrazzo/parser": "^0.8.0",
|
|
53
|
+
"@terrazzo/token-tools": "^0.8.0"
|
|
58
54
|
},
|
|
59
55
|
"devDependencies": {
|
|
60
56
|
"@vitejs/plugin-react-swc": "^3.10.0",
|
|
@@ -63,11 +59,10 @@
|
|
|
63
59
|
"vite": "^6.3.5"
|
|
64
60
|
},
|
|
65
61
|
"scripts": {
|
|
66
|
-
"build": "
|
|
67
|
-
"
|
|
68
|
-
"dev": "tsc -p tsconfig.build.json -w",
|
|
62
|
+
"build": "rolldown -c && attw --profile esm-only --pack . && vite build",
|
|
63
|
+
"dev": "rolldown -c -w",
|
|
69
64
|
"format": "biome check --fix --unsafe .",
|
|
70
|
-
"lint": "pnpm --filter @terrazzo/cli run \"/^lint
|
|
65
|
+
"lint": "pnpm --filter @terrazzo/cli run \"/^lint:(js|ts)/\"",
|
|
71
66
|
"lint:js": "biome check .",
|
|
72
67
|
"lint:ts": "tsc --noEmit",
|
|
73
68
|
"test": "vitest run"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineConfig } from 'rolldown';
|
|
2
|
+
import { dts } from 'rolldown-plugin-dts';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
input: {
|
|
6
|
+
index: './src/index.ts',
|
|
7
|
+
},
|
|
8
|
+
plugins: [dts()],
|
|
9
|
+
external: [
|
|
10
|
+
'@clack/prompts',
|
|
11
|
+
'@hono/node-server',
|
|
12
|
+
'@humanwhocodes/momoa',
|
|
13
|
+
'@terrazzo/parser',
|
|
14
|
+
'@terrazzo/token-lab',
|
|
15
|
+
'@terrazzo/token-tools',
|
|
16
|
+
'@types/escodegen',
|
|
17
|
+
'chokidar',
|
|
18
|
+
'detect-package-manager',
|
|
19
|
+
'dotenv',
|
|
20
|
+
'escodegen',
|
|
21
|
+
'merge-anything',
|
|
22
|
+
'meriyah',
|
|
23
|
+
'mime',
|
|
24
|
+
'picocolors',
|
|
25
|
+
'yaml-to-momoa',
|
|
26
|
+
],
|
|
27
|
+
output: {
|
|
28
|
+
dir: 'dist',
|
|
29
|
+
format: 'es',
|
|
30
|
+
sourcemap: true,
|
|
31
|
+
},
|
|
32
|
+
});
|
package/dist/build.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type BuildRunnerResult, type ConfigInit, type Logger } from '@terrazzo/parser';
|
|
2
|
-
import { type Flags } from './shared.js';
|
|
3
|
-
export interface BuildOptions {
|
|
4
|
-
flags: Flags;
|
|
5
|
-
config: ConfigInit;
|
|
6
|
-
configPath: string;
|
|
7
|
-
logger: Logger;
|
|
8
|
-
}
|
|
9
|
-
/** tz build */
|
|
10
|
-
export declare function buildCmd({ config, configPath, flags, logger }: BuildOptions): Promise<void>;
|
|
11
|
-
/** Write files */
|
|
12
|
-
export declare function writeFiles(result: BuildRunnerResult, { config, logger }: {
|
|
13
|
-
config: ConfigInit;
|
|
14
|
-
logger: Logger;
|
|
15
|
-
}): void;
|
|
16
|
-
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAgB,MAAM,kBAAkB,CAAC;AAItG,OAAO,EAEL,KAAK,KAAK,EAOX,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAe;AACf,wBAAsB,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,YAAY,iBAgFjF;AAED,kBAAkB;AAClB,wBAAgB,UAAU,CAAC,MAAM,EAAE,iBAAiB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,QAO/G"}
|
package/dist/build.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { build, parse } from '@terrazzo/parser';
|
|
5
|
-
import chokidar from 'chokidar';
|
|
6
|
-
import pc from 'picocolors';
|
|
7
|
-
import yamlToMomoa from 'yaml-to-momoa';
|
|
8
|
-
import { DEFAULT_TOKENS_PATH, GREEN_CHECK, cwd, loadTokens, printError, printSuccess, resolveConfig, } from './shared.js';
|
|
9
|
-
/** tz build */
|
|
10
|
-
export async function buildCmd({ config, configPath, flags, logger }) {
|
|
11
|
-
try {
|
|
12
|
-
const startTime = performance.now();
|
|
13
|
-
if (!Array.isArray(config.plugins) || !config.plugins.length) {
|
|
14
|
-
logger.error({
|
|
15
|
-
group: 'config',
|
|
16
|
-
message: `No plugins defined! Add some in ${configPath || 'terrazzo.config.js'}`,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
// first build
|
|
20
|
-
let rawSchemas = await loadTokens(config.tokens, { logger });
|
|
21
|
-
if (!rawSchemas) {
|
|
22
|
-
logger.error({
|
|
23
|
-
group: 'config',
|
|
24
|
-
message: `Error loading ${path.relative(fileURLToPath(cwd), fileURLToPath(config.tokens[0] || DEFAULT_TOKENS_PATH))}`,
|
|
25
|
-
});
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
let { tokens, sources } = await parse(rawSchemas, { config, logger, yamlToMomoa });
|
|
29
|
-
let result = await build(tokens, { sources, config, logger });
|
|
30
|
-
writeFiles(result, { config, logger });
|
|
31
|
-
// --watch (handle rebuild)
|
|
32
|
-
if (flags.watch) {
|
|
33
|
-
const dt = new Intl.DateTimeFormat('en-us', {
|
|
34
|
-
hour: '2-digit',
|
|
35
|
-
minute: '2-digit',
|
|
36
|
-
});
|
|
37
|
-
async function rebuild({ messageBefore, messageAfter } = {}) {
|
|
38
|
-
try {
|
|
39
|
-
if (messageBefore) {
|
|
40
|
-
logger.info({ group: 'plugin', label: 'watch', message: messageBefore });
|
|
41
|
-
}
|
|
42
|
-
rawSchemas = await loadTokens(config.tokens, { logger });
|
|
43
|
-
if (!rawSchemas) {
|
|
44
|
-
throw new Error(`Error loading ${path.relative(fileURLToPath(cwd), fileURLToPath(config.tokens[0] || DEFAULT_TOKENS_PATH))}`);
|
|
45
|
-
}
|
|
46
|
-
const parseResult = await parse(rawSchemas, { config, logger, yamlToMomoa });
|
|
47
|
-
tokens = parseResult.tokens;
|
|
48
|
-
sources = parseResult.sources;
|
|
49
|
-
result = await build(tokens, { sources, config, logger });
|
|
50
|
-
if (messageAfter) {
|
|
51
|
-
logger.info({ group: 'plugin', label: 'watch', message: messageAfter });
|
|
52
|
-
}
|
|
53
|
-
writeFiles(result, { config, logger });
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
console.error(pc.red(`✗ ${err.message || err}`));
|
|
57
|
-
// don’t exit! we’re watching, so continue as long as possible
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const tokenWatcher = chokidar.watch(config.tokens.map((filename) => fileURLToPath(filename)));
|
|
61
|
-
tokenWatcher.on('change', async (filename) => {
|
|
62
|
-
await rebuild({
|
|
63
|
-
messageBefore: `${pc.dim(dt.format(new Date()))} ${pc.green('tz')}} ${pc.yellow(filename)} updated ${GREEN_CHECK}`,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
const configWatcher = chokidar.watch(resolveConfig(configPath));
|
|
67
|
-
configWatcher.on('change', async () => {
|
|
68
|
-
await rebuild({
|
|
69
|
-
messageBefore: `${pc.dim(dt.format(new Date()))} ${pc.green('tz')} ${pc.yellow('Config updated. Reloading…')}`,
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
// keep process occupied
|
|
73
|
-
await new Promise(() => { });
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
printSuccess(`${Object.keys(tokens).length} token${Object.keys(tokens).length !== 1 ? 's' : ''} built`, startTime);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
printError(err.message);
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/** Write files */
|
|
85
|
-
export function writeFiles(result, { config, logger }) {
|
|
86
|
-
for (const { filename, contents } of result.outputFiles) {
|
|
87
|
-
const output = new URL(filename, config.outDir);
|
|
88
|
-
fs.mkdirSync(new URL('.', output), { recursive: true });
|
|
89
|
-
fs.writeFileSync(output, contents);
|
|
90
|
-
logger.debug({ group: 'parser', label: 'buildEnd', message: `Wrote file ${fileURLToPath(output)}` });
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=build.js.map
|
package/dist/build.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAwD,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACtG,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,mBAAmB,EAEnB,WAAW,EACX,GAAG,EACH,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,GACd,MAAM,aAAa,CAAC;AASrB,eAAe;AACf,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAgB;IAChF,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,WAAW,CAAC,G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AAC,CAAC,CAAC,EAAE,QAAQ,EACzF,SAAS,CACV,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,UAAU,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,kBAAkB;AAClB,MAAM,UAAU,UAAU,CAAC,MAAyB,EAAE,EAAE,MAAM,EAAE,MAAM,EAA0C;IAC9G,KAAK,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACxD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAChD,EAAE,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,aAAa,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;IACvG,CAAC;AACH,CAAC"}
|
package/dist/check.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type ConfigInit, type Logger } from '@terrazzo/parser';
|
|
2
|
-
export interface CheckOptions {
|
|
3
|
-
/** positional CLI args */
|
|
4
|
-
positionals: string[];
|
|
5
|
-
config: ConfigInit;
|
|
6
|
-
logger: Logger;
|
|
7
|
-
}
|
|
8
|
-
/** tz check */
|
|
9
|
-
export declare function checkCmd({ config, logger, positionals }: CheckOptions): Promise<void>;
|
|
10
|
-
//# sourceMappingURL=check.d.ts.map
|
package/dist/check.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAS,MAAM,kBAAkB,CAAC;AAIvE,MAAM,WAAW,YAAY;IAC3B,0BAA0B;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAe;AACf,wBAAsB,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,YAAY,iBAiB3E"}
|
package/dist/check.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { parse } from '@terrazzo/parser';
|
|
2
|
-
import yamlToMomoa from 'yaml-to-momoa';
|
|
3
|
-
import { loadTokens, printError, printSuccess, resolveTokenPath } from './shared.js';
|
|
4
|
-
/** tz check */
|
|
5
|
-
export async function checkCmd({ config, logger, positionals }) {
|
|
6
|
-
try {
|
|
7
|
-
const startTime = performance.now();
|
|
8
|
-
const tokenPaths = positionals.slice(1).length
|
|
9
|
-
? positionals.slice(1).map((tokenPath) => resolveTokenPath(tokenPath, { logger }))
|
|
10
|
-
: config.tokens;
|
|
11
|
-
const sources = await loadTokens(tokenPaths, { logger });
|
|
12
|
-
if (!sources?.length) {
|
|
13
|
-
logger.error({ group: 'config', message: 'Couldn’t find any tokens. Run `npx tz init` to create some.' });
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
await parse(sources, { config, continueOnError: true, logger, yamlToMomoa }); // will throw if errors
|
|
17
|
-
printSuccess('No errors', startTime);
|
|
18
|
-
}
|
|
19
|
-
catch (err) {
|
|
20
|
-
printError(err.message);
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=check.js.map
|
package/dist/check.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check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AClB,CAAC;AACH,CAAC"}
|
package/dist/help.d.ts
DELETED
package/dist/help.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,wBAAgB,OAAO,SAgBtB"}
|
package/dist/help.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/** Show help */
|
|
2
|
-
export function helpCmd() {
|
|
3
|
-
console.log(`tz
|
|
4
|
-
[commands]
|
|
5
|
-
build Build token artifacts from tokens.json
|
|
6
|
-
--watch, -w Watch tokens.json for changes and recompile
|
|
7
|
-
--no-lint Disable linters running on build
|
|
8
|
-
check [path] Check tokens.json for errors and run linters
|
|
9
|
-
lint [path] (alias of check)
|
|
10
|
-
init Create a starter tokens.json file
|
|
11
|
-
lab Manage your tokens with a web interface
|
|
12
|
-
|
|
13
|
-
[options]
|
|
14
|
-
--help Show this message
|
|
15
|
-
--config, -c Path to config (default: ./terrazzo.config.js)
|
|
16
|
-
--quiet Suppress warnings
|
|
17
|
-
`);
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=help.js.map
|
package/dist/help.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"help.js","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,MAAM,UAAU,OAAO;IACrB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;CAcb,CAAC,CAAC;AACH,CAAC"}
|
package/dist/init.d.ts
DELETED
package/dist/init.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AA6E/C,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,iBA6LpD"}
|
package/dist/init.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import { exec } from 'node:child_process';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { confirm, intro, multiselect, outro, select, spinner } from '@clack/prompts';
|
|
6
|
-
import { pluralize } from '@terrazzo/token-tools';
|
|
7
|
-
import { detect } from 'detect-package-manager';
|
|
8
|
-
import { generate } from 'escodegen';
|
|
9
|
-
import { parseModule } from 'meriyah';
|
|
10
|
-
import { DEFAULT_CONFIG_PATH, DEFAULT_TOKENS_PATH, cwd, loadConfig, printError } from './shared.js';
|
|
11
|
-
const INSTALL_COMMAND = {
|
|
12
|
-
npm: 'install -D --silent',
|
|
13
|
-
yarn: 'add -D --silent',
|
|
14
|
-
pnpm: 'add -D --silent',
|
|
15
|
-
bun: 'install -D --silent',
|
|
16
|
-
};
|
|
17
|
-
const DTCG_ROOT_URL = 'https://raw.githubusercontent.com/terrazzoapp/dtcg-examples/refs/heads/main/';
|
|
18
|
-
const DESIGN_SYSTEMS = {
|
|
19
|
-
'adobe-spectrum': {
|
|
20
|
-
name: 'Spectrum',
|
|
21
|
-
author: 'Adobe',
|
|
22
|
-
tokens: ['adobe-spectrum.json'],
|
|
23
|
-
},
|
|
24
|
-
'apple-hig': {
|
|
25
|
-
name: 'Human Interface Guidelines',
|
|
26
|
-
author: 'Apple',
|
|
27
|
-
tokens: ['apple-hig.json'],
|
|
28
|
-
},
|
|
29
|
-
'figma-sds': {
|
|
30
|
-
name: 'Simple Design System',
|
|
31
|
-
author: 'Figma',
|
|
32
|
-
tokens: ['figma-sds.json'],
|
|
33
|
-
},
|
|
34
|
-
'github-primer': {
|
|
35
|
-
name: 'Primer',
|
|
36
|
-
author: 'GitHub',
|
|
37
|
-
tokens: ['github-primer.json'],
|
|
38
|
-
},
|
|
39
|
-
'ibm-carbon': {
|
|
40
|
-
name: 'Carbon',
|
|
41
|
-
author: 'IBM',
|
|
42
|
-
tokens: ['ibm-carbon.json'],
|
|
43
|
-
},
|
|
44
|
-
'microsoft-fluent': {
|
|
45
|
-
name: 'Fluent',
|
|
46
|
-
author: 'Microsoft',
|
|
47
|
-
tokens: ['microsoft-fluent.json'],
|
|
48
|
-
},
|
|
49
|
-
radix: {
|
|
50
|
-
name: 'Radix',
|
|
51
|
-
author: 'Radix',
|
|
52
|
-
tokens: ['radix.json'],
|
|
53
|
-
},
|
|
54
|
-
'salesforce-lightning': {
|
|
55
|
-
name: 'Lightning',
|
|
56
|
-
author: 'Salesforce',
|
|
57
|
-
tokens: ['salesforce-lightning.json'],
|
|
58
|
-
},
|
|
59
|
-
'shopify-polaris': {
|
|
60
|
-
name: 'Polaris',
|
|
61
|
-
author: 'Shopify',
|
|
62
|
-
tokens: ['shopify-polaris.json'],
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
export async function initCmd({ logger }) {
|
|
66
|
-
try {
|
|
67
|
-
intro('⛋ Welcome to Terrazzo');
|
|
68
|
-
const packageManager = await detect({ cwd: fileURLToPath(cwd) });
|
|
69
|
-
// TODO: pass in CLI flags?
|
|
70
|
-
const { config, configPath } = await loadConfig({ cmd: 'init', flags: {}, logger });
|
|
71
|
-
const relConfigPath = configPath
|
|
72
|
-
? path.relative(fileURLToPath(cwd), fileURLToPath(new URL(configPath)))
|
|
73
|
-
: undefined;
|
|
74
|
-
let tokensPath = config.tokens[0];
|
|
75
|
-
let startFromDS = !(tokensPath && fs.existsSync(tokensPath));
|
|
76
|
-
// 1. tokens
|
|
77
|
-
if (tokensPath && fs.existsSync(tokensPath)) {
|
|
78
|
-
if (await confirm({
|
|
79
|
-
message: `Found tokens at ${path.relative(fileURLToPath(cwd), fileURLToPath(tokensPath))}. Overwrite with a new design system?`,
|
|
80
|
-
})) {
|
|
81
|
-
startFromDS = true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
tokensPath = DEFAULT_TOKENS_PATH;
|
|
86
|
-
}
|
|
87
|
-
if (startFromDS) {
|
|
88
|
-
const ds = DESIGN_SYSTEMS[(await select({
|
|
89
|
-
message: 'Start from existing design system?',
|
|
90
|
-
options: [
|
|
91
|
-
...Object.entries(DESIGN_SYSTEMS).map(([id, { author, name }]) => ({
|
|
92
|
-
value: id,
|
|
93
|
-
label: `${author} ${name}`,
|
|
94
|
-
})),
|
|
95
|
-
{ value: 'none', label: 'None' },
|
|
96
|
-
],
|
|
97
|
-
}))];
|
|
98
|
-
if (ds) {
|
|
99
|
-
// TODO: support multiple tokens files?
|
|
100
|
-
const s = spinner();
|
|
101
|
-
s.start('Downloading');
|
|
102
|
-
const tokenSource = await fetch(new URL(ds.tokens[0], DTCG_ROOT_URL)).then((res) => res.text());
|
|
103
|
-
fs.writeFileSync(tokensPath, tokenSource);
|
|
104
|
-
s.stop('Download complete');
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
// 2. plugins
|
|
108
|
-
const existingPlugins = config.plugins.map((p) => p.name);
|
|
109
|
-
const pluginSelection = await multiselect({
|
|
110
|
-
message: 'Install plugins?',
|
|
111
|
-
options: [
|
|
112
|
-
{ value: '@terrazzo/plugin-css', label: 'CSS' },
|
|
113
|
-
{ value: '@terrazzo/plugin-js', label: 'JS + TS' },
|
|
114
|
-
{ value: '@terrazzo/plugin-sass', label: 'Sass' },
|
|
115
|
-
{ value: '@terrazzo/plugin-tailwind', label: 'Tailwind' },
|
|
116
|
-
],
|
|
117
|
-
required: false,
|
|
118
|
-
});
|
|
119
|
-
const newPlugins = Array.isArray(pluginSelection)
|
|
120
|
-
? pluginSelection.filter((p) => !existingPlugins.includes(p))
|
|
121
|
-
: [];
|
|
122
|
-
if (newPlugins?.length) {
|
|
123
|
-
const plugins = newPlugins.map((p) => ({ specifier: p.replace('@terrazzo/plugin-', ''), package: p }));
|
|
124
|
-
const pluginCount = `${newPlugins.length} ${pluralize(newPlugins.length, 'plugin', 'plugins')}`;
|
|
125
|
-
const s = spinner();
|
|
126
|
-
s.start(`Installing ${pluginCount}`);
|
|
127
|
-
// note: thi sis async to show the spinner
|
|
128
|
-
await new Promise((resolve, reject) => {
|
|
129
|
-
const subprocess = exec([packageManager, INSTALL_COMMAND[packageManager], newPlugins.join(' ')].join(' '), {
|
|
130
|
-
cwd,
|
|
131
|
-
});
|
|
132
|
-
subprocess.on('error', reject);
|
|
133
|
-
subprocess.on('exit', resolve);
|
|
134
|
-
});
|
|
135
|
-
s.message('Updating config');
|
|
136
|
-
if (configPath) {
|
|
137
|
-
const ast = parseModule(fs.readFileSync(configPath, 'utf8'));
|
|
138
|
-
const astExport = ast.body.find((node) => node.type === 'ExportDefaultDeclaration');
|
|
139
|
-
// 2a. add plugin imports
|
|
140
|
-
// note: this has the potential to duplicate plugins, but we tried our
|
|
141
|
-
// best to filter already, and this may be the user’s fault if they
|
|
142
|
-
// selected to install a plugin already installed. But also, this is
|
|
143
|
-
// easily-fixable, so let’s not waste too much time here (and possibly
|
|
144
|
-
// introduce bugs).
|
|
145
|
-
ast.body.push(...plugins.map((p) => ({
|
|
146
|
-
type: 'ImportDeclaration',
|
|
147
|
-
source: { type: 'Literal', value: p.package },
|
|
148
|
-
specifiers: [{ type: 'ImportDefaultSpecifier', local: { type: 'Identifier', name: p.specifier } }],
|
|
149
|
-
attributes: [],
|
|
150
|
-
})));
|
|
151
|
-
// 2b. add plugins to config.plugins
|
|
152
|
-
if (!astExport) {
|
|
153
|
-
logger.error({ group: 'config', message: `SyntaxError: ${relConfigPath} does not have default export.` });
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const astConfig = (astExport.declaration.type === 'CallExpression'
|
|
157
|
-
? // export default defineConfig({ ... })
|
|
158
|
-
astExport.declaration.arguments[0]
|
|
159
|
-
: // export default { ... }
|
|
160
|
-
astExport.declaration);
|
|
161
|
-
if (astConfig.type !== 'ObjectExpression') {
|
|
162
|
-
logger.error({
|
|
163
|
-
group: 'config',
|
|
164
|
-
message: `Config: expected object default export, received ${astConfig.type}`,
|
|
165
|
-
});
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const pluginsArray = astConfig.properties.find((property) => property.type === 'Property' && property.key.type === 'Identifier' && property.key.name === 'plugins')?.value;
|
|
169
|
-
const pluginsAst = plugins.map((p) => ({
|
|
170
|
-
type: 'CallExpression',
|
|
171
|
-
callee: {
|
|
172
|
-
type: 'Identifier',
|
|
173
|
-
name: p.specifier,
|
|
174
|
-
},
|
|
175
|
-
arguments: [],
|
|
176
|
-
}));
|
|
177
|
-
if (pluginsArray) {
|
|
178
|
-
pluginsArray.elements.push(...pluginsAst);
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
astConfig.properties.push({
|
|
182
|
-
type: 'Property',
|
|
183
|
-
key: { type: 'Identifier', name: 'plugins' },
|
|
184
|
-
value: { type: 'ArrayExpression', elements: pluginsAst },
|
|
185
|
-
kind: 'init',
|
|
186
|
-
computed: false,
|
|
187
|
-
method: false,
|
|
188
|
-
shorthand: false,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
// 2c. update new file (and we’ll probably format it wrong but hey)
|
|
192
|
-
fs.writeFileSync(configPath, generate(ast, {
|
|
193
|
-
format: {
|
|
194
|
-
indent: { style: ' ' },
|
|
195
|
-
quotes: 'single',
|
|
196
|
-
semicolons: true,
|
|
197
|
-
},
|
|
198
|
-
}));
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
// 2a. write new config file (easy)
|
|
202
|
-
fs.writeFileSync(DEFAULT_CONFIG_PATH, `import { defineConfig } from '@terrazzo/cli';
|
|
203
|
-
${plugins.map((p) => `import ${p.specifier} from '${p.package}';`).join('\n')}
|
|
204
|
-
export default defineConfig({
|
|
205
|
-
tokens: ['./tokens.json'],
|
|
206
|
-
plugins: [
|
|
207
|
-
${plugins.map((p) => `${p.specifier}(),`).join('\n ')}
|
|
208
|
-
],
|
|
209
|
-
outDir: './dist/',
|
|
210
|
-
lint: {
|
|
211
|
-
/** @see https://terrazzo.app/docs/cli/lint */
|
|
212
|
-
},
|
|
213
|
-
});`);
|
|
214
|
-
}
|
|
215
|
-
s.stop(`Installed ${pluginCount}`);
|
|
216
|
-
}
|
|
217
|
-
outro('⛋ Done! 🎉');
|
|
218
|
-
}
|
|
219
|
-
catch (err) {
|
|
220
|
-
printError(err.message);
|
|
221
|
-
process.exit(1);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAe,WAAW,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEpG,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,qBAAqB;IAC1B,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE,iBAAiB;IACvB,GAAG,EAAE,qBAAqB;CAC3B,CAAC;AAgBF,MAAM,aAAa,GAAG,8EAA8E,CAAC;A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J,CAAC;iBAAM,CAAC;gBACN,mCAAmC;gBACnC,EAAE,CAAC,aAAa,CACd,mBAAmB,EACnB;EACR,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;MAIvE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;;;;;;IAMxD,CACK,CAAC;YACJ,CAAC;YACD,CAAC,CAAC,IAAI,CAAC,aAAa,WAAW,EAAE,CAAC,CAAC;QACrC,CAAC;QAED,KAAK,CAAC,YAAY,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,UAAU,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/dist/lab.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ConfigInit } from '@terrazzo/parser';
|
|
2
|
-
import type { Logger } from '@terrazzo/parser';
|
|
3
|
-
import type { Flags } from './shared.js';
|
|
4
|
-
export interface BuildOptions {
|
|
5
|
-
flags: Flags;
|
|
6
|
-
config: ConfigInit;
|
|
7
|
-
configPath: string;
|
|
8
|
-
logger: Logger;
|
|
9
|
-
}
|
|
10
|
-
export declare function labCmd({ config, logger }: BuildOptions): Promise<void>;
|
|
11
|
-
//# sourceMappingURL=lab.d.ts.map
|
package/dist/lab.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lab.d.ts","sourceRoot":"","sources":["../src/lab.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,YAAY,iBA6E5D"}
|
package/dist/lab.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { createReadStream, createWriteStream } from 'node:fs';
|
|
2
|
-
import { readdir } from 'node:fs/promises';
|
|
3
|
-
import { Readable, Writable } from 'node:stream';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { serve } from '@hono/node-server';
|
|
6
|
-
import mime from 'mime';
|
|
7
|
-
export async function labCmd({ config, logger }) {
|
|
8
|
-
/** TODO: handle multiple files */
|
|
9
|
-
const [tokenFileUrl] = config.tokens;
|
|
10
|
-
const staticFiles = new Set();
|
|
11
|
-
const dirEntries = await readdir(fileURLToPath(import.meta.resolve('./lab')), {
|
|
12
|
-
withFileTypes: true,
|
|
13
|
-
recursive: true,
|
|
14
|
-
});
|
|
15
|
-
for (const entry of dirEntries) {
|
|
16
|
-
if (entry.isFile() === false) {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
const absolutePath = `${entry.parentPath.replaceAll('\\', '/')}/${entry.name}`;
|
|
20
|
-
staticFiles.add(absolutePath.replace(fileURLToPath(import.meta.resolve('./lab')).replaceAll('\\', '/'), ''));
|
|
21
|
-
}
|
|
22
|
-
const server = serve({
|
|
23
|
-
port: 9000,
|
|
24
|
-
overrideGlobalObjects: false,
|
|
25
|
-
async fetch(request) {
|
|
26
|
-
const url = new URL(request.url);
|
|
27
|
-
const pathname = url.pathname;
|
|
28
|
-
if (pathname === '/') {
|
|
29
|
-
return new Response(Readable.toWeb(createReadStream(fileURLToPath(import.meta.resolve('./lab/index.html')))), {
|
|
30
|
-
headers: {
|
|
31
|
-
'Content-Type': 'text/html',
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
if (pathname === '/api/tokens') {
|
|
36
|
-
if (request.method === 'GET') {
|
|
37
|
-
return new Response(Readable.toWeb(createReadStream(tokenFileUrl)), {
|
|
38
|
-
headers: {
|
|
39
|
-
'Content-Type': 'application/json',
|
|
40
|
-
'Cache-Control': 'no-cache',
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
else if (request.method === 'POST' && request.body) {
|
|
45
|
-
await request.body.pipeTo(Writable.toWeb(createWriteStream(tokenFileUrl)));
|
|
46
|
-
return new Response(JSON.stringify({ success: true }), {
|
|
47
|
-
headers: {
|
|
48
|
-
'Content-Type': 'application/json',
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (staticFiles.has(pathname)) {
|
|
54
|
-
return new Response(Readable.toWeb(createReadStream(fileURLToPath(import.meta.resolve(`./lab${pathname}`)))), {
|
|
55
|
-
headers: { 'Content-Type': mime.getType(pathname) ?? 'application/octet-stream' },
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
return new Response('Not found', { status: 404 });
|
|
59
|
-
},
|
|
60
|
-
}, (info) => {
|
|
61
|
-
logger.info({
|
|
62
|
-
group: 'server',
|
|
63
|
-
message: `Token Lab running at http://${info.address === '::' ? 'localhost' : info.address}:${info.port}`,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
/**
|
|
67
|
-
* The cli entrypoint is going to manually exit the process after labCmd returns.
|
|
68
|
-
*/
|
|
69
|
-
await new Promise((resolve, reject) => {
|
|
70
|
-
server.on('close', resolve);
|
|
71
|
-
server.on('error', reject);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=lab.js.map
|