@tamagui/cli 2.7.7 → 3.0.0-0.canary.1791056644527
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/add.cjs +76 -87
- package/dist/build.cjs +421 -278
- package/dist/cli.cjs +410 -340
- package/dist/generate-prompt.cjs +37 -386
- package/dist/generate.cjs +45 -54
- package/dist/icons.cjs +263 -0
- package/dist/index.cjs +1 -1
- package/dist/migrate.cjs +443 -0
- package/dist/preview-theme.cjs +70 -0
- package/dist/setup-prompt.cjs +216 -0
- package/dist/to-tailwind-default-config.cjs +874 -0
- package/dist/to-tailwind.cjs +213 -0
- package/dist/update-template.cjs +43 -52
- package/dist/update.cjs +14 -18
- package/dist/upgrade.cjs +417 -401
- package/dist/utils.cjs +84 -101
- package/metro.cjs +1 -0
- package/metro.d.ts +1 -0
- package/metro.mjs +1 -0
- package/package.json +45 -14
- package/src/build.ts +579 -361
- package/src/cli.ts +171 -24
- package/src/generate-prompt.ts +18 -526
- package/src/icons.ts +308 -0
- package/src/migrate.ts +428 -0
- package/src/preview-theme.ts +54 -0
- package/src/setup-prompt.ts +192 -0
- package/src/to-tailwind-default-config.ts +852 -0
- package/src/to-tailwind.ts +313 -0
- package/src/upgrade.ts +30 -33
- package/src/utils.ts +11 -9
- package/types/add.d.ts +1 -1
- package/types/add.d.ts.map +1 -1
- package/types/build.d.ts +2 -1
- package/types/build.d.ts.map +1 -1
- package/types/generate-prompt.d.ts +2 -2
- package/types/generate-prompt.d.ts.map +1 -1
- package/types/icons.d.ts +14 -0
- package/types/icons.d.ts.map +1 -0
- package/types/migrate.d.ts +7 -0
- package/types/migrate.d.ts.map +1 -0
- package/types/preview-theme.d.ts +8 -0
- package/types/preview-theme.d.ts.map +1 -0
- package/types/setup-prompt.d.ts +5 -0
- package/types/setup-prompt.d.ts.map +1 -0
- package/types/to-tailwind-default-config.d.ts +53 -0
- package/types/to-tailwind-default-config.d.ts.map +1 -0
- package/types/to-tailwind.d.ts +16 -0
- package/types/to-tailwind.d.ts.map +1 -0
- package/types/upgrade.d.ts.map +1 -1
- package/types/utils.d.ts.map +1 -1
- package/vite.cjs +1 -0
- package/vite.d.ts +1 -0
- package/vite.mjs +1 -0
package/src/cli.ts
CHANGED
|
@@ -3,30 +3,62 @@ import chalk from 'chalk'
|
|
|
3
3
|
|
|
4
4
|
import { disposeAll, getOptions } from './utils'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
;['exit', 'SIGINT'].forEach((_) => {
|
|
8
|
-
process.on(_, () => {
|
|
9
|
-
disposeAll()
|
|
10
|
-
process.exit()
|
|
11
|
-
})
|
|
12
|
-
})
|
|
6
|
+
process.on('exit', disposeAll)
|
|
13
7
|
|
|
14
8
|
const COMMAND_MAP = {
|
|
15
9
|
check: {
|
|
16
|
-
description: `Checks
|
|
10
|
+
description: `Checks flat style values, inconsistent versions, duplicate installs, lockfile issues, and missing config.`,
|
|
17
11
|
shorthands: [],
|
|
18
12
|
flags: {
|
|
19
13
|
'--help': Boolean,
|
|
20
14
|
'--debug': Boolean,
|
|
21
15
|
'--verbose': Boolean,
|
|
16
|
+
'--styles-only': Boolean,
|
|
17
|
+
'--deps-only': Boolean,
|
|
18
|
+
'--strict': Boolean,
|
|
22
19
|
},
|
|
23
20
|
async run() {
|
|
24
21
|
const { _, ...flags } = arg(this.flags)
|
|
25
22
|
const options = await getOptions({
|
|
26
23
|
debug: flags['--debug'] ? (flags['--verbose'] ? 'verbose' : true) : false,
|
|
24
|
+
loadTamaguiOptions: flags['--strict'] && !flags['--deps-only'],
|
|
27
25
|
})
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (!flags['--styles-only']) {
|
|
27
|
+
const { checkDeps } = require('@tamagui/static/checkDeps')
|
|
28
|
+
await checkDeps(options.paths.root)
|
|
29
|
+
}
|
|
30
|
+
if (flags['--deps-only']) return
|
|
31
|
+
if (flags['--strict']) {
|
|
32
|
+
if (!options.tamaguiOptions.config) {
|
|
33
|
+
throw new Error('Strict style checking requires a Tamagui config.')
|
|
34
|
+
}
|
|
35
|
+
const { loadTamagui } = require('@tamagui/static/loadTamagui')
|
|
36
|
+
process.env.TAMAGUI_KEEP_THEMES = '1'
|
|
37
|
+
const loaded = await loadTamagui(
|
|
38
|
+
{ ...options.tamaguiOptions, platform: 'web' },
|
|
39
|
+
true
|
|
40
|
+
)
|
|
41
|
+
if (!loaded?.tamaguiConfig) {
|
|
42
|
+
throw new Error('Unable to load the Tamagui config for strict style checking.')
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const { checkStyleFiles, formatCheckResults, MissingConfigArtifactError } =
|
|
46
|
+
require('@tamagui/language-service/check') as any
|
|
47
|
+
try {
|
|
48
|
+
const result = checkStyleFiles({
|
|
49
|
+
root: options.paths.root,
|
|
50
|
+
configPath: options.paths.conf,
|
|
51
|
+
strict: flags['--strict'],
|
|
52
|
+
})
|
|
53
|
+
console.info(formatCheckResults(result))
|
|
54
|
+
if (result.diagnosticCount > 0) process.exitCode = 1
|
|
55
|
+
} catch (error: any) {
|
|
56
|
+
if (error instanceof MissingConfigArtifactError && !flags['--strict']) {
|
|
57
|
+
console.warn(chalk.yellow(`skipping flat value check: ${error.message}`))
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
throw error
|
|
61
|
+
}
|
|
30
62
|
},
|
|
31
63
|
},
|
|
32
64
|
|
|
@@ -46,18 +78,7 @@ const COMMAND_MAP = {
|
|
|
46
78
|
})
|
|
47
79
|
const { loadTamagui } = require('@tamagui/static/loadTamagui')
|
|
48
80
|
process.env.TAMAGUI_KEEP_THEMES = '1'
|
|
49
|
-
await loadTamagui({
|
|
50
|
-
...options.tamaguiOptions,
|
|
51
|
-
platform: 'web',
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
// also generate prompt to .tamagui/prompt.md
|
|
55
|
-
const { generatePrompt } = require('./generate-prompt')
|
|
56
|
-
const { join } = require('node:path')
|
|
57
|
-
await generatePrompt({
|
|
58
|
-
...options,
|
|
59
|
-
output: join(options.paths.dotDir, 'prompt.md'),
|
|
60
|
-
})
|
|
81
|
+
await loadTamagui({ ...options.tamaguiOptions, platform: 'web' }, true)
|
|
61
82
|
},
|
|
62
83
|
},
|
|
63
84
|
|
|
@@ -146,6 +167,38 @@ const COMMAND_MAP = {
|
|
|
146
167
|
},
|
|
147
168
|
},
|
|
148
169
|
|
|
170
|
+
icons: {
|
|
171
|
+
shorthands: [],
|
|
172
|
+
description: `Generate themed SVG icon components from Lucide, Heroicons, Phosphor, or a folder of svgs.`,
|
|
173
|
+
usage: `$ tamagui icons add Search ChevronDown
|
|
174
|
+
$ tamagui icons add Copy --from phosphor --weight bold
|
|
175
|
+
$ tamagui icons add Clipboard --from heroicons --variant solid
|
|
176
|
+
$ tamagui icons add Logo --from ./assets/icons --out src/icons
|
|
177
|
+
$ tamagui icons add Search=magnifying-glass --from phosphor`,
|
|
178
|
+
flags: {
|
|
179
|
+
'--help': Boolean,
|
|
180
|
+
'--from': String,
|
|
181
|
+
'--weight': String,
|
|
182
|
+
'--variant': String,
|
|
183
|
+
'--out': String,
|
|
184
|
+
},
|
|
185
|
+
async run() {
|
|
186
|
+
const { _, ...flags } = arg(this.flags)
|
|
187
|
+
const [_cmd, subcommand, ...names] = _
|
|
188
|
+
if (subcommand !== 'add') {
|
|
189
|
+
throw new Error('usage: tamagui icons add <Name...> [--from] [--out]')
|
|
190
|
+
}
|
|
191
|
+
const { addIcons } = require('./icons')
|
|
192
|
+
await addIcons({
|
|
193
|
+
names,
|
|
194
|
+
from: flags['--from'],
|
|
195
|
+
weight: flags['--weight'],
|
|
196
|
+
variant: flags['--variant'],
|
|
197
|
+
out: flags['--out'],
|
|
198
|
+
})
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
|
|
149
202
|
build: {
|
|
150
203
|
shorthands: ['b'],
|
|
151
204
|
description: `Use to pre-build a Tamagui component directory. Use -- to run a command after optimization, then auto-restore files.`,
|
|
@@ -227,6 +280,68 @@ const COMMAND_MAP = {
|
|
|
227
280
|
},
|
|
228
281
|
},
|
|
229
282
|
|
|
283
|
+
setup: {
|
|
284
|
+
shorthands: [],
|
|
285
|
+
description: `Print an AI-agent prompt for adding Tamagui to a project for the first time`,
|
|
286
|
+
usage: `$ tamagui setup`,
|
|
287
|
+
flags: {
|
|
288
|
+
'--help': Boolean,
|
|
289
|
+
},
|
|
290
|
+
async run() {
|
|
291
|
+
const { printSetupPrompt } = require('./setup-prompt')
|
|
292
|
+
printSetupPrompt()
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
|
|
296
|
+
migrate: {
|
|
297
|
+
shorthands: [],
|
|
298
|
+
description: `Print an AI-agent prompt for migrating a Tamagui app to v3`,
|
|
299
|
+
usage: `$ tamagui migrate --from v2
|
|
300
|
+
$ tamagui migrate --from v1`,
|
|
301
|
+
flags: {
|
|
302
|
+
'--help': Boolean,
|
|
303
|
+
'--from': String,
|
|
304
|
+
},
|
|
305
|
+
async run() {
|
|
306
|
+
const { _, ...flags } = arg(this.flags)
|
|
307
|
+
const [_cmd, fromArg] = _
|
|
308
|
+
const { printMigrationPrompt } = require('./migrate')
|
|
309
|
+
|
|
310
|
+
printMigrationPrompt({
|
|
311
|
+
from: flags['--from'] || fromArg,
|
|
312
|
+
})
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
'to-tailwind': {
|
|
317
|
+
shorthands: [],
|
|
318
|
+
description: `Convert Tamagui JSX props in files or globs to Tailwind className syntax`,
|
|
319
|
+
flags: {
|
|
320
|
+
'--help': Boolean,
|
|
321
|
+
'--write': Boolean,
|
|
322
|
+
// path to the app's tamagui config so token/media/shorthand resolution uses the app's
|
|
323
|
+
// ACTUAL scales, not the bundled default fallback.
|
|
324
|
+
'--config': String,
|
|
325
|
+
// acknowledge use of the bundled default scales (required for --write without --config).
|
|
326
|
+
'--use-default-config': Boolean,
|
|
327
|
+
// opt in to DOM renaming (View→div). default: preserve Tamagui components (RN-safe).
|
|
328
|
+
'--rename-dom': Boolean,
|
|
329
|
+
},
|
|
330
|
+
async run() {
|
|
331
|
+
const { _, ...flags } = arg(this.flags)
|
|
332
|
+
const { toTailwind } = require('./to-tailwind')
|
|
333
|
+
const [_cmd, ...patterns] = _
|
|
334
|
+
|
|
335
|
+
await toTailwind({
|
|
336
|
+
patterns,
|
|
337
|
+
write: flags['--write'],
|
|
338
|
+
configPath: flags['--config'],
|
|
339
|
+
useDefaultConfig: flags['--use-default-config'],
|
|
340
|
+
renameDom: flags['--rename-dom'],
|
|
341
|
+
})
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
|
|
230
345
|
'update-template': {
|
|
231
346
|
shorthands: ['ut'],
|
|
232
347
|
description: `Used to update your git repo with the source template. (e.g. Takeout)`,
|
|
@@ -269,6 +384,31 @@ const COMMAND_MAP = {
|
|
|
269
384
|
})
|
|
270
385
|
},
|
|
271
386
|
},
|
|
387
|
+
|
|
388
|
+
'preview-theme': {
|
|
389
|
+
shorthands: ['preview'],
|
|
390
|
+
description: `Preview a theme configuration in the browser on tamagui.dev/theme`,
|
|
391
|
+
usage: `$ tamagui preview-theme ./theme.json
|
|
392
|
+
$ tamagui preview-theme --theme '{"palettes": ...}'
|
|
393
|
+
$ tamagui preview-theme ./theme.json --print`,
|
|
394
|
+
flags: {
|
|
395
|
+
'--help': Boolean,
|
|
396
|
+
'--theme': String,
|
|
397
|
+
'--url': String,
|
|
398
|
+
'--print': Boolean,
|
|
399
|
+
},
|
|
400
|
+
async run() {
|
|
401
|
+
const { _, ...flags } = arg(this.flags)
|
|
402
|
+
const [_cmd, themeArg] = _
|
|
403
|
+
const { previewTheme } = require('./preview-theme')
|
|
404
|
+
await previewTheme({
|
|
405
|
+
theme: flags['--theme'],
|
|
406
|
+
themeArg,
|
|
407
|
+
url: flags['--url'],
|
|
408
|
+
print: flags['--print'],
|
|
409
|
+
})
|
|
410
|
+
},
|
|
411
|
+
},
|
|
272
412
|
}
|
|
273
413
|
|
|
274
414
|
type CommandDefinitions = typeof COMMAND_MAP
|
|
@@ -332,8 +472,13 @@ main()
|
|
|
332
472
|
async function main() {
|
|
333
473
|
if (flags['--help']) {
|
|
334
474
|
console.info(`\n$ tamagui ${command}: ${definition.description}\n`)
|
|
475
|
+
if ('usage' in definition && definition.usage) {
|
|
476
|
+
console.info(`Usage:\n${definition.usage}\n`)
|
|
477
|
+
}
|
|
335
478
|
console.info(
|
|
336
|
-
`Flags
|
|
479
|
+
`Flags:\n${Object.entries(definition.flags)
|
|
480
|
+
.map(([k, v]) => ` ${k} (${v.name})`)
|
|
481
|
+
.join('\n')}`
|
|
337
482
|
)
|
|
338
483
|
process.exit(0)
|
|
339
484
|
}
|
|
@@ -354,7 +499,9 @@ async function main() {
|
|
|
354
499
|
await definition.run()
|
|
355
500
|
} catch (err: any) {
|
|
356
501
|
console.error(`Error running command: ${err.message}`)
|
|
502
|
+
process.exit(1) // a thrown command error must be a NON-ZERO exit (safety: --write aborts)
|
|
357
503
|
}
|
|
358
504
|
|
|
359
|
-
|
|
505
|
+
// `check` sets exitCode when it finds problems; a literal 0 would erase it
|
|
506
|
+
process.exit(process.exitCode ?? 0)
|
|
360
507
|
}
|