@pantoken/cli 0.1.5 → 0.1.7

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/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Theme } from "@pantoken/model";
2
-
3
2
  //#region src/index.d.ts
4
3
  /** The parsed CLI invocation. */
5
4
  interface CliArgs {
package/dist/index.mjs CHANGED
@@ -100,6 +100,154 @@ let package = Package(
100
100
  targets: [.target(name: "${name}", path: "Sources/${name}")]
101
101
  )
102
102
  `;
103
+ /** Validate the invocation is a runnable `generate <target>`; throw a usage error otherwise. */
104
+ function assertGenerateTarget(args) {
105
+ if (args.command !== "generate") throw new Error(`Unknown command "${args.command}". Usage: pantoken generate <target> [--out dir] [--theme t]`);
106
+ if (PLANNED.has(args.target)) throw new Error(`Target "${args.target}" is planned but not implemented yet. Available now: ${[...SUPPORTED].join(", ")}.`);
107
+ if (!SUPPORTED.has(args.target)) throw new Error(`Unknown target "${args.target}". Available: ${[...SUPPORTED].join(", ")}.`);
108
+ }
109
+ /** Generate Swift token source plus an SPM `Package.swift` manifest stub. */
110
+ async function runSwift(args) {
111
+ const file = await generateSwift({
112
+ outDir: join(args.out, "Sources", args.className),
113
+ theme: args.theme,
114
+ className: args.className,
115
+ icons: args.icons
116
+ });
117
+ const manifestPath = join(args.out, "Package.swift");
118
+ mkdirSync(dirname(manifestPath), { recursive: true });
119
+ writeFileSync(manifestPath, SWIFT_PACKAGE_MANIFEST(args.className));
120
+ console.log(`✓ pantoken: wrote ${file}`);
121
+ console.log(`✓ pantoken: wrote ${manifestPath} (SwiftPM manifest stub)`);
122
+ }
123
+ /** Generate the Android token resources. */
124
+ async function runAndroid(args) {
125
+ const files = await generateAndroid({
126
+ outDir: args.out,
127
+ theme: args.theme,
128
+ icons: args.icons
129
+ });
130
+ for (const file of files) console.log(`✓ pantoken: wrote ${file}`);
131
+ }
132
+ /** Generate the Jetpack Compose token source. */
133
+ async function runCompose(args) {
134
+ const file = await generateCompose({
135
+ outDir: args.out,
136
+ theme: args.theme,
137
+ className: args.className
138
+ });
139
+ console.log(`✓ pantoken: wrote ${file}`);
140
+ }
141
+ /** Generate the Flutter token source. */
142
+ async function runFlutter(args) {
143
+ const file = await generateFlutter({
144
+ outDir: args.out,
145
+ theme: args.theme,
146
+ className: args.className,
147
+ icons: args.icons
148
+ });
149
+ console.log(`✓ pantoken: wrote ${file}`);
150
+ }
151
+ /** Write the WordPress `theme.json`. */
152
+ function runWordpress(args) {
153
+ mkdirSync(args.out, { recursive: true });
154
+ const file = join(args.out, "theme.json");
155
+ writeFileSync(file, `${JSON.stringify(toThemeJson(byTheme(args.theme)), null, 2)}\n`);
156
+ console.log(`✓ pantoken: wrote ${file}`);
157
+ }
158
+ /** Write the vanilla `variables.json`. */
159
+ function runVanilla(args) {
160
+ mkdirSync(args.out, { recursive: true });
161
+ const file = join(args.out, "variables.json");
162
+ writeFileSync(file, `${JSON.stringify(toVanillaVariables(byTheme(args.theme)), null, 2)}\n`);
163
+ console.log(`✓ pantoken: wrote ${file}`);
164
+ }
165
+ /** Write the Mintlify `docs.json`. */
166
+ function runMintlify(args) {
167
+ mkdirSync(args.out, { recursive: true });
168
+ const file = join(args.out, "docs.json");
169
+ writeFileSync(file, `${JSON.stringify(toMintlifyConfig(byTheme(args.theme)), null, 2)}\n`);
170
+ console.log(`✓ pantoken: wrote ${file}`);
171
+ }
172
+ /** Write the Drupal theme assets. */
173
+ function runDrupal(args) {
174
+ for (const asset of toDrupalTheme()) {
175
+ const file = join(args.out, asset.path);
176
+ mkdirSync(dirname(file), { recursive: true });
177
+ writeFileSync(file, asset.content);
178
+ console.log(`✓ pantoken: wrote ${file}`);
179
+ }
180
+ }
181
+ /** Write the Rust token source for the egui or iced format. */
182
+ function runRust(args) {
183
+ const format = args.format === "iced" ? "iced" : "egui";
184
+ const file = args.out.includes(".") ? args.out : join(args.out, "tokens.rs");
185
+ mkdirSync(dirname(file), { recursive: true });
186
+ writeFileSync(file, generateRust({
187
+ format,
188
+ theme: args.theme
189
+ }));
190
+ console.log(`✓ pantoken: wrote ${file}`);
191
+ }
192
+ /** Write a swatch palette in the requested format (ase, gpl, sketch, or svg). */
193
+ function runSwatches(args) {
194
+ const format = args.format ?? "ase";
195
+ const swatches = toSwatches(byTheme(args.theme));
196
+ const ext = format === "sketch" ? "sketchpalette" : format;
197
+ const file = args.out.includes(".") ? args.out : join(args.out, `instructure.${ext}`);
198
+ mkdirSync(dirname(file), { recursive: true });
199
+ if (format === "ase") writeFileSync(file, toAse(swatches));
200
+ else if (format === "gpl") writeFileSync(file, toGpl(swatches));
201
+ else if (format === "sketch") writeFileSync(file, `${JSON.stringify(toSketchPalette(swatches), null, 2)}\n`);
202
+ else if (format === "svg") writeFileSync(file, toSvg(swatches));
203
+ else throw new Error(`Unknown swatch format "${format}". Use ase, gpl, sketch, or svg.`);
204
+ console.log(`✓ pantoken: wrote ${file}`);
205
+ }
206
+ /** Build and write the icon font (TTF, WOFF2, CSS, and codepoints). */
207
+ async function runIconFont(args) {
208
+ const font = await buildIconFont({
209
+ theme: args.theme,
210
+ icons: args.icons,
211
+ fontName: args.className
212
+ });
213
+ mkdirSync(args.out, { recursive: true });
214
+ const ttf = join(args.out, `${args.className}.ttf`);
215
+ const woff2 = join(args.out, `${args.className}.woff2`);
216
+ const cssFile = join(args.out, "icons.css");
217
+ const codepoints = join(args.out, "codepoints.json");
218
+ writeFileSync(ttf, font.ttf);
219
+ writeFileSync(woff2, font.woff2);
220
+ writeFileSync(cssFile, font.css);
221
+ writeFileSync(codepoints, `${JSON.stringify(font.codepoints, null, 2)}\n`);
222
+ for (const file of [
223
+ ttf,
224
+ woff2,
225
+ cssFile,
226
+ codepoints
227
+ ]) console.log(`✓ pantoken: wrote ${file}`);
228
+ }
229
+ /** Write the Jekyll or Hugo static-site assets (same asset shape, different source). */
230
+ function runStaticSite(args) {
231
+ const assets = args.target === "jekyll" ? toJekyllAssets() : toHugoAssets();
232
+ for (const asset of assets) {
233
+ const file = join(args.out, asset.path);
234
+ mkdirSync(dirname(file), { recursive: true });
235
+ writeFileSync(file, asset.content);
236
+ console.log(`✓ pantoken: wrote ${file}`);
237
+ }
238
+ }
239
+ /** Write the Pendo `global.css`, honouring the `--no-scope`/`--no-important`/`--no-prune` flags. */
240
+ function runPendo(args) {
241
+ mkdirSync(args.out, { recursive: true });
242
+ const file = join(args.out, "global.css");
243
+ writeFileSync(file, buildPendoCss({
244
+ theme: args.theme,
245
+ scope: !args.noScope,
246
+ important: !args.noImportant,
247
+ prune: !args.noPrune
248
+ }));
249
+ console.log(`✓ pantoken: wrote ${file}`);
250
+ }
103
251
  /**
104
252
  * Run the CLI.
105
253
  *
@@ -120,149 +268,42 @@ let package = Package(
120
268
  */
121
269
  async function run(argv) {
122
270
  const args = parseArgs(argv);
123
- if (args.command !== "generate") throw new Error(`Unknown command "${args.command}". Usage: pantoken generate <target> [--out dir] [--theme t]`);
124
- if (PLANNED.has(args.target)) throw new Error(`Target "${args.target}" is planned but not implemented yet. Available now: ${[...SUPPORTED].join(", ")}.`);
125
- if (!SUPPORTED.has(args.target)) throw new Error(`Unknown target "${args.target}". Available: ${[...SUPPORTED].join(", ")}.`);
126
- if (args.target === "swift") {
127
- const file = await generateSwift({
128
- outDir: join(args.out, "Sources", args.className),
129
- theme: args.theme,
130
- className: args.className,
131
- icons: args.icons
132
- });
133
- const manifestPath = join(args.out, "Package.swift");
134
- mkdirSync(dirname(manifestPath), { recursive: true });
135
- writeFileSync(manifestPath, SWIFT_PACKAGE_MANIFEST(args.className));
136
- console.log(`✓ pantoken: wrote ${file}`);
137
- console.log(`✓ pantoken: wrote ${manifestPath} (SwiftPM manifest stub)`);
138
- return;
139
- }
140
- if (args.target === "android") {
141
- const files = await generateAndroid({
142
- outDir: args.out,
143
- theme: args.theme,
144
- icons: args.icons
145
- });
146
- for (const file of files) console.log(`✓ pantoken: wrote ${file}`);
147
- return;
148
- }
149
- if (args.target === "compose") {
150
- const file = await generateCompose({
151
- outDir: args.out,
152
- theme: args.theme,
153
- className: args.className
154
- });
155
- console.log(`✓ pantoken: wrote ${file}`);
156
- return;
157
- }
158
- if (args.target === "flutter") {
159
- const file = await generateFlutter({
160
- outDir: args.out,
161
- theme: args.theme,
162
- className: args.className,
163
- icons: args.icons
164
- });
165
- console.log(`✓ pantoken: wrote ${file}`);
166
- return;
167
- }
271
+ assertGenerateTarget(args);
272
+ if (args.target === "swift") return runSwift(args);
273
+ if (args.target === "android") return runAndroid(args);
274
+ if (args.target === "compose") return runCompose(args);
275
+ if (args.target === "flutter") return runFlutter(args);
168
276
  if (args.target === "wordpress") {
169
- mkdirSync(args.out, { recursive: true });
170
- const file = join(args.out, "theme.json");
171
- writeFileSync(file, `${JSON.stringify(toThemeJson(byTheme(args.theme)), null, 2)}\n`);
172
- console.log(`✓ pantoken: wrote ${file}`);
277
+ runWordpress(args);
173
278
  return;
174
279
  }
175
280
  if (args.target === "vanilla") {
176
- mkdirSync(args.out, { recursive: true });
177
- const file = join(args.out, "variables.json");
178
- writeFileSync(file, `${JSON.stringify(toVanillaVariables(byTheme(args.theme)), null, 2)}\n`);
179
- console.log(`✓ pantoken: wrote ${file}`);
281
+ runVanilla(args);
180
282
  return;
181
283
  }
182
284
  if (args.target === "mintlify") {
183
- mkdirSync(args.out, { recursive: true });
184
- const file = join(args.out, "docs.json");
185
- writeFileSync(file, `${JSON.stringify(toMintlifyConfig(byTheme(args.theme)), null, 2)}\n`);
186
- console.log(`✓ pantoken: wrote ${file}`);
285
+ runMintlify(args);
187
286
  return;
188
287
  }
189
288
  if (args.target === "drupal") {
190
- for (const asset of toDrupalTheme()) {
191
- const file = join(args.out, asset.path);
192
- mkdirSync(dirname(file), { recursive: true });
193
- writeFileSync(file, asset.content);
194
- console.log(`✓ pantoken: wrote ${file}`);
195
- }
289
+ runDrupal(args);
196
290
  return;
197
291
  }
198
292
  if (args.target === "rust") {
199
- const format = args.format === "iced" ? "iced" : "egui";
200
- const file = args.out.includes(".") ? args.out : join(args.out, "tokens.rs");
201
- mkdirSync(dirname(file), { recursive: true });
202
- writeFileSync(file, generateRust({
203
- format,
204
- theme: args.theme
205
- }));
206
- console.log(`✓ pantoken: wrote ${file}`);
293
+ runRust(args);
207
294
  return;
208
295
  }
209
296
  if (args.target === "swatches") {
210
- const format = args.format ?? "ase";
211
- const swatches = toSwatches(byTheme(args.theme));
212
- const ext = format === "sketch" ? "sketchpalette" : format;
213
- const file = args.out.includes(".") ? args.out : join(args.out, `instructure.${ext}`);
214
- mkdirSync(dirname(file), { recursive: true });
215
- if (format === "ase") writeFileSync(file, toAse(swatches));
216
- else if (format === "gpl") writeFileSync(file, toGpl(swatches));
217
- else if (format === "sketch") writeFileSync(file, `${JSON.stringify(toSketchPalette(swatches), null, 2)}\n`);
218
- else if (format === "svg") writeFileSync(file, toSvg(swatches));
219
- else throw new Error(`Unknown swatch format "${format}". Use ase, gpl, sketch, or svg.`);
220
- console.log(`✓ pantoken: wrote ${file}`);
221
- return;
222
- }
223
- if (args.target === "icon-font") {
224
- const font = await buildIconFont({
225
- theme: args.theme,
226
- icons: args.icons,
227
- fontName: args.className
228
- });
229
- mkdirSync(args.out, { recursive: true });
230
- const ttf = join(args.out, `${args.className}.ttf`);
231
- const woff2 = join(args.out, `${args.className}.woff2`);
232
- const cssFile = join(args.out, "icons.css");
233
- const codepoints = join(args.out, "codepoints.json");
234
- writeFileSync(ttf, font.ttf);
235
- writeFileSync(woff2, font.woff2);
236
- writeFileSync(cssFile, font.css);
237
- writeFileSync(codepoints, `${JSON.stringify(font.codepoints, null, 2)}\n`);
238
- for (const file of [
239
- ttf,
240
- woff2,
241
- cssFile,
242
- codepoints
243
- ]) console.log(`✓ pantoken: wrote ${file}`);
297
+ runSwatches(args);
244
298
  return;
245
299
  }
300
+ if (args.target === "icon-font") return runIconFont(args);
246
301
  if (args.target === "jekyll" || args.target === "hugo") {
247
- const assets = args.target === "jekyll" ? toJekyllAssets() : toHugoAssets();
248
- for (const asset of assets) {
249
- const file = join(args.out, asset.path);
250
- mkdirSync(dirname(file), { recursive: true });
251
- writeFileSync(file, asset.content);
252
- console.log(`✓ pantoken: wrote ${file}`);
253
- }
302
+ runStaticSite(args);
254
303
  return;
255
304
  }
256
305
  if (args.target === "pendo") {
257
- mkdirSync(args.out, { recursive: true });
258
- const file = join(args.out, "global.css");
259
- writeFileSync(file, buildPendoCss({
260
- theme: args.theme,
261
- scope: !args.noScope,
262
- important: !args.noImportant,
263
- prune: !args.noPrune
264
- }));
265
- console.log(`✓ pantoken: wrote ${file}`);
306
+ runPendo(args);
266
307
  return;
267
308
  }
268
309
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pantoken/cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "pantoken generate <target> — emit native design-token source (Swift now; Kotlin/Dart/Drupal to follow).",
5
5
  "homepage": "https://pantoken.iywahl.com",
6
6
  "bugs": "https://github.com/thedannywahl/pantoken/issues",