create-asterui 0.1.1 → 0.1.3
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/README.md +19 -9
- package/dist/index.js +129 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,25 @@ pnpm create asterui
|
|
|
12
12
|
yarn create asterui
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
### With arguments
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm create asterui my-app
|
|
19
|
+
npm create asterui my-app --js
|
|
20
|
+
npm create asterui my-app --themes business
|
|
21
|
+
npm create asterui my-app --js --themes all --pm pnpm
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Options
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
--js Use JavaScript instead of TypeScript
|
|
28
|
+
--ts Use TypeScript (default)
|
|
29
|
+
--themes <preset> Theme preset: light-dark, business, all
|
|
30
|
+
--pm <manager> Package manager: npm, pnpm, yarn
|
|
31
|
+
-h, --help Show help message
|
|
32
|
+
```
|
|
33
|
+
|
|
15
34
|
## What it does
|
|
16
35
|
|
|
17
36
|
- Creates a new Vite + React project
|
|
@@ -20,15 +39,6 @@ yarn create asterui
|
|
|
20
39
|
- Sets up theme configuration (light/dark, business/corporate, or custom)
|
|
21
40
|
- Supports TypeScript or JavaScript
|
|
22
41
|
|
|
23
|
-
## Options
|
|
24
|
-
|
|
25
|
-
The CLI will prompt you for:
|
|
26
|
-
|
|
27
|
-
- **Project name** - Directory name for your project
|
|
28
|
-
- **Language** - TypeScript (recommended) or JavaScript
|
|
29
|
-
- **Themes** - Light/Dark, Business/Corporate, All themes, or custom selection
|
|
30
|
-
- **Package manager** - npm, pnpm, or yarn (auto-detected)
|
|
31
|
-
|
|
32
42
|
## After scaffolding
|
|
33
43
|
|
|
34
44
|
```bash
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,58 @@ const DAISYUI_THEMES = [
|
|
|
13
13
|
'luxury', 'dracula', 'cmyk', 'autumn', 'business', 'acid', 'lemonade',
|
|
14
14
|
'night', 'coffee', 'winter', 'dim', 'nord', 'sunset'
|
|
15
15
|
];
|
|
16
|
+
const THEME_PRESETS = ['light-dark', 'business', 'all'];
|
|
17
|
+
function parseArgs() {
|
|
18
|
+
const args = process.argv.slice(2);
|
|
19
|
+
const result = {};
|
|
20
|
+
for (let i = 0; i < args.length; i++) {
|
|
21
|
+
const arg = args[i];
|
|
22
|
+
if (arg === '--help' || arg === '-h') {
|
|
23
|
+
result.help = true;
|
|
24
|
+
}
|
|
25
|
+
else if (arg === '--js') {
|
|
26
|
+
result.language = 'js';
|
|
27
|
+
}
|
|
28
|
+
else if (arg === '--ts') {
|
|
29
|
+
result.language = 'ts';
|
|
30
|
+
}
|
|
31
|
+
else if (arg === '--themes' && args[i + 1]) {
|
|
32
|
+
result.themes = args[++i];
|
|
33
|
+
}
|
|
34
|
+
else if (arg === '--pm' && args[i + 1]) {
|
|
35
|
+
const pm = args[++i];
|
|
36
|
+
if (pm === 'npm' || pm === 'pnpm' || pm === 'yarn') {
|
|
37
|
+
result.pm = pm;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (!arg.startsWith('-') && !result.projectName) {
|
|
41
|
+
result.projectName = arg;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
function showHelp() {
|
|
47
|
+
console.log(`
|
|
48
|
+
${pc.bold('create-asterui')} - Scaffold a new AsterUI project
|
|
49
|
+
|
|
50
|
+
${pc.bold('Usage:')}
|
|
51
|
+
npm create asterui [project-name] [options]
|
|
52
|
+
|
|
53
|
+
${pc.bold('Options:')}
|
|
54
|
+
--js Use JavaScript instead of TypeScript
|
|
55
|
+
--ts Use TypeScript (default)
|
|
56
|
+
--themes <preset> Theme preset: light-dark, business, all
|
|
57
|
+
--pm <manager> Package manager: npm, pnpm, yarn
|
|
58
|
+
-h, --help Show this help message
|
|
59
|
+
|
|
60
|
+
${pc.bold('Examples:')}
|
|
61
|
+
npm create asterui
|
|
62
|
+
npm create asterui my-app
|
|
63
|
+
npm create asterui my-app --js
|
|
64
|
+
npm create asterui my-app --themes business
|
|
65
|
+
npm create asterui my-app --js --themes all --pm pnpm
|
|
66
|
+
`);
|
|
67
|
+
}
|
|
16
68
|
function detectPackageManager() {
|
|
17
69
|
const userAgent = process.env.npm_config_user_agent || '';
|
|
18
70
|
if (userAgent.includes('pnpm'))
|
|
@@ -21,46 +73,54 @@ function detectPackageManager() {
|
|
|
21
73
|
return 'yarn';
|
|
22
74
|
return 'npm';
|
|
23
75
|
}
|
|
24
|
-
function getInstallCommand(pm) {
|
|
25
|
-
return pm === 'yarn' ? 'yarn' : `${pm} install`;
|
|
26
|
-
}
|
|
27
76
|
function getRunCommand(pm) {
|
|
28
77
|
return pm === 'npm' ? 'npm run' : pm;
|
|
29
78
|
}
|
|
30
79
|
async function main() {
|
|
80
|
+
const cliArgs = parseArgs();
|
|
81
|
+
if (cliArgs.help) {
|
|
82
|
+
showHelp();
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
31
85
|
console.log();
|
|
32
86
|
p.intro(pc.bgCyan(pc.black(' create-asterui ')));
|
|
33
87
|
const detectedPm = detectPackageManager();
|
|
34
88
|
const options = await p.group({
|
|
35
|
-
projectName: () =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
89
|
+
projectName: () => cliArgs.projectName
|
|
90
|
+
? Promise.resolve(cliArgs.projectName)
|
|
91
|
+
: p.text({
|
|
92
|
+
message: 'Project name',
|
|
93
|
+
placeholder: 'my-asterui-app',
|
|
94
|
+
defaultValue: 'my-asterui-app',
|
|
95
|
+
validate: (value) => {
|
|
96
|
+
if (!value)
|
|
97
|
+
return 'Project name is required';
|
|
98
|
+
if (!/^[a-z0-9-]+$/.test(value))
|
|
99
|
+
return 'Project name must be lowercase with hyphens only';
|
|
100
|
+
if (fs.existsSync(value))
|
|
101
|
+
return `Directory "${value}" already exists`;
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
language: () => cliArgs.language
|
|
105
|
+
? Promise.resolve(cliArgs.language)
|
|
106
|
+
: p.select({
|
|
107
|
+
message: 'Language',
|
|
108
|
+
options: [
|
|
109
|
+
{ value: 'ts', label: 'TypeScript', hint: 'recommended' },
|
|
110
|
+
{ value: 'js', label: 'JavaScript' },
|
|
111
|
+
],
|
|
112
|
+
}),
|
|
113
|
+
themePreset: () => cliArgs.themes && THEME_PRESETS.includes(cliArgs.themes)
|
|
114
|
+
? Promise.resolve(cliArgs.themes)
|
|
115
|
+
: p.select({
|
|
116
|
+
message: 'Themes',
|
|
117
|
+
options: [
|
|
118
|
+
{ value: 'light-dark', label: 'Light/Dark', hint: 'recommended' },
|
|
119
|
+
{ value: 'business', label: 'Business/Corporate' },
|
|
120
|
+
{ value: 'all', label: 'All themes' },
|
|
121
|
+
{ value: 'custom', label: 'Choose specific...' },
|
|
122
|
+
],
|
|
123
|
+
}),
|
|
64
124
|
customThemes: ({ results }) => results.themePreset === 'custom'
|
|
65
125
|
? p.multiselect({
|
|
66
126
|
message: 'Select themes',
|
|
@@ -69,14 +129,25 @@ async function main() {
|
|
|
69
129
|
required: true,
|
|
70
130
|
})
|
|
71
131
|
: Promise.resolve([]),
|
|
72
|
-
packageManager: () =>
|
|
73
|
-
|
|
132
|
+
packageManager: () => cliArgs.pm
|
|
133
|
+
? Promise.resolve(cliArgs.pm)
|
|
134
|
+
: p.select({
|
|
135
|
+
message: 'Package manager',
|
|
136
|
+
options: [
|
|
137
|
+
{ value: detectedPm, label: detectedPm, hint: 'detected' },
|
|
138
|
+
...['npm', 'pnpm', 'yarn']
|
|
139
|
+
.filter((pm) => pm !== detectedPm)
|
|
140
|
+
.map((pm) => ({ value: pm, label: pm })),
|
|
141
|
+
],
|
|
142
|
+
}),
|
|
143
|
+
optionalDeps: () => p.multiselect({
|
|
144
|
+
message: 'Optional components (require extra dependencies)',
|
|
74
145
|
options: [
|
|
75
|
-
{ value:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
.map((pm) => ({ value: pm, label: pm })),
|
|
146
|
+
{ value: 'chart', label: 'Chart', hint: 'apexcharts' },
|
|
147
|
+
{ value: 'qrcode', label: 'QRCode', hint: 'qrcode' },
|
|
148
|
+
{ value: 'virtuallist', label: 'VirtualList', hint: '@tanstack/react-virtual' },
|
|
79
149
|
],
|
|
150
|
+
required: false,
|
|
80
151
|
}),
|
|
81
152
|
}, {
|
|
82
153
|
onCancel: () => {
|
|
@@ -94,7 +165,7 @@ async function main() {
|
|
|
94
165
|
// Copy template files
|
|
95
166
|
copyDir(templateDir, projectDir);
|
|
96
167
|
// Generate package.json
|
|
97
|
-
const packageJson = generatePackageJson(options.projectName, options.language);
|
|
168
|
+
const packageJson = generatePackageJson(options.projectName, options.language, options.optionalDeps);
|
|
98
169
|
fs.writeFileSync(path.join(projectDir, 'package.json'), JSON.stringify(packageJson, null, 2));
|
|
99
170
|
// Generate index.css with theme config
|
|
100
171
|
const themes = getThemes(options.themePreset, options.customThemes);
|
|
@@ -137,7 +208,7 @@ function copyDir(src, dest) {
|
|
|
137
208
|
}
|
|
138
209
|
}
|
|
139
210
|
}
|
|
140
|
-
function generatePackageJson(name, language) {
|
|
211
|
+
function generatePackageJson(name, language, optionalDeps = []) {
|
|
141
212
|
const isTs = language === 'ts';
|
|
142
213
|
const pkg = {
|
|
143
214
|
name,
|
|
@@ -163,10 +234,25 @@ function generatePackageJson(name, language) {
|
|
|
163
234
|
vite: '^7.0.0',
|
|
164
235
|
},
|
|
165
236
|
};
|
|
237
|
+
// Add optional dependencies
|
|
238
|
+
const deps = pkg.dependencies;
|
|
239
|
+
if (optionalDeps.includes('chart')) {
|
|
240
|
+
deps['apexcharts'] = '^5.0.0';
|
|
241
|
+
}
|
|
242
|
+
if (optionalDeps.includes('qrcode')) {
|
|
243
|
+
deps['qrcode'] = '^1.5.0';
|
|
244
|
+
}
|
|
245
|
+
if (optionalDeps.includes('virtuallist')) {
|
|
246
|
+
deps['@tanstack/react-virtual'] = '^3.0.0';
|
|
247
|
+
}
|
|
166
248
|
if (isTs) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
249
|
+
const devDeps = pkg.devDependencies;
|
|
250
|
+
devDeps['typescript'] = '^5.6.0';
|
|
251
|
+
devDeps['@types/react'] = '^19.0.0';
|
|
252
|
+
devDeps['@types/react-dom'] = '^19.0.0';
|
|
253
|
+
if (optionalDeps.includes('qrcode')) {
|
|
254
|
+
devDeps['@types/qrcode'] = '^1.5.0';
|
|
255
|
+
}
|
|
170
256
|
}
|
|
171
257
|
return pkg;
|
|
172
258
|
}
|