@citruslime/create-boilerplate 0.1.2 → 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 +13 -18
- package/hooks/common.sh +7 -0
- package/hooks/post-checkout +11 -0
- package/hooks/post-merge +11 -0
- package/hooks/pre-commit +11 -0
- package/main.mjs +395 -0
- package/package.json +12 -13
- package/{boilerplate-app → template}/.vscode/extensions.json +3 -4
- package/{boilerplate-app → template}/.vscode/settings.json +9 -13
- package/{boilerplate-app/.vscode/boilerplate-app.code-workspace → template/.vscode/template.code-workspace} +13 -18
- package/template/README.md +11 -0
- package/{boilerplate-app → template}/_editorconfig +0 -0
- package/{boilerplate-app → template}/_eslintignore +0 -0
- package/template/_eslintrc.js +3 -0
- package/{boilerplate-app → template}/_gitignore +1 -0
- package/{boilerplate-app → template}/_lintstagedrc.json +1 -1
- package/{boilerplate-app → template}/_stylelintignore +0 -0
- package/template/_stylelintrc.js +3 -0
- package/{boilerplate-app → template}/index.html +1 -1
- package/template/package.json +13 -0
- package/template/postcss.config.js +6 -0
- package/{boilerplate-app → template}/public/favicon.ico +0 -0
- package/template/src/app.vue +31 -0
- package/template/src/env.d.ts +9 -0
- package/template/src/main.ts +17 -0
- package/{boilerplate-app → template}/src/router/index.ts +2 -1
- package/template/src/state/authentication/index.ts +9 -0
- package/template/src/state/index.ts +1 -0
- package/template/src/views/dasboard/index.vue +28 -0
- package/template/tailwind.config.js +7 -0
- package/{boilerplate-app → template}/tsconfig.json +10 -10
- package/template/vite.config.ts +71 -0
- package/boilerplate-app/_eslintrc.js +0 -4
- package/boilerplate-app/_stylelintrc.js +0 -3
- package/boilerplate-app/package.json +0 -55
- package/boilerplate-app/postcss.config.js +0 -8
- package/boilerplate-app/public/site.webmanifest +0 -8
- package/boilerplate-app/public/web.config +0 -7
- package/boilerplate-app/src/app.css +0 -9
- package/boilerplate-app/src/app.ts +0 -5
- package/boilerplate-app/src/app.vue +0 -7
- package/boilerplate-app/src/main.ts +0 -23
- package/boilerplate-app/src/shims-vue.d.ts +0 -7
- package/boilerplate-app/src/state/index.ts +0 -1
- package/boilerplate-app/src/state/utils/index.ts +0 -1
- package/boilerplate-app/src/views/dashboard/index.ts +0 -5
- package/boilerplate-app/src/views/dashboard/index.vue +0 -11
- package/boilerplate-app/src/vite-env.d.ts +0 -2
- package/boilerplate-app/tailwind.config.js +0 -16
- package/boilerplate-app/vite.config.ts +0 -50
- package/index.js +0 -250
package/index.js
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/* eslint-disable indent, array-bracket-newline, array-bracket-spacing, space-before-function-paren, brace-style, eol-last, jsdoc/require-jsdoc */
|
|
4
|
-
require('core-js/features/string/replace-all');
|
|
5
|
-
|
|
6
|
-
const { execSync } = require('child_process');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
green,
|
|
12
|
-
bold,
|
|
13
|
-
lightCyan,
|
|
14
|
-
red
|
|
15
|
-
} = require('kolorist');
|
|
16
|
-
const argv = require('minimist')(process.argv.slice(2));
|
|
17
|
-
|
|
18
|
-
const cwd = process.cwd();
|
|
19
|
-
|
|
20
|
-
const renameFiles = {
|
|
21
|
-
_gitignore: '.gitignore', // eslint-disable-line @typescript-eslint/naming-convention
|
|
22
|
-
_editorconfig: '.editorconfig', // eslint-disable-line @typescript-eslint/naming-convention
|
|
23
|
-
_eslintignore: '.eslintignore', // eslint-disable-line @typescript-eslint/naming-convention
|
|
24
|
-
'_eslintrc.js': '.eslintrc.js', // eslint-disable-line @typescript-eslint/naming-convention
|
|
25
|
-
'_lintstagedrc.json': '.lintstagedrc.json', // eslint-disable-line @typescript-eslint/naming-convention
|
|
26
|
-
_stylelintignore: '.stylelintignore', // eslint-disable-line @typescript-eslint/naming-convention
|
|
27
|
-
'_stylelintrc.js': '.stylelintrc.js', // eslint-disable-line @typescript-eslint/naming-convention
|
|
28
|
-
'boilerplate-app.code-workspace': '' // eslint-disable-line @typescript-eslint/naming-convention,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const boilerplateAppText = 'boilerplate-app';
|
|
32
|
-
|
|
33
|
-
const fsOptions = {
|
|
34
|
-
encoding: 'utf-8'
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
let root;
|
|
38
|
-
let targetDir;
|
|
39
|
-
let packageName;
|
|
40
|
-
let portFrontend;
|
|
41
|
-
let portBackend;
|
|
42
|
-
let autoRun;
|
|
43
|
-
|
|
44
|
-
async function init() {
|
|
45
|
-
targetDir = argv._[0];
|
|
46
|
-
packageName = argv._[1];
|
|
47
|
-
portFrontend = argv._[2];
|
|
48
|
-
portBackend = argv._[3];
|
|
49
|
-
autoRun = argv._[4];
|
|
50
|
-
|
|
51
|
-
const pkgManager = /yarn/.test(process.env.npm_execpath) ? 'yarn' : 'error';
|
|
52
|
-
|
|
53
|
-
testScriptParams(targetDir, packageName, pkgManager, portFrontend, portBackend, autoRun);
|
|
54
|
-
|
|
55
|
-
const packageNameStylised = packageName.split('-')
|
|
56
|
-
.map(e => e.charAt(0).toUpperCase() + e.toLowerCase().slice(1))
|
|
57
|
-
.join(' ');
|
|
58
|
-
|
|
59
|
-
root = path.join(cwd, targetDir);
|
|
60
|
-
|
|
61
|
-
if (!fs.existsSync(root)) {
|
|
62
|
-
fs.mkdirSync(root);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
emptyDir(root);
|
|
66
|
-
|
|
67
|
-
console.log(`\n\n${lightCyan('Scaffolding project in ' + root + ' ...')}`);
|
|
68
|
-
|
|
69
|
-
const templateDir = path.join(__dirname, boilerplateAppText);
|
|
70
|
-
|
|
71
|
-
renameFiles['boilerplate-app.code-workspace'] = 'boilerplate-app.code-workspace';
|
|
72
|
-
|
|
73
|
-
copyFilesToTarget(templateDir, packageNameStylised);
|
|
74
|
-
ensureFilesDoNotContainBoilerplateData(templateDir);
|
|
75
|
-
runShelledScripts();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function runShelledScripts() {
|
|
79
|
-
const execCmd = `echo "\n\n${bold(green('Finishing installing project ...'))}"
|
|
80
|
-
cd ${targetDir}
|
|
81
|
-
echo "${lightCyan('Running yarn ...')}"
|
|
82
|
-
yarn install
|
|
83
|
-
echo "${lightCyan('Preparing project ...')}"
|
|
84
|
-
yarn prepare
|
|
85
|
-
${autoRun === 'true' ? `echo "${lightCyan('Running project in development environment ...')}"` : ''}
|
|
86
|
-
${autoRun === 'true' ? 'yarn dev' : ''}
|
|
87
|
-
`;
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
execSync(execCmd, { shell: 'powershell.exe', stdio: 'inherit' });
|
|
91
|
-
console.log(`\n\n${bold(green('Task Complete.'))}`);
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
console.log(`\n\n${bold(red('Task Failed.'))}`);
|
|
95
|
-
|
|
96
|
-
console.log(`\n\nStatus Code: ${err.status} with '${err.message}'`);
|
|
97
|
-
|
|
98
|
-
console.log(`\nerror : ${err}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function copyFilesToTarget(templateDir, packageNameStylised) {
|
|
103
|
-
const files = fs.readdirSync(templateDir);
|
|
104
|
-
for (const file of files) {
|
|
105
|
-
if (file === 'index.html') {
|
|
106
|
-
writeIndexHtml(templateDir, root, file, packageNameStylised);
|
|
107
|
-
} else if (file === 'vite.config.ts') {
|
|
108
|
-
writeViteConfig(templateDir, root, file, portFrontend, portBackend);
|
|
109
|
-
} else {
|
|
110
|
-
write(templateDir, root, file, null);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function writeIndexHtml(templateDir, root, file, packageNameStylised) {
|
|
116
|
-
let fileContent = fs.readFileSync(path.join(templateDir, file), fsOptions);
|
|
117
|
-
|
|
118
|
-
fileContent = fileContent.replace(boilerplateAppText, packageNameStylised);
|
|
119
|
-
|
|
120
|
-
write(templateDir, root, file, fileContent);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function writeViteConfig(templateDir, root, file, portFrontend, portBackend) {
|
|
124
|
-
let fileContent = fs.readFileSync(path.join(templateDir, file), fsOptions);
|
|
125
|
-
|
|
126
|
-
fileContent = fileContent.replace(9999999999, portFrontend)
|
|
127
|
-
.replace('[[PORTNUMBERBACKEND]]', portBackend);
|
|
128
|
-
|
|
129
|
-
write(templateDir, root, file, fileContent);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function write(templateDir, root, file, content) {
|
|
133
|
-
const targetPath = renameFiles[file] ?
|
|
134
|
-
path.join(root, renameFiles[file]) :
|
|
135
|
-
path.join(root, file);
|
|
136
|
-
if (content) {
|
|
137
|
-
fs.writeFileSync(targetPath, content);
|
|
138
|
-
} else {
|
|
139
|
-
copy(path.join(templateDir, file), targetPath);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function copy(src, dest) {
|
|
144
|
-
const stat = fs.statSync(src);
|
|
145
|
-
if (stat.isDirectory()) {
|
|
146
|
-
copyDir(src, dest);
|
|
147
|
-
} else {
|
|
148
|
-
fs.copyFileSync(src, dest);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function testScriptParams(targetDir, packageName, pkgManager, portFrontend, portBackend, autoRun) {
|
|
153
|
-
if (!targetDir) {
|
|
154
|
-
throw new Error(red('✖') + ' Missing target directory');
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (!packageName || !isValidPackageName(packageName)) {
|
|
158
|
-
throw new Error(red('✖') + ' A valid, hyphenated, lowercase project name (e.g. "lowercase-hyphenated-project-name") argument must be provided.');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (pkgManager === 'error') {
|
|
162
|
-
throw new Error(red('✖') + ' The init script must be executed using yarn.');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (!portFrontend || isNaN(Number(portFrontend))) {
|
|
166
|
-
throw new Error(red('✖') + ' The front-end port parameter is required and must be a number.');
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (!portBackend || isNaN(Number(portBackend))) {
|
|
170
|
-
throw new Error(red('✖') + ' The back-end port parameter is required and must be a number.');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
let arBool = (autoRun.toString().toLowerCase() === 'true' ?
|
|
174
|
-
true :
|
|
175
|
-
(autoRun.toString().toLowerCase() === 'false' ?
|
|
176
|
-
false :
|
|
177
|
-
'')
|
|
178
|
-
);
|
|
179
|
-
if (typeof arBool !== 'boolean') {
|
|
180
|
-
throw new Error(red('✖') + ' The autoRun parameter must be present and a boolean value.');
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function isValidPackageName(projectName) {
|
|
185
|
-
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
|
|
186
|
-
projectName
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function copyDir(srcDir, destDir) {
|
|
191
|
-
fs.mkdirSync(destDir, { recursive: true });
|
|
192
|
-
for (const file of fs.readdirSync(srcDir)) {
|
|
193
|
-
const srcFile = path.resolve(srcDir, file);
|
|
194
|
-
const destFile = path.resolve(destDir, file);
|
|
195
|
-
copy(srcFile, destFile);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function emptyDir(dir) {
|
|
200
|
-
if (!fs.existsSync(dir)) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
for (const file of fs.readdirSync(dir)) {
|
|
204
|
-
const abs = path.resolve(dir, file);
|
|
205
|
-
// baseline is Node 12 so can't use rmSync :(
|
|
206
|
-
if (fs.lstatSync(abs).isDirectory()) {
|
|
207
|
-
emptyDir(abs);
|
|
208
|
-
fs.rmdirSync(abs);
|
|
209
|
-
} else {
|
|
210
|
-
fs.unlinkSync(abs);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function getFilesInFlatArray(path) {
|
|
216
|
-
const files = [];
|
|
217
|
-
for (const file of fs.readdirSync(path)) {
|
|
218
|
-
const fullPath = path + '/' + file;
|
|
219
|
-
if (fs.lstatSync(fullPath).isDirectory()) getFilesInFlatArray(fullPath).forEach(x => files.push(file + '/' + x));
|
|
220
|
-
else files.push(file);
|
|
221
|
-
}
|
|
222
|
-
return files;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function ensureFilesDoNotContainBoilerplateData() {
|
|
226
|
-
const files = getFilesInFlatArray(root);
|
|
227
|
-
|
|
228
|
-
for (const filePath of files) {
|
|
229
|
-
let oldFilePath = path.join(root, filePath);
|
|
230
|
-
let newFilePath = path.join(root, filePath);
|
|
231
|
-
|
|
232
|
-
if (!fs.lstatSync(oldFilePath).isDirectory()) {
|
|
233
|
-
if (newFilePath.indexOf(boilerplateAppText) > -1) {
|
|
234
|
-
newFilePath = newFilePath.replace(boilerplateAppText, packageName);
|
|
235
|
-
fs.renameSync(oldFilePath, newFilePath);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
let fileContent = fs.readFileSync(newFilePath, fsOptions);
|
|
239
|
-
if (fileContent && typeof fileContent === 'string') {
|
|
240
|
-
fileContent = fileContent.replaceAll(boilerplateAppText, packageName);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
fs.writeFileSync(newFilePath, fileContent);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
init().catch((e) => {
|
|
249
|
-
console.error(e);
|
|
250
|
-
});
|