@tamagui/cli 1.100.6 → 1.101.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/dist/add.js +5 -4
- package/dist/add.js.map +2 -2
- package/dist/add.mjs +64 -0
- package/dist/add.native.js +6 -5
- package/dist/add.native.js.map +2 -2
- package/dist/build.js +36 -21
- package/dist/build.js.map +2 -2
- package/dist/build.mjs +37 -0
- package/dist/build.native.js +100 -57
- package/dist/build.native.js.map +2 -2
- package/dist/cli.js +29 -22
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +250 -0
- package/dist/cli.native.js +56 -22
- package/dist/cli.native.js.map +2 -2
- package/dist/generate.mjs +27 -0
- package/dist/index.mjs +2 -0
- package/dist/studio.mjs +108 -0
- package/dist/update-template.mjs +23 -0
- package/dist/update.mjs +2 -0
- package/dist/utils.mjs +72 -0
- package/package.json +9 -7
- package/src/add.ts +3 -1
- package/src/build.ts +78 -32
- package/src/cli.ts +33 -23
- package/types/add.d.ts.map +1 -1
- package/types/build.d.ts +6 -1
- package/types/build.d.ts.map +1 -1
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { loadTamaguiBuildConfigSync, loadTamagui as loadTamaguiStatic } from "@tamagui/static";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import fs, { pathExists, readJSON } from "fs-extra";
|
|
5
|
+
async function getOptions({
|
|
6
|
+
root = process.cwd(),
|
|
7
|
+
tsconfigPath = "tsconfig.json",
|
|
8
|
+
tamaguiOptions,
|
|
9
|
+
host,
|
|
10
|
+
debug,
|
|
11
|
+
loadTamaguiOptions
|
|
12
|
+
} = {}) {
|
|
13
|
+
const tsConfigFilePath = join(root, tsconfigPath);
|
|
14
|
+
ensure(await fs.pathExists(tsConfigFilePath), `No tsconfig found: ${tsConfigFilePath}`);
|
|
15
|
+
const dotDir = join(root, ".tamagui");
|
|
16
|
+
let pkgJson = {},
|
|
17
|
+
config = "";
|
|
18
|
+
try {
|
|
19
|
+
config = await getDefaultTamaguiConfigPath(), pkgJson = await readJSON(join(root, "package.json"));
|
|
20
|
+
} catch {}
|
|
21
|
+
const filledOptions = {
|
|
22
|
+
platform: "native",
|
|
23
|
+
components: ["tamagui"],
|
|
24
|
+
config,
|
|
25
|
+
...tamaguiOptions
|
|
26
|
+
},
|
|
27
|
+
finalOptions = loadTamaguiOptions ? loadTamaguiBuildConfigSync(filledOptions) : filledOptions;
|
|
28
|
+
return {
|
|
29
|
+
mode: process.env.NODE_ENV === "production" ? "production" : "development",
|
|
30
|
+
root,
|
|
31
|
+
host: host || "127.0.0.1",
|
|
32
|
+
pkgJson,
|
|
33
|
+
debug,
|
|
34
|
+
tsconfigPath,
|
|
35
|
+
tamaguiOptions: finalOptions,
|
|
36
|
+
paths: {
|
|
37
|
+
root,
|
|
38
|
+
dotDir,
|
|
39
|
+
conf: join(dotDir, "tamagui.config.json"),
|
|
40
|
+
types: join(dotDir, "types.json")
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function ensure(condition, message) {
|
|
45
|
+
condition || (console.error(chalk.red.bold("Error:"), chalk.yellow(`${message}`)), process.exit(1));
|
|
46
|
+
}
|
|
47
|
+
const defaultPaths = ["tamagui.config.ts", join("src", "tamagui.config.ts")];
|
|
48
|
+
let cachedPath = "";
|
|
49
|
+
async function getDefaultTamaguiConfigPath() {
|
|
50
|
+
if (cachedPath) return cachedPath;
|
|
51
|
+
const existing = (await Promise.all(defaultPaths.map(path => pathExists(path)))).findIndex(x => !!x),
|
|
52
|
+
found = defaultPaths[existing];
|
|
53
|
+
if (!found) throw new Error("No found tamagui.config.ts");
|
|
54
|
+
return cachedPath = found, found;
|
|
55
|
+
}
|
|
56
|
+
let cached = null;
|
|
57
|
+
const loadTamagui = async opts => {
|
|
58
|
+
const loaded = await loadTamaguiStatic({
|
|
59
|
+
config: await getDefaultTamaguiConfigPath(),
|
|
60
|
+
components: ["tamagui"],
|
|
61
|
+
...opts
|
|
62
|
+
});
|
|
63
|
+
return loaded && (cached = loaded), loaded;
|
|
64
|
+
},
|
|
65
|
+
disposers = /* @__PURE__ */new Set();
|
|
66
|
+
function registerDispose(cb) {
|
|
67
|
+
disposers.add(cb);
|
|
68
|
+
}
|
|
69
|
+
function disposeAll() {
|
|
70
|
+
disposers.forEach(cb => cb());
|
|
71
|
+
}
|
|
72
|
+
export { disposeAll, ensure, getOptions, loadTamagui, registerDispose };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.101.0",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"clean:build": "tamagui-build clean:build"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tamagui/create-theme": "1.
|
|
27
|
-
"@tamagui/generate-themes": "1.
|
|
28
|
-
"@tamagui/static": "1.
|
|
29
|
-
"@tamagui/types": "1.
|
|
30
|
-
"@tamagui/vite-plugin": "1.
|
|
26
|
+
"@tamagui/create-theme": "1.101.0",
|
|
27
|
+
"@tamagui/generate-themes": "1.101.0",
|
|
28
|
+
"@tamagui/static": "1.101.0",
|
|
29
|
+
"@tamagui/types": "1.101.0",
|
|
30
|
+
"@tamagui/vite-plugin": "1.101.0",
|
|
31
31
|
"@vitejs/plugin-react-swc": "^3.6.0",
|
|
32
32
|
"arg": "^5.0.2",
|
|
33
33
|
"chalk": "^4.1.2",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"kill-port": "^2.0.1",
|
|
46
46
|
"marked": "^5.1.0",
|
|
47
47
|
"marked-terminal": "^5.2.0",
|
|
48
|
+
"micromatch": "^4.0.7",
|
|
48
49
|
"opener": "^1.5.2",
|
|
49
50
|
"prompts": "2.1.0",
|
|
50
51
|
"ts-morph": "^15.1.0",
|
|
@@ -55,7 +56,8 @@
|
|
|
55
56
|
"vite-tsconfig-paths": "^4.3.2"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
|
-
"@tamagui/build": "1.
|
|
59
|
+
"@tamagui/build": "1.101.0",
|
|
60
|
+
"@types/chokidar": "^2.1.3",
|
|
59
61
|
"@types/marked": "^5.0.0"
|
|
60
62
|
}
|
|
61
63
|
}
|
package/src/add.ts
CHANGED
|
@@ -6,12 +6,14 @@ import path from 'node:path'
|
|
|
6
6
|
|
|
7
7
|
import chalk from 'chalk'
|
|
8
8
|
import { pascalCase } from 'change-case'
|
|
9
|
-
import
|
|
9
|
+
import FSExtra from 'fs-extra'
|
|
10
10
|
import { marked } from 'marked'
|
|
11
11
|
import TerminalRenderer from 'marked-terminal'
|
|
12
12
|
import open from 'opener'
|
|
13
13
|
import prompts from 'prompts'
|
|
14
14
|
|
|
15
|
+
const { copy, ensureDir, readFileSync } = FSExtra
|
|
16
|
+
|
|
15
17
|
marked.setOptions({
|
|
16
18
|
headerIds: false,
|
|
17
19
|
mangle: false,
|
package/src/build.ts
CHANGED
|
@@ -1,51 +1,97 @@
|
|
|
1
|
-
import { dirname, resolve } from 'path'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { dirname, basename, resolve, join, extname } from 'node:path'
|
|
2
|
+
import {
|
|
3
|
+
createExtractor,
|
|
4
|
+
extractToClassNames,
|
|
5
|
+
extractToNative,
|
|
6
|
+
loadTamagui,
|
|
7
|
+
loadTamaguiBuildConfigSync,
|
|
8
|
+
} from '@tamagui/static'
|
|
9
|
+
import type { CLIResolvedOptions, TamaguiOptions } from '@tamagui/types'
|
|
5
10
|
import chokidar from 'chokidar'
|
|
6
|
-
import { readFile } from 'fs-extra'
|
|
7
|
-
|
|
8
|
-
export const build = async (options: CLIResolvedOptions) => {
|
|
9
|
-
// const tamagui = await loadTamagui(options.tamaguiOptions)
|
|
11
|
+
import { readFile, writeFile } from 'fs-extra'
|
|
12
|
+
import MicroMatch from 'micromatch'
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
export const build = async (
|
|
15
|
+
options: CLIResolvedOptions & {
|
|
16
|
+
target?: 'web' | 'native'
|
|
17
|
+
dir?: string
|
|
18
|
+
include?: string
|
|
19
|
+
exclude?: string
|
|
14
20
|
}
|
|
15
|
-
|
|
21
|
+
) => {
|
|
22
|
+
const sourceDir = options.dir ?? '.'
|
|
16
23
|
const promises: Promise<void>[] = []
|
|
17
|
-
|
|
24
|
+
|
|
25
|
+
const buildOptions = loadTamaguiBuildConfigSync(options.tamaguiOptions)
|
|
26
|
+
const platform = options.target ?? 'web'
|
|
27
|
+
process.env.TAMAGUI_TARGET = platform
|
|
28
|
+
|
|
29
|
+
const tamaguiOptions = {
|
|
30
|
+
...buildOptions,
|
|
31
|
+
platform,
|
|
32
|
+
} satisfies TamaguiOptions
|
|
33
|
+
|
|
34
|
+
// load once first
|
|
35
|
+
await loadTamagui(tamaguiOptions)
|
|
18
36
|
|
|
19
37
|
await new Promise<void>((res) => {
|
|
20
38
|
chokidar
|
|
21
39
|
// prevent infinite loop but cause race condition if you just build directly
|
|
22
|
-
.watch(sourceDir
|
|
40
|
+
.watch(`${sourceDir}/**/*.tsx`, {
|
|
23
41
|
// persistent: true,
|
|
24
42
|
})
|
|
25
43
|
.on('add', (relativePath) => {
|
|
44
|
+
if (options.exclude) {
|
|
45
|
+
if (MicroMatch.contains(relativePath, options.exclude)) {
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (options.include) {
|
|
50
|
+
if (!MicroMatch.contains(relativePath, options.include)) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
26
55
|
const sourcePath = resolve(process.cwd(), relativePath)
|
|
56
|
+
console.info(` [tamagui] optimizing ${sourcePath}`)
|
|
27
57
|
|
|
28
58
|
promises.push(
|
|
29
59
|
(async () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const out = await extractToClassNames({
|
|
39
|
-
extractor,
|
|
40
|
-
source,
|
|
41
|
-
sourcePath,
|
|
42
|
-
options: options.tamaguiOptions,
|
|
43
|
-
shouldPrintDebug: options.debug || false,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
// await writeFile()
|
|
60
|
+
if (options.debug) {
|
|
61
|
+
process.env.NODE_ENV ||= 'development'
|
|
62
|
+
}
|
|
63
|
+
const source = await readFile(sourcePath, 'utf-8')
|
|
64
|
+
|
|
65
|
+
if (platform === 'web') {
|
|
66
|
+
const extractor = createExtractor({
|
|
67
|
+
platform,
|
|
47
68
|
})
|
|
48
|
-
|
|
69
|
+
|
|
70
|
+
const out = await extractToClassNames({
|
|
71
|
+
extractor,
|
|
72
|
+
source,
|
|
73
|
+
sourcePath,
|
|
74
|
+
options: buildOptions,
|
|
75
|
+
shouldPrintDebug: options.debug || false,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
if (!out) {
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const cssName = '_' + basename(sourcePath, extname(sourcePath))
|
|
83
|
+
const stylePath = join(dirname(sourcePath), cssName + '.css')
|
|
84
|
+
const code = `import "./${cssName}.css"\n${out.js}`
|
|
85
|
+
|
|
86
|
+
await Promise.all([
|
|
87
|
+
writeFile(sourcePath, code, 'utf-8'),
|
|
88
|
+
writeFile(stylePath, out.styles, 'utf-8'),
|
|
89
|
+
])
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// native
|
|
93
|
+
const out = extractToNative(sourcePath, source, tamaguiOptions)
|
|
94
|
+
await writeFile(sourcePath, out.code, 'utf-8')
|
|
49
95
|
})()
|
|
50
96
|
)
|
|
51
97
|
})
|
package/src/cli.ts
CHANGED
|
@@ -137,23 +137,33 @@ const COMMAND_MAP = {
|
|
|
137
137
|
},
|
|
138
138
|
},
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
140
|
+
build: {
|
|
141
|
+
shorthands: ['b'],
|
|
142
|
+
description: `Use to pre-build a Tamagui component directory`,
|
|
143
|
+
flags: {
|
|
144
|
+
'--help': Boolean,
|
|
145
|
+
'--debug': Boolean,
|
|
146
|
+
'--verbose': Boolean,
|
|
147
|
+
'--target': String,
|
|
148
|
+
'--include': String,
|
|
149
|
+
'--exclude': String,
|
|
150
|
+
},
|
|
151
|
+
async run() {
|
|
152
|
+
const { _, ...flags } = arg(this.flags)
|
|
153
|
+
const [_command, dir] = _
|
|
154
|
+
const imported = await import('./build.js')
|
|
155
|
+
const options = await getOptions({
|
|
156
|
+
debug: flags['--debug'] ? (flags['--verbose'] ? 'verbose' : true) : false,
|
|
157
|
+
})
|
|
158
|
+
await imported['default'].build({
|
|
159
|
+
...options,
|
|
160
|
+
dir,
|
|
161
|
+
include: flags['--include'],
|
|
162
|
+
target: flags['--target'] || 'web',
|
|
163
|
+
exclude: flags['--exclude'],
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
},
|
|
157
167
|
|
|
158
168
|
// update: {
|
|
159
169
|
// shorthands: [],
|
|
@@ -238,12 +248,12 @@ const {
|
|
|
238
248
|
)
|
|
239
249
|
|
|
240
250
|
if (flags['--version']) {
|
|
241
|
-
console.
|
|
251
|
+
console.info(require('../package.json').version)
|
|
242
252
|
process.exit(0)
|
|
243
253
|
}
|
|
244
254
|
|
|
245
255
|
if (!command && flags['--help']) {
|
|
246
|
-
console.
|
|
256
|
+
console.info(`$ tamagui
|
|
247
257
|
|
|
248
258
|
commands:
|
|
249
259
|
|
|
@@ -267,8 +277,8 @@ main()
|
|
|
267
277
|
|
|
268
278
|
async function main() {
|
|
269
279
|
if (flags['--help']) {
|
|
270
|
-
console.
|
|
271
|
-
console.
|
|
280
|
+
console.info(`\n$ tamagui ${command}: ${definition.description}\n`)
|
|
281
|
+
console.info(
|
|
272
282
|
`Flags: ${Object.entries(definition.flags).map(([k, v]) => `${k} (${v.name})`)}`
|
|
273
283
|
)
|
|
274
284
|
process.exit(0)
|
|
@@ -278,7 +288,7 @@ async function main() {
|
|
|
278
288
|
|
|
279
289
|
// help for any command
|
|
280
290
|
if (cmdFlags['--help']) {
|
|
281
|
-
console.
|
|
291
|
+
console.info(`$ tamagui ${_}
|
|
282
292
|
|
|
283
293
|
Flags: ${JSON.stringify(cmdFlags, null, 2)}
|
|
284
294
|
|
|
@@ -297,7 +307,7 @@ async function main() {
|
|
|
297
307
|
|
|
298
308
|
function showHelp(definition: CommandDefinition, flags: { '--help'?: boolean }) {
|
|
299
309
|
if (flags['--help']) {
|
|
300
|
-
console.
|
|
310
|
+
console.info(`$ ${definition}`)
|
|
301
311
|
}
|
|
302
312
|
}
|
|
303
313
|
|
package/types/add.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../src/add.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../src/add.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,qBAAqB,2BAA4B,CAAA;AAC9D,eAAO,MAAM,uBAAuB,SAAgB,MAAM,iBAAiB,MAAM,kBAqGhF,CAAA"}
|
package/types/build.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { CLIResolvedOptions } from '@tamagui/types';
|
|
2
|
-
export declare const build: (options: CLIResolvedOptions
|
|
2
|
+
export declare const build: (options: CLIResolvedOptions & {
|
|
3
|
+
target?: 'web' | 'native';
|
|
4
|
+
dir?: string;
|
|
5
|
+
include?: string;
|
|
6
|
+
exclude?: string;
|
|
7
|
+
}) => Promise<void>;
|
|
3
8
|
//# sourceMappingURL=build.d.ts.map
|
package/types/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,gBAAgB,CAAA;AAKxE,eAAO,MAAM,KAAK,YACP,kBAAkB,GAAG;IAC5B,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAA;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,kBAoFF,CAAA"}
|