@tamagui/cli 2.7.7 → 3.0.0-beta.1097.1

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.
Files changed (46) hide show
  1. package/dist/add.cjs +76 -87
  2. package/dist/build.cjs +425 -278
  3. package/dist/cli.cjs +361 -340
  4. package/dist/generate-prompt.cjs +484 -362
  5. package/dist/generate.cjs +45 -54
  6. package/dist/index.cjs +1 -1
  7. package/dist/migrate.cjs +437 -0
  8. package/dist/setup-prompt.cjs +216 -0
  9. package/dist/to-tailwind-default-config.cjs +789 -0
  10. package/dist/to-tailwind.cjs +213 -0
  11. package/dist/update-template.cjs +43 -52
  12. package/dist/update.cjs +14 -18
  13. package/dist/upgrade.cjs +417 -401
  14. package/dist/utils.cjs +84 -101
  15. package/metro.cjs +1 -0
  16. package/metro.d.ts +1 -0
  17. package/metro.mjs +1 -0
  18. package/package.json +43 -13
  19. package/src/build.ts +594 -362
  20. package/src/cli.ts +113 -12
  21. package/src/generate-prompt.ts +428 -329
  22. package/src/migrate.ts +422 -0
  23. package/src/setup-prompt.ts +192 -0
  24. package/src/to-tailwind-default-config.ts +767 -0
  25. package/src/to-tailwind.ts +313 -0
  26. package/src/upgrade.ts +30 -33
  27. package/src/utils.ts +11 -9
  28. package/types/add.d.ts +1 -1
  29. package/types/add.d.ts.map +1 -1
  30. package/types/build.d.ts +2 -1
  31. package/types/build.d.ts.map +1 -1
  32. package/types/generate-prompt.d.ts +6 -2
  33. package/types/generate-prompt.d.ts.map +1 -1
  34. package/types/migrate.d.ts +7 -0
  35. package/types/migrate.d.ts.map +1 -0
  36. package/types/setup-prompt.d.ts +5 -0
  37. package/types/setup-prompt.d.ts.map +1 -0
  38. package/types/to-tailwind-default-config.d.ts +53 -0
  39. package/types/to-tailwind-default-config.d.ts.map +1 -0
  40. package/types/to-tailwind.d.ts +16 -0
  41. package/types/to-tailwind.d.ts.map +1 -0
  42. package/types/upgrade.d.ts.map +1 -1
  43. package/types/utils.d.ts.map +1 -1
  44. package/vite.cjs +1 -0
  45. package/vite.d.ts +1 -0
  46. 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
- // exit handlers
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 for inconsistent versions, duplicate installs, lockfile issues, and missing config.`,
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
- const { checkDeps } = require('@tamagui/static/checkDeps')
29
- await checkDeps(options.paths.root)
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 typeof import('@tamagui/language-service/check')
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) {
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
 
@@ -227,6 +259,68 @@ const COMMAND_MAP = {
227
259
  },
228
260
  },
229
261
 
262
+ setup: {
263
+ shorthands: [],
264
+ description: `Print an AI-agent prompt for adding Tamagui to a project for the first time`,
265
+ usage: `$ tamagui setup`,
266
+ flags: {
267
+ '--help': Boolean,
268
+ },
269
+ async run() {
270
+ const { printSetupPrompt } = require('./setup-prompt')
271
+ printSetupPrompt()
272
+ },
273
+ },
274
+
275
+ migrate: {
276
+ shorthands: [],
277
+ description: `Print an AI-agent prompt for migrating a Tamagui app to v3`,
278
+ usage: `$ tamagui migrate --from v2
279
+ $ tamagui migrate --from v1`,
280
+ flags: {
281
+ '--help': Boolean,
282
+ '--from': String,
283
+ },
284
+ async run() {
285
+ const { _, ...flags } = arg(this.flags)
286
+ const [_cmd, fromArg] = _
287
+ const { printMigrationPrompt } = require('./migrate')
288
+
289
+ printMigrationPrompt({
290
+ from: flags['--from'] || fromArg,
291
+ })
292
+ },
293
+ },
294
+
295
+ 'to-tailwind': {
296
+ shorthands: [],
297
+ description: `Convert Tamagui JSX props in files or globs to Tailwind className syntax`,
298
+ flags: {
299
+ '--help': Boolean,
300
+ '--write': Boolean,
301
+ // path to the app's tamagui config so token/media/shorthand resolution uses the app's
302
+ // ACTUAL scales, not the bundled default fallback.
303
+ '--config': String,
304
+ // acknowledge use of the bundled default scales (required for --write without --config).
305
+ '--use-default-config': Boolean,
306
+ // opt in to DOM renaming (View→div). default: preserve Tamagui components (RN-safe).
307
+ '--rename-dom': Boolean,
308
+ },
309
+ async run() {
310
+ const { _, ...flags } = arg(this.flags)
311
+ const { toTailwind } = require('./to-tailwind')
312
+ const [_cmd, ...patterns] = _
313
+
314
+ await toTailwind({
315
+ patterns,
316
+ write: flags['--write'],
317
+ configPath: flags['--config'],
318
+ useDefaultConfig: flags['--use-default-config'],
319
+ renameDom: flags['--rename-dom'],
320
+ })
321
+ },
322
+ },
323
+
230
324
  'update-template': {
231
325
  shorthands: ['ut'],
232
326
  description: `Used to update your git repo with the source template. (e.g. Takeout)`,
@@ -332,8 +426,13 @@ main()
332
426
  async function main() {
333
427
  if (flags['--help']) {
334
428
  console.info(`\n$ tamagui ${command}: ${definition.description}\n`)
429
+ if ('usage' in definition && definition.usage) {
430
+ console.info(`Usage:\n${definition.usage}\n`)
431
+ }
335
432
  console.info(
336
- `Flags: ${Object.entries(definition.flags).map(([k, v]) => `${k} (${v.name})`)}`
433
+ `Flags:\n${Object.entries(definition.flags)
434
+ .map(([k, v]) => ` ${k} (${v.name})`)
435
+ .join('\n')}`
337
436
  )
338
437
  process.exit(0)
339
438
  }
@@ -354,7 +453,9 @@ async function main() {
354
453
  await definition.run()
355
454
  } catch (err: any) {
356
455
  console.error(`Error running command: ${err.message}`)
456
+ process.exit(1) // a thrown command error must be a NON-ZERO exit (safety: --write aborts)
357
457
  }
358
458
 
359
- process.exit(0)
459
+ // `check` sets exitCode when it finds problems; a literal 0 would erase it
460
+ process.exit(process.exitCode ?? 0)
360
461
  }