create-lve 0.3.11 → 0.4.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.
- package/config.js +13 -4
- package/index.js +25 -21
- package/package.json +1 -1
package/config.js
CHANGED
|
@@ -49,6 +49,7 @@ const FRAMEWORK_CONFIG = {
|
|
|
49
49
|
},
|
|
50
50
|
react: {
|
|
51
51
|
deps: (isUno) => ({
|
|
52
|
+
dependencies: isUno ? { '@unocss/reset': 'latest' } : {},
|
|
52
53
|
devDependencies: isUno
|
|
53
54
|
? { unocss: 'latest' }
|
|
54
55
|
: { tailwindcss: 'latest', '@tailwindcss/vite': 'latest' },
|
|
@@ -70,7 +71,7 @@ const CSS_STRATEGIES = {
|
|
|
70
71
|
unocss: {
|
|
71
72
|
pluginImport: "import UnoCSS from 'unocss/vite'\n",
|
|
72
73
|
pluginCode: 'UnoCSS(), ',
|
|
73
|
-
entryImport: "import 'virtual:uno.css'\n",
|
|
74
|
+
entryImport: "import '@unocss/reset/tailwind.css'\nimport 'virtual:uno.css'\n",
|
|
74
75
|
async setup(ctx) {
|
|
75
76
|
const unoConfig = `
|
|
76
77
|
import { defineConfig, presetWind3, transformerCompileClass } from 'unocss'
|
|
@@ -81,7 +82,9 @@ export default defineConfig({
|
|
|
81
82
|
{
|
|
82
83
|
name: 'auto-uno-injector',
|
|
83
84
|
enforce: 'pre',
|
|
84
|
-
idFilter(id) {
|
|
85
|
+
idFilter(id) {
|
|
86
|
+
return /\\.[tj]sx$|\\.vue$/.test(id)
|
|
87
|
+
},
|
|
85
88
|
async transform(code) {
|
|
86
89
|
const classRegex = /(?:class|className)=["']([^"']+)["']/g
|
|
87
90
|
let match
|
|
@@ -94,9 +97,14 @@ export default defineConfig({
|
|
|
94
97
|
}
|
|
95
98
|
},
|
|
96
99
|
},
|
|
97
|
-
transformerCompileClass({
|
|
100
|
+
transformerCompileClass({
|
|
101
|
+
classPrefix: '',
|
|
102
|
+
hashFn: (str) => btoa(str).slice(0, 6),
|
|
103
|
+
keepUnknown: false,
|
|
104
|
+
}),
|
|
98
105
|
],
|
|
99
|
-
})
|
|
106
|
+
})
|
|
107
|
+
`.trim()
|
|
100
108
|
await fs.writeFile(path.join(ctx.targetDir, 'uno.config.ts'), unoConfig + '\n')
|
|
101
109
|
const stylePath = path.join(ctx.targetDir, 'src/style.css')
|
|
102
110
|
if (fs.existsSync(stylePath)) await fs.remove(stylePath)
|
|
@@ -139,6 +147,7 @@ async function applyProjectTransform(ctx) {
|
|
|
139
147
|
const config = FRAMEWORK_CONFIG[framework]
|
|
140
148
|
pkg.name = ctx.name
|
|
141
149
|
const extraConfig = config.deps(isUno)
|
|
150
|
+
pkg.dependencies = { ...pkg.dependencies, ...extraConfig.dependencies }
|
|
142
151
|
pkg.devDependencies = { ...pkg.devDependencies, ...extraConfig.devDependencies }
|
|
143
152
|
if (extraConfig.pnpm) pkg.pnpm = { ...pkg.pnpm, ...extraConfig.pnpm }
|
|
144
153
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 })
|
package/index.js
CHANGED
|
@@ -23,7 +23,7 @@ async function main() {
|
|
|
23
23
|
path: () =>
|
|
24
24
|
p.text({
|
|
25
25
|
message: '项目名称',
|
|
26
|
-
placeholder: '
|
|
26
|
+
placeholder: 'react-app',
|
|
27
27
|
defaultValue: 'react-app',
|
|
28
28
|
validate: (value) => {
|
|
29
29
|
if (!value || value.length === 0) return
|
|
@@ -58,8 +58,6 @@ async function main() {
|
|
|
58
58
|
{ value: 'unocss', label: 'UnoCSS' },
|
|
59
59
|
],
|
|
60
60
|
}),
|
|
61
|
-
|
|
62
|
-
install: () => p.confirm({ message: '是否现在自动安装依赖?', initialValue: true }),
|
|
63
61
|
},
|
|
64
62
|
{
|
|
65
63
|
onCancel: () => {
|
|
@@ -73,7 +71,7 @@ async function main() {
|
|
|
73
71
|
name: project.path,
|
|
74
72
|
framework: project.framework,
|
|
75
73
|
css: project.cssEngine,
|
|
76
|
-
shouldInstall:
|
|
74
|
+
shouldInstall: true,
|
|
77
75
|
targetDir: path.resolve(process.cwd(), project.path),
|
|
78
76
|
templateDir: path.resolve(__dirname, `template-${project.framework}`),
|
|
79
77
|
isNext: project.framework === 'next',
|
|
@@ -98,31 +96,37 @@ async function main() {
|
|
|
98
96
|
}
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
s.start('🛠️ 正在按需装配架构')
|
|
102
|
-
|
|
103
99
|
try {
|
|
100
|
+
s.start('Creating project')
|
|
101
|
+
const startScaffold = Date.now()
|
|
102
|
+
|
|
104
103
|
if (project.shouldOverwrite) await fs.emptyDir(ctx.targetDir)
|
|
105
104
|
await fs.ensureDir(ctx.targetDir)
|
|
106
105
|
await fs.copy(ctx.templateDir, ctx.targetDir)
|
|
107
|
-
|
|
108
106
|
await cleanupTemplate(ctx)
|
|
109
|
-
|
|
110
107
|
await applyProjectTransform(ctx)
|
|
111
108
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
109
|
+
const costScaffold = ((Date.now() - startScaffold) / 1000).toFixed(1)
|
|
110
|
+
s.stop(pc.green(`Creating project in ${costScaffold}s`))
|
|
111
|
+
|
|
112
|
+
s.start('Installing dependencies')
|
|
113
|
+
const startInstall = Date.now()
|
|
114
|
+
await installDependencies(ctx, s)
|
|
115
|
+
|
|
116
|
+
const costInstall = ((Date.now() - startInstall) / 1000).toFixed(1)
|
|
117
|
+
s.stop(pc.green(`Dependencies installed in ${costInstall}s`))
|
|
118
|
+
|
|
119
|
+
console.log(pc.gray(`◇ Scaffolded ${ctx.name} with Vite application`))
|
|
120
|
+
console.log(
|
|
121
|
+
pc.gray(
|
|
122
|
+
`• Node ${process.version.slice(1)} ${ctx.pkgManager} ${execSync(ctx.pkgManager + ' -v')
|
|
123
|
+
.toString()
|
|
124
|
+
.trim()}`,
|
|
125
|
+
),
|
|
126
|
+
)
|
|
127
|
+
console.log(pc.green(`→ Next: cd ${ctx.name} && ${ctx.devCmd.replace(' ', ' run ')}`))
|
|
124
128
|
} catch (err) {
|
|
125
|
-
s.stop(pc.red('
|
|
129
|
+
s.stop(pc.red('Failed'))
|
|
126
130
|
|
|
127
131
|
if (ctx && ctx.targetDir && fs.existsSync(ctx.targetDir)) {
|
|
128
132
|
p.log.warn(pc.yellow(`正在清理残留文件: ${ctx.targetDir}...`))
|