-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbin.js
174 lines (143 loc) · 4.91 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
import * as p from '@clack/prompts';
import { bold, cyan, grey } from 'kleur/colors';
import { create } from './index.js';
import { dist } from './utils.js';
const { version } = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url), 'utf-8'));
let cwd = process.argv[2] || '.';
console.log(`
${grey(`create-atlas-addon version ${version}`)}
`);
p.intro('Welcome to AtlasFramework!');
if (cwd === '.') {
const dir = await p.text({
message: 'Where should we create your project?',
placeholder: ' (hit Enter to use current directory)'
});
if (p.isCancel(dir)) process.exit(1);
if (dir) {
cwd = /** @type {string} */ (dir);
}
}
if (fs.existsSync(cwd)) {
if (fs.readdirSync(cwd).length > 0) {
const force = await p.confirm({
message: 'Directory not empty. Continue?',
initialValue: false
});
// bail if `force` is `false` or the user cancelled with Ctrl-C
if (force !== true) {
process.exit(1);
}
}
}
const options = await p.group(
{
template: () =>
p.select({
message: 'Which AtlasFramework app template?',
// @ts-expect-error i have no idea what is going on here
options: fs.readdirSync(dist('templates')).map((dir) => {
const meta_file = dist(`templates/${dir}/meta.json`);
const { title, description } = JSON.parse(fs.readFileSync(meta_file, 'utf8'));
return {
label: title,
hint: description,
value: dir
};
})
}),
fancy_name: () =>
p.text({
message: 'What should the "Fancy Name" name be?',
placeholder: ' (e.g Comms Addon)',
validate: (value) => {
if (value == "" ) return "A valid name must be passed, e.g Comms Addon"
}
}),
underscore_name: () =>
p.text({
message: 'What should the file name be?',
placeholder: ' (e.g comms_addon)',
validate: (value) => {
if (value === "") return "A valid name must be passed, e.g comms_addon";
if (!/^[a-z_]+$/.test(value)) return "Name can only contain lowercase letters and underscores, e.g comms_addon"
}
}),
global: () =>
p.text({
message: "What should the global variable be?",
placeholder: " (e.g CommsAddon)",
validate: (value) => {
if (value === "") return "A valid name must be passed, e.g. CommsAddon";
if (!/^[a-zA-Z]+$/.test(value)) return "Name can only contain upper & lowercase letters, e.g. CommsAddon";
},
}),
acronym: () =>
p.text({
message: 'What should the acronym be?',
placeholder: ' (e.g CommsAddon)',
validate: (value) => {
if (value === "") return "A valid acronym must be passed, e.g. CommsAddon";
if (!/^[a-zA-Z]+$/.test(value)) return "Acronym can only contain upper & lowercase letters, e.g. CommsAddon";
},
}),
// features: () =>
// p.multiselect({
// message: 'Select additional options (use arrow keys/space bar)',
// required: false,
// options: [
// {
// value: 'eslint',
// label: 'Add ESLint for code linting'
// },
// {
// value: 'prettier',
// label: 'Add Prettier for code formatting'
// },
// {
// value: 'playwright',
// label: 'Add Playwright for browser testing'
// },
// {
// value: 'vitest',
// label: 'Add Vitest for unit testing'
// }
// ]
// })
},
{ onCancel: () => process.exit(1) }
);
const s = p.spinner();
s.start("Copying over template files...");
await create(cwd, {
name: path.basename(path.resolve(cwd)),
template: /** @type {'skeleton'} */ (options.template),
fancy_name: options.fancy_name,
underscore_name: options.underscore_name,
global: options.global,
acronym: options.acronym
});
s.stop("Copied over template files!")
p.outro(`Your project is ready!`);
console.log(bold('✔ Fancy Name'));
console.log(cyan(` ${options.fancy_name}\n`));
console.log(bold('✔ Underscore Name'));
console.log(cyan(` ${options.underscore_name}\n`));
console.log(bold('✔ Global Variable Name'));
console.log(cyan(` ${options.global}\n`));
console.log(bold('✔ Acronym Name'));
console.log(cyan(` ${options.acronym}\n`));
console.log('\nNext steps:');
let i = 1;
const relative = path.relative(process.cwd(), cwd);
if (relative !== '') {
console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
}
console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional)`);
console.log(` ${i++}: ${bold(cyan('lauxc workspace'))}`);
console.log(` ${i++}: ${bold(cyan('Run your server!'))}`);
console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`);
console.log(`\nStuck? Visit us at ${cyan('https://discord.gg/glua')}`);