create-lve 0.4.0 → 0.4.2
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 +16 -20
- 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
|
@@ -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,29 @@ async function main() {
|
|
|
98
96
|
}
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
s.start('🛠️ 正在按需装配架构')
|
|
102
|
-
|
|
103
99
|
try {
|
|
100
|
+
s.start('Creating project')
|
|
101
|
+
|
|
104
102
|
if (project.shouldOverwrite) await fs.emptyDir(ctx.targetDir)
|
|
105
103
|
await fs.ensureDir(ctx.targetDir)
|
|
106
104
|
await fs.copy(ctx.templateDir, ctx.targetDir)
|
|
107
|
-
|
|
108
105
|
await cleanupTemplate(ctx)
|
|
109
|
-
|
|
110
106
|
await applyProjectTransform(ctx)
|
|
111
107
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
108
|
+
s.start('Installing dependencies')
|
|
109
|
+
await installDependencies(ctx, s)
|
|
110
|
+
|
|
111
|
+
console.log(pc.gray(`◇ Scaffolded ${ctx.name} with Vite application`))
|
|
112
|
+
console.log(
|
|
113
|
+
pc.gray(
|
|
114
|
+
`• Node ${process.version.slice(1)} ${ctx.pkgManager} ${execSync(ctx.pkgManager + ' -V')
|
|
115
|
+
.toString()
|
|
116
|
+
.trim()}`,
|
|
117
|
+
),
|
|
118
|
+
)
|
|
119
|
+
console.log(pc.green(`→ Next: cd ${ctx.name} && ${ctx.devCmd.replace(' ', ' run ')}`))
|
|
124
120
|
} catch (err) {
|
|
125
|
-
s.stop(pc.red('
|
|
121
|
+
s.stop(pc.red('Failed'))
|
|
126
122
|
|
|
127
123
|
if (ctx && ctx.targetDir && fs.existsSync(ctx.targetDir)) {
|
|
128
124
|
p.log.warn(pc.yellow(`正在清理残留文件: ${ctx.targetDir}...`))
|