create-arcstack 0.1.0
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 +61 -0
- package/bin/run.cjs +341 -0
- package/bin/run.cjs.map +1 -0
- package/bin/run.d.cts +1 -0
- package/bin/run.d.ts +1 -0
- package/bin/run.js +308 -0
- package/bin/run.js.map +1 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[![Create Arcstack][i1]][l1]
|
|
2
|
+
[![Downloads][d1]][d1]
|
|
3
|
+
|
|
4
|
+
# About Create Arcstack
|
|
5
|
+
|
|
6
|
+
Scaffold new applications using any of the Arcstack templates and starter kits.
|
|
7
|
+
|
|
8
|
+
## Starter kits
|
|
9
|
+
|
|
10
|
+
You can choose between one of the following official starter kits
|
|
11
|
+
|
|
12
|
+
- `express` : An Express.js app scaffolded with Tonelix's Arcstack
|
|
13
|
+
- `h3` : An H3.js app scaffolded with Tonelix's Arcstack
|
|
14
|
+
- More coming soon...
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
# Using npm
|
|
20
|
+
npm init arcstack
|
|
21
|
+
|
|
22
|
+
# Using yarn
|
|
23
|
+
yarn create arcstack
|
|
24
|
+
|
|
25
|
+
# Using pnpm
|
|
26
|
+
pnpm create arcstack
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Options
|
|
30
|
+
|
|
31
|
+
### `location`
|
|
32
|
+
|
|
33
|
+
You can pass the installation `location` directory as the first argument to the command. For example:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npm init arcstack my-app
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
or even
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
npm init arcstack ./
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
This argument is optional and the command will prompt you to enter the installation `location` if not provided.
|
|
46
|
+
|
|
47
|
+
## Contributing
|
|
48
|
+
|
|
49
|
+
Thank you for considering contributing to the Arcstack framework! The [Contribution Guide](https://github.com/toneflix/arcstack/blob/main/CONTRIBUTING.md) can be found in the Arcstack documentation and will provide you with all the information you need to get started.
|
|
50
|
+
|
|
51
|
+
## Security Vulnerabilities
|
|
52
|
+
|
|
53
|
+
If you discover a security vulnerability within Arcstack, please send an e-mail to Legacy via [oss@toneflix.net](mailto:oss@toneflix.net). All security vulnerabilities will be promptly addressed.
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
[MIT License](LICENSE).
|
|
58
|
+
|
|
59
|
+
[i1]: https://img.shields.io/npm/v/create-arcstack?style=flat-square&label=create-arcstack&color=%230970ce
|
|
60
|
+
[l1]: https://www.npmjs.com/package/create-arcstack
|
|
61
|
+
[d1]: https://img.shields.io/npm/dt/create-arcstack?style=flat-square&label=Downloads&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fcreate-arcstack
|
package/bin/run.cjs
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//#region rolldown:runtime
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
let __h3ravel_musket = require("@h3ravel/musket");
|
|
26
|
+
__h3ravel_musket = __toESM(__h3ravel_musket);
|
|
27
|
+
let inquirer = require("inquirer");
|
|
28
|
+
inquirer = __toESM(inquirer);
|
|
29
|
+
let __inquirer_core = require("@inquirer/core");
|
|
30
|
+
__inquirer_core = __toESM(__inquirer_core);
|
|
31
|
+
let node_path = require("node:path");
|
|
32
|
+
node_path = __toESM(node_path);
|
|
33
|
+
let __h3ravel_support = require("@h3ravel/support");
|
|
34
|
+
__h3ravel_support = __toESM(__h3ravel_support);
|
|
35
|
+
let __h3ravel_shared = require("@h3ravel/shared");
|
|
36
|
+
__h3ravel_shared = __toESM(__h3ravel_shared);
|
|
37
|
+
let node_fs_promises = require("node:fs/promises");
|
|
38
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
39
|
+
let __antfu_install_pkg = require("@antfu/install-pkg");
|
|
40
|
+
__antfu_install_pkg = __toESM(__antfu_install_pkg);
|
|
41
|
+
let giget = require("giget");
|
|
42
|
+
giget = __toESM(giget);
|
|
43
|
+
let node_fs = require("node:fs");
|
|
44
|
+
node_fs = __toESM(node_fs);
|
|
45
|
+
let ora = require("ora");
|
|
46
|
+
ora = __toESM(ora);
|
|
47
|
+
|
|
48
|
+
//#region src/logo.ts
|
|
49
|
+
const altLogo = String.raw`%c
|
|
50
|
+
_ __ _ _
|
|
51
|
+
/_\ _ __ ___/ _\ |_ __ _ ___| | __
|
|
52
|
+
//_\\| '__/ __\ \| __/ _\ |/ __| |/ /
|
|
53
|
+
/ _ \ | | (___\ \ || (_| | (__| <
|
|
54
|
+
\_/ \_/_| \___\__/\__\__,_|\___|_|\_\
|
|
55
|
+
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/templates.ts
|
|
60
|
+
/**
|
|
61
|
+
* List of first party templates
|
|
62
|
+
*/
|
|
63
|
+
const templates = [{
|
|
64
|
+
name: "Express Starter Kit",
|
|
65
|
+
alias: "express",
|
|
66
|
+
hint: "An Express application starter kit",
|
|
67
|
+
source: "github:toneflix/arcstack"
|
|
68
|
+
}, {
|
|
69
|
+
name: "H3 Starter Kit",
|
|
70
|
+
alias: "h3",
|
|
71
|
+
hint: "A H3 application starter kit",
|
|
72
|
+
source: "github:toneflix/arcstack"
|
|
73
|
+
}];
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/actions.ts
|
|
77
|
+
var actions_default = class {
|
|
78
|
+
skipInstallation;
|
|
79
|
+
constructor(location, appName, description) {
|
|
80
|
+
this.location = location;
|
|
81
|
+
this.appName = appName;
|
|
82
|
+
this.description = description;
|
|
83
|
+
if (!this.location) this.location = (0, node_path.join)(process.cwd(), ".temp");
|
|
84
|
+
}
|
|
85
|
+
async pm() {
|
|
86
|
+
return await (0, __antfu_install_pkg.detectPackageManager)() ?? "npm";
|
|
87
|
+
}
|
|
88
|
+
async runCmd(npx = false) {
|
|
89
|
+
if (npx) return "npx";
|
|
90
|
+
const pm = await this.pm();
|
|
91
|
+
return pm === "npm" ? "npm run" : pm;
|
|
92
|
+
}
|
|
93
|
+
async download(template, install = false, auth, overwrite = false) {
|
|
94
|
+
if (this.location?.includes(".temp") || overwrite && (0, node_fs.existsSync)(this.location)) await (0, node_fs_promises.rm)(this.location, {
|
|
95
|
+
force: true,
|
|
96
|
+
recursive: true
|
|
97
|
+
});
|
|
98
|
+
else if ((0, node_fs.existsSync)(this.location)) {
|
|
99
|
+
console.log("\n");
|
|
100
|
+
__h3ravel_shared.Logger.parse([
|
|
101
|
+
[" ERROR ", "bgRed"],
|
|
102
|
+
[this.location, ["gray", "italic"]],
|
|
103
|
+
["is not empty.", "white"]
|
|
104
|
+
], " ");
|
|
105
|
+
console.log("");
|
|
106
|
+
process.exit(0);
|
|
107
|
+
}
|
|
108
|
+
this.skipInstallation = !install;
|
|
109
|
+
this.removeLockFile();
|
|
110
|
+
return await (0, giget.downloadTemplate)(template, {
|
|
111
|
+
dir: this.location,
|
|
112
|
+
auth,
|
|
113
|
+
install,
|
|
114
|
+
registry: await this.pm(),
|
|
115
|
+
forceClean: false
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async installPackage(name) {
|
|
119
|
+
await (0, __antfu_install_pkg.installPackage)(name, {
|
|
120
|
+
cwd: this.location,
|
|
121
|
+
silent: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async complete(installed = false) {
|
|
125
|
+
console.log("");
|
|
126
|
+
__h3ravel_shared.Logger.success("Your Arcstack project has been created successfully");
|
|
127
|
+
__h3ravel_shared.Logger.parse([["cd", "cyan"], ["./" + (0, node_path.relative)(process.cwd(), this.location), "green"]]);
|
|
128
|
+
if (!installed) __h3ravel_shared.Logger.parse([[await __h3ravel_shared.Resolver.getPakageInstallCommand(), "cyan"]]);
|
|
129
|
+
__h3ravel_shared.Logger.parse([[await this.runCmd(), "cyan"], ["dev", "green"]], " ");
|
|
130
|
+
__h3ravel_shared.Logger.parse([["Open http://localhost:3000", "cyan"]]);
|
|
131
|
+
console.log("");
|
|
132
|
+
__h3ravel_shared.Logger.parse([["Have any questions", "white"]]);
|
|
133
|
+
__h3ravel_shared.Logger.parse([["Checkout our other projects -", "white"], ["https://toneflix.net/open-source", "yellow"]]);
|
|
134
|
+
}
|
|
135
|
+
async cleanup() {
|
|
136
|
+
const pkgPath = (0, node_path.join)(this.location, "package.json");
|
|
137
|
+
const pkg = await (0, node_fs_promises.readFile)(pkgPath, "utf-8").then(JSON.parse);
|
|
138
|
+
delete pkg.packageManager;
|
|
139
|
+
pkg.name = __h3ravel_support.Str.slugify(this.appName ?? (0, node_path.basename)(this.location).replace(".", ""), "-");
|
|
140
|
+
pkg.scripts = __h3ravel_shared.packageJsonScript;
|
|
141
|
+
if (this.description) pkg.description = this.description;
|
|
142
|
+
await Promise.allSettled([
|
|
143
|
+
(0, node_fs_promises.writeFile)(pkgPath, JSON.stringify(pkg, null, 2)),
|
|
144
|
+
this.removeLockFile(),
|
|
145
|
+
(0, node_fs_promises.rm)((0, node_path.join)(this.location, "pnpm-workspace.yaml"), { force: true }),
|
|
146
|
+
(0, node_fs_promises.rm)((0, node_path.join)(this.location, "README.md"), { force: true }),
|
|
147
|
+
(0, node_fs_promises.rm)((0, node_path.join)(this.location, ".github"), {
|
|
148
|
+
force: true,
|
|
149
|
+
recursive: true
|
|
150
|
+
})
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
async removeLockFile() {
|
|
154
|
+
if (!this.skipInstallation) return;
|
|
155
|
+
await Promise.allSettled([
|
|
156
|
+
(0, node_fs_promises.unlink)((0, node_path.join)(this.location, "package-lock.json")),
|
|
157
|
+
(0, node_fs_promises.unlink)((0, node_path.join)(this.location, "yarn.lock")),
|
|
158
|
+
(0, node_fs_promises.unlink)((0, node_path.join)(this.location, "pnpm-lock.yaml"))
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
async getBanner() {
|
|
162
|
+
return await (0, node_fs_promises.readFile)((0, node_path.join)(process.cwd(), "./logo.txt"), "utf-8");
|
|
163
|
+
}
|
|
164
|
+
async copyExampleEnv() {
|
|
165
|
+
const envPath = (0, node_path.join)(this.location, ".env");
|
|
166
|
+
const exampleEnvPath = (0, node_path.join)(this.location, ".env.example");
|
|
167
|
+
if ((0, node_fs.existsSync)(exampleEnvPath)) await (0, node_fs_promises.copyFile)(exampleEnvPath, envPath);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/utils.ts
|
|
173
|
+
/**
|
|
174
|
+
* Removes all files in dirPath except the one specified by keepFileName
|
|
175
|
+
*
|
|
176
|
+
* @param dirPath
|
|
177
|
+
* @param keepFileName
|
|
178
|
+
*/
|
|
179
|
+
async function cleanDirectoryExcept(dirPath, keepFileName) {
|
|
180
|
+
const files = await (0, node_fs_promises.readdir)(dirPath);
|
|
181
|
+
for (const file of files) {
|
|
182
|
+
if (file === keepFileName) continue;
|
|
183
|
+
await (0, node_fs_promises.rm)(node_path.default.join(dirPath, file), {
|
|
184
|
+
recursive: true,
|
|
185
|
+
force: true
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Moves all files from dirPath to parent directory and removes dirPath
|
|
191
|
+
*
|
|
192
|
+
* @param dirPath
|
|
193
|
+
* @param parent
|
|
194
|
+
*/
|
|
195
|
+
async function hoistDirectoryContents(parent, dirPath) {
|
|
196
|
+
const source = node_path.default.isAbsolute(dirPath) ? dirPath : node_path.default.join(process.cwd(), dirPath);
|
|
197
|
+
const targetParent = node_path.default.isAbsolute(parent) ? parent : node_path.default.join(process.cwd(), parent);
|
|
198
|
+
if (!source.startsWith(targetParent)) throw new Error("Source must be inside the parent directory");
|
|
199
|
+
const entries = await (0, node_fs_promises.readdir)(source);
|
|
200
|
+
for (const entry of entries) await (0, node_fs_promises.rename)(node_path.default.join(source, entry), node_path.default.join(targetParent, entry));
|
|
201
|
+
await (0, node_fs_promises.rm)(source, { recursive: true });
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/Commands/CreateArcstackCommand.ts
|
|
206
|
+
var CreateArcstackCommand = class extends __h3ravel_musket.Command {
|
|
207
|
+
signature = `create-arcstack
|
|
208
|
+
{location?: The location where this project should be created relative to the current dir.}
|
|
209
|
+
{--n|name?: The name of your project.}
|
|
210
|
+
{--i|install: Install node_modules right away}
|
|
211
|
+
{--t|token?: Kit repo authentication token.}
|
|
212
|
+
{--d|desc?: Project Description.}
|
|
213
|
+
{--k|kit?: Starter template kit.}
|
|
214
|
+
{--p|pre: Download prerelease version if available.}
|
|
215
|
+
{--o|overwrite: Overwrite the installation directory if it is not empty.}
|
|
216
|
+
`;
|
|
217
|
+
description = "Display a personalized greeting.";
|
|
218
|
+
async handle() {
|
|
219
|
+
const options = this.options();
|
|
220
|
+
const pathName = this.argument("location");
|
|
221
|
+
console.log(altLogo, `font-family: monospace`);
|
|
222
|
+
let { template } = await inquirer.default.prompt([{
|
|
223
|
+
type: "list",
|
|
224
|
+
name: "template",
|
|
225
|
+
message: "Choose starter template kit:",
|
|
226
|
+
choices: templates.map((e) => ({
|
|
227
|
+
name: e.name,
|
|
228
|
+
value: e.alias,
|
|
229
|
+
disabled: !e.source ? "(Unavailable at this time)" : false
|
|
230
|
+
})),
|
|
231
|
+
default: "full",
|
|
232
|
+
when: () => !options.kit
|
|
233
|
+
}]).catch((err) => {
|
|
234
|
+
if (err instanceof __inquirer_core.AbortPromptError || err instanceof __inquirer_core.ExitPromptError) {
|
|
235
|
+
this.info("Thanks for trying out our starter kit.");
|
|
236
|
+
process.exit(0);
|
|
237
|
+
}
|
|
238
|
+
return err;
|
|
239
|
+
});
|
|
240
|
+
let { appName, description } = await inquirer.default.prompt([{
|
|
241
|
+
type: "input",
|
|
242
|
+
name: "appName",
|
|
243
|
+
message: "What is the name of your project:",
|
|
244
|
+
default: `arcstack-${template}`,
|
|
245
|
+
when: () => !options.name
|
|
246
|
+
}, {
|
|
247
|
+
type: "input",
|
|
248
|
+
name: "description",
|
|
249
|
+
message: "Project Description:",
|
|
250
|
+
default: `Simple ${__h3ravel_support.Str.of(template).ucfirst()}.js project created with Arcstack.`,
|
|
251
|
+
when: () => !options.desc
|
|
252
|
+
}]).catch((err) => {
|
|
253
|
+
if (err instanceof __inquirer_core.AbortPromptError || err instanceof __inquirer_core.ExitPromptError) {
|
|
254
|
+
this.info("Thanks for trying out our starter kit.");
|
|
255
|
+
process.exit(0);
|
|
256
|
+
}
|
|
257
|
+
return err;
|
|
258
|
+
});
|
|
259
|
+
let { location } = await inquirer.default.prompt([{
|
|
260
|
+
type: "input",
|
|
261
|
+
name: "location",
|
|
262
|
+
message: "Installation location relative to the current dir:",
|
|
263
|
+
default: __h3ravel_support.Str.slugify(options.name ?? appName ?? (0, node_path.basename)(process.cwd()), "-"),
|
|
264
|
+
when: () => !pathName
|
|
265
|
+
}]).catch((err) => {
|
|
266
|
+
if (err instanceof __inquirer_core.AbortPromptError || err instanceof __inquirer_core.ExitPromptError) {
|
|
267
|
+
this.info("Thanks for trying out our starter kit.");
|
|
268
|
+
process.exit(0);
|
|
269
|
+
}
|
|
270
|
+
return err;
|
|
271
|
+
});
|
|
272
|
+
/**
|
|
273
|
+
* Find selected template kit
|
|
274
|
+
*/
|
|
275
|
+
const kit = templates.find((e) => e.alias === template);
|
|
276
|
+
let { install, token, pre } = await inquirer.default.prompt([
|
|
277
|
+
{
|
|
278
|
+
type: "confirm",
|
|
279
|
+
name: "pre",
|
|
280
|
+
message: `An alpha version of the ${kit.name.replace(/\s*kit$/i, "").trim()} kit is available. Would you like to use it instead?`,
|
|
281
|
+
default: false,
|
|
282
|
+
when: () => kit.prereleaseSource && !options.pre
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
type: "input",
|
|
286
|
+
name: "token",
|
|
287
|
+
message: "Authentication token:",
|
|
288
|
+
when: () => options.kit && !options.token
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
type: "confirm",
|
|
292
|
+
name: "install",
|
|
293
|
+
message: "Would you want to install node_modules right away:",
|
|
294
|
+
default: true,
|
|
295
|
+
when: () => !options.install
|
|
296
|
+
}
|
|
297
|
+
]).catch((err) => {
|
|
298
|
+
if (err instanceof __inquirer_core.AbortPromptError || err instanceof __inquirer_core.ExitPromptError) {
|
|
299
|
+
this.info("Thanks for trying out our starter kit.");
|
|
300
|
+
process.exit(0);
|
|
301
|
+
}
|
|
302
|
+
return err;
|
|
303
|
+
});
|
|
304
|
+
pre = options.pre ?? pre;
|
|
305
|
+
token = options.token ?? token;
|
|
306
|
+
appName = options.name ?? appName;
|
|
307
|
+
install = options.install ?? install;
|
|
308
|
+
template = options.kit ?? template;
|
|
309
|
+
location = pathName ?? location;
|
|
310
|
+
description = options.description ?? description;
|
|
311
|
+
/**
|
|
312
|
+
* Validate selected kit
|
|
313
|
+
*/
|
|
314
|
+
if (kit && !kit.source) {
|
|
315
|
+
this.error(`ERROR: The ${kit.name} kit is not currently available`);
|
|
316
|
+
process.exit(1);
|
|
317
|
+
}
|
|
318
|
+
const source = pre && kit.prereleaseSource ? kit.prereleaseSource : kit.source;
|
|
319
|
+
const actions = new actions_default((0, node_path.join)(process.cwd(), location), appName, description);
|
|
320
|
+
const spinner = (0, ora.default)(`Loading Template...`).start();
|
|
321
|
+
const result = await actions.download(source, install, token, options.overwrite);
|
|
322
|
+
if (result.dir && kit.alias) {
|
|
323
|
+
await cleanDirectoryExcept(result.dir, kit.alias);
|
|
324
|
+
await hoistDirectoryContents(result.dir, (0, node_path.join)(result.dir, kit.alias));
|
|
325
|
+
}
|
|
326
|
+
spinner.info(__h3ravel_shared.Logger.parse([["Cleaning Up...", "green"]], "", false)).start();
|
|
327
|
+
await actions.cleanup();
|
|
328
|
+
spinner.info(__h3ravel_shared.Logger.parse([["Initializing Project...", "green"]], "", false)).start();
|
|
329
|
+
await actions.copyExampleEnv();
|
|
330
|
+
spinner.succeed(__h3ravel_shared.Logger.parse([["Project initialization complete!", "green"]], "", false));
|
|
331
|
+
await actions.complete(install);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/run.ts
|
|
337
|
+
var Application = class {};
|
|
338
|
+
__h3ravel_musket.Kernel.init(new Application(), { rootCommand: CreateArcstackCommand });
|
|
339
|
+
|
|
340
|
+
//#endregion
|
|
341
|
+
//# sourceMappingURL=run.cjs.map
|
package/bin/run.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.cjs","names":["templates: {\n name: string;\n alias: \"express\" | \"h3\";\n hint: string;\n source: string;\n prereleaseSource?: string;\n}[]","location?: string","appName?: string","description?: string","Resolver","Str","packageJsonScript","path","Command","AbortPromptError","ExitPromptError","Str","source: string","Actions","Logger","Kernel"],"sources":["../src/logo.ts","../src/templates.ts","../src/actions.ts","../src/utils.ts","../src/Commands/CreateArcstackCommand.ts","../src/run.ts"],"sourcesContent":["export const altLogo = String.raw`%c\n _ __ _ _ \n /_\\ _ __ ___/ _\\ |_ __ _ ___| | __\n //_\\\\| '__/ __\\ \\| __/ _\\ |/ __| |/ /\n/ _ \\ | | (___\\ \\ || (_| | (__| < \n\\_/ \\_/_| \\___\\__/\\__\\__,_|\\___|_|\\_\\\n \n`;\n","/*\n * create-h3ravel\n *\n * (c) H3ravel Framework\n *\n * The H3ravel framework and all it's base packages are\n * open-sourced software licensed under the MIT license.\n */\n\n/**\n * List of first party templates\n */\nexport const templates: {\n name: string;\n alias: \"express\" | \"h3\";\n hint: string;\n source: string;\n prereleaseSource?: string;\n}[] = [\n {\n name: \"Express Starter Kit\",\n alias: \"express\",\n hint: \"An Express application starter kit\",\n source: \"github:toneflix/arcstack\",\n },\n {\n name: \"H3 Starter Kit\",\n alias: \"h3\",\n hint: \"A H3 application starter kit\",\n source: \"github:toneflix/arcstack\",\n },\n];\n","import { Logger, Resolver, packageJsonScript } from \"@h3ravel/shared\";\nimport { basename, join, relative } from \"node:path\";\nimport { copyFile, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { detectPackageManager, installPackage } from \"@antfu/install-pkg\";\n\nimport { Str } from \"@h3ravel/support\";\nimport { downloadTemplate } from \"giget\";\nimport { existsSync } from \"node:fs\";\nimport { unlink } from \"node:fs/promises\";\n\nexport default class {\n skipInstallation?: boolean;\n\n constructor(\n private location?: string,\n private appName?: string,\n private description?: string,\n ) {\n if (!this.location) {\n this.location = join(process.cwd(), \".temp\");\n }\n }\n\n async pm() {\n return (await detectPackageManager()) ?? \"npm\";\n }\n\n async runCmd(npx: boolean = false) {\n if (npx) return \"npx\";\n\n const pm = await this.pm();\n\n return pm === \"npm\" ? \"npm run\" : pm;\n }\n\n async download(template: string, install = false, auth?: string, overwrite = false) {\n if (this.location?.includes(\".temp\") || (overwrite && existsSync(this.location!))) {\n await rm(this.location!, { force: true, recursive: true });\n } else if (existsSync(this.location!)) {\n console.log(\"\\n\");\n Logger.parse(\n [\n [\" ERROR \", \"bgRed\"],\n [this.location!, [\"gray\", \"italic\"]],\n [\"is not empty.\", \"white\"],\n ],\n \" \",\n );\n console.log(\"\");\n process.exit(0);\n }\n\n this.skipInstallation = !install;\n this.removeLockFile();\n\n return await downloadTemplate(template, {\n dir: this.location,\n auth,\n install,\n registry: await this.pm(),\n forceClean: false,\n });\n }\n\n async installPackage(name: string) {\n await installPackage(name, {\n cwd: this.location,\n silent: true,\n });\n }\n\n async complete(installed = false) {\n console.log(\"\");\n\n Logger.success(\"Your Arcstack project has been created successfully\");\n Logger.parse([\n [\"cd\", \"cyan\"],\n [\"./\" + relative(process.cwd(), this.location!), \"green\"],\n ]);\n if (!installed) {\n Logger.parse([[await Resolver.getPakageInstallCommand(), \"cyan\"]]);\n }\n\n Logger.parse(\n [\n [await this.runCmd(), \"cyan\"],\n [\"dev\", \"green\"],\n ],\n \" \",\n );\n Logger.parse([[\"Open http://localhost:3000\", \"cyan\"]]);\n\n console.log(\"\");\n\n Logger.parse([[\"Have any questions\", \"white\"]]);\n // Logger.parse([\n // [\"Join our Discord server -\", \"white\"],\n // [\"https://discord.gg/hsG2A8PuGb\", \"yellow\"],\n // ]);\n Logger.parse([\n [\"Checkout our other projects -\", \"white\"],\n [\"https://toneflix.net/open-source\", \"yellow\"],\n ]);\n }\n\n async cleanup() {\n const pkgPath = join(this.location!, \"package.json\");\n const pkg = await readFile(pkgPath!, \"utf-8\").then(JSON.parse);\n\n delete pkg.packageManager;\n pkg.name = Str.slugify(this.appName ?? basename(this.location!).replace(\".\", \"\"), \"-\");\n pkg.scripts = packageJsonScript;\n if (this.description) {\n pkg.description = this.description;\n }\n\n await Promise.allSettled([\n writeFile(pkgPath, JSON.stringify(pkg, null, 2)),\n this.removeLockFile(),\n rm(join(this.location!, \"pnpm-workspace.yaml\"), { force: true }),\n rm(join(this.location!, \"README.md\"), { force: true }),\n rm(join(this.location!, \".github\"), { force: true, recursive: true }),\n ]);\n }\n\n async removeLockFile() {\n if (!this.skipInstallation) {\n return;\n }\n\n await Promise.allSettled([\n unlink(join(this.location!, \"package-lock.json\")),\n unlink(join(this.location!, \"yarn.lock\")),\n unlink(join(this.location!, \"pnpm-lock.yaml\")),\n ]);\n }\n\n async getBanner() {\n return await readFile(join(process.cwd(), \"./logo.txt\"), \"utf-8\");\n }\n\n async copyExampleEnv() {\n const envPath = join(this.location!, \".env\");\n const exampleEnvPath = join(this.location!, \".env.example\");\n\n if (existsSync(exampleEnvPath)) {\n await copyFile(exampleEnvPath, envPath);\n }\n }\n}\n","import { readdir, rename } from \"node:fs/promises\";\n\nimport path from \"node:path\";\nimport { rm } from \"node:fs/promises\";\n\n/**\n * Removes all files in dirPath except the one specified by keepFileName\n *\n * @param dirPath\n * @param keepFileName\n */\nexport async function cleanDirectoryExcept(dirPath: string, keepFileName: string) {\n const files = await readdir(dirPath);\n\n for (const file of files) {\n if (file === keepFileName) continue;\n\n const fullPath = path.join(dirPath, file);\n\n await rm(fullPath, { recursive: true, force: true });\n }\n}\n\n/**\n * Moves all files from dirPath to parent directory and removes dirPath\n *\n * @param dirPath\n * @param parent\n */\nexport async function hoistDirectoryContents(parent: string, dirPath: string) {\n const source = path.isAbsolute(dirPath) ? dirPath : path.join(process.cwd(), dirPath);\n\n const targetParent = path.isAbsolute(parent) ? parent : path.join(process.cwd(), parent);\n\n if (!source.startsWith(targetParent)) {\n throw new Error(\"Source must be inside the parent directory\");\n }\n\n const entries = await readdir(source);\n\n for (const entry of entries) {\n const from = path.join(source, entry);\n const to = path.join(targetParent, entry);\n\n await rename(from, to);\n }\n\n await rm(source, { recursive: true });\n}\n","import { Command } from \"@h3ravel/musket\";\nimport { altLogo } from \"src/logo\";\nimport inquirer from \"inquirer\";\nimport { AbortPromptError, ExitPromptError } from \"@inquirer/core\";\nimport { basename, join } from \"node:path\";\nimport { templates } from \"src/templates\";\nimport { Str } from \"@h3ravel/support\";\nimport Actions from \"src/actions\";\nimport ora from \"ora\";\nimport { Logger } from \"@h3ravel/shared\";\nimport { cleanDirectoryExcept, hoistDirectoryContents } from \"src/utils\";\n\nexport class CreateArcstackCommand extends Command {\n protected signature = `create-arcstack\n {location?: The location where this project should be created relative to the current dir.}\n {--n|name?: The name of your project.}\n {--i|install: Install node_modules right away}\n {--t|token?: Kit repo authentication token.}\n {--d|desc?: Project Description.}\n {--k|kit?: Starter template kit.}\n {--p|pre: Download prerelease version if available.}\n {--o|overwrite: Overwrite the installation directory if it is not empty.}\n `;\n protected description = \"Display a personalized greeting.\";\n\n async handle() {\n const options = this.options();\n const pathName = this.argument(\"location\");\n\n console.log(altLogo, `font-family: monospace`);\n\n let { template } = await inquirer\n .prompt([\n {\n type: \"list\",\n name: \"template\",\n message: \"Choose starter template kit:\",\n choices: <never>templates.map((e) => ({\n name: e.name,\n value: e.alias,\n disabled: !e.source ? \"(Unavailable at this time)\" : false,\n })),\n default: \"full\",\n when: () => !options.kit,\n },\n ])\n .catch((err) => {\n if (err instanceof AbortPromptError || err instanceof ExitPromptError) {\n this.info(\"Thanks for trying out our starter kit.\");\n process.exit(0);\n }\n return err;\n });\n\n let { appName, description } = await inquirer\n .prompt([\n {\n type: \"input\",\n name: \"appName\",\n message: \"What is the name of your project:\",\n default: `arcstack-${template}`,\n when: () => !options.name,\n },\n {\n type: \"input\",\n name: \"description\",\n message: \"Project Description:\",\n default: `Simple ${Str.of(template).ucfirst()}.js project created with Arcstack.`,\n when: () => !options.desc,\n },\n ])\n .catch((err) => {\n if (err instanceof AbortPromptError || err instanceof ExitPromptError) {\n this.info(\"Thanks for trying out our starter kit.\");\n process.exit(0);\n }\n return err;\n });\n\n let { location } = await inquirer\n .prompt([\n {\n type: \"input\",\n name: \"location\",\n message: \"Installation location relative to the current dir:\",\n default: Str.slugify(options.name ?? appName ?? basename(process.cwd()), \"-\"),\n when: () => !pathName,\n },\n ])\n .catch((err) => {\n if (err instanceof AbortPromptError || err instanceof ExitPromptError) {\n this.info(\"Thanks for trying out our starter kit.\");\n process.exit(0);\n }\n return err;\n });\n\n /**\n * Find selected template kit\n */\n const kit = templates.find((e) => e.alias === template)!;\n\n let { install, token, pre } = await inquirer\n .prompt([\n {\n type: \"confirm\",\n name: \"pre\",\n message: `An alpha version of the ${kit.name.replace(/\\s*kit$/i, \"\").trim()} kit is available. Would you like to use it instead?`,\n default: false,\n when: () => kit.prereleaseSource && !options.pre,\n } as never,\n {\n type: \"input\",\n name: \"token\",\n message: \"Authentication token:\",\n when: () => options.kit && !options.token,\n },\n {\n type: \"confirm\",\n name: \"install\",\n message: \"Would you want to install node_modules right away:\",\n default: true,\n when: () => !options.install,\n },\n ])\n .catch((err) => {\n if (err instanceof AbortPromptError || err instanceof ExitPromptError) {\n this.info(\"Thanks for trying out our starter kit.\");\n process.exit(0);\n }\n return err;\n });\n\n pre = options.pre ?? pre;\n token = options.token ?? token;\n appName = options.name ?? appName;\n install = options.install ?? install;\n template = options.kit ?? template;\n location = pathName ?? location;\n description = options.description ?? description;\n\n /**\n * Validate selected kit\n */\n if (kit && !kit.source) {\n this.error(`ERROR: The ${kit.name} kit is not currently available`);\n process.exit(1);\n }\n\n const source: string = pre && kit.prereleaseSource ? kit.prereleaseSource! : kit.source;\n const actions = new Actions(join(process.cwd(), location), appName, description);\n const spinner = ora(`Loading Template...`).start();\n\n const result = await actions.download(source, install, token, options.overwrite);\n\n if (result.dir && kit.alias) {\n await cleanDirectoryExcept(result.dir, kit.alias);\n await hoistDirectoryContents(result.dir, join(result.dir, kit.alias));\n }\n\n spinner.info(Logger.parse([[\"Cleaning Up...\", \"green\"]], \"\", false)).start();\n await actions.cleanup();\n\n spinner.info(Logger.parse([[\"Initializing Project...\", \"green\"]], \"\", false)).start();\n await actions.copyExampleEnv();\n\n spinner.succeed(Logger.parse([[\"Project initialization complete!\", \"green\"]], \"\", false));\n\n await actions.complete(install);\n }\n}\n","#!/usr/bin/env node\n\nimport { CreateArcstackCommand } from \"./Commands/CreateArcstackCommand\";\nimport { Kernel } from \"@h3ravel/musket\";\n\nclass Application {}\n\nKernel.init(new Application(), {\n rootCommand: CreateArcstackCommand,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAa,UAAU,OAAO,GAAG;;;;;;;;;;;;;;ACYjC,MAAaA,YAMP,CACJ;CACE,MAAM;CACN,OAAO;CACP,MAAM;CACN,QAAQ;CACT,EACD;CACE,MAAM;CACN,OAAO;CACP,MAAM;CACN,QAAQ;CACT,CACF;;;;ACrBD,4BAAqB;CACnB;CAEA,YACE,AAAQC,UACR,AAAQC,SACR,AAAQC,aACR;EAHQ;EACA;EACA;AAER,MAAI,CAAC,KAAK,SACR,MAAK,+BAAgB,QAAQ,KAAK,EAAE,QAAQ;;CAIhD,MAAM,KAAK;AACT,SAAQ,qDAA4B,IAAK;;CAG3C,MAAM,OAAO,MAAe,OAAO;AACjC,MAAI,IAAK,QAAO;EAEhB,MAAM,KAAK,MAAM,KAAK,IAAI;AAE1B,SAAO,OAAO,QAAQ,YAAY;;CAGpC,MAAM,SAAS,UAAkB,UAAU,OAAO,MAAe,YAAY,OAAO;AAClF,MAAI,KAAK,UAAU,SAAS,QAAQ,IAAK,qCAAwB,KAAK,SAAU,CAC9E,gCAAS,KAAK,UAAW;GAAE,OAAO;GAAM,WAAW;GAAM,CAAC;mCACtC,KAAK,SAAU,EAAE;AACrC,WAAQ,IAAI,KAAK;AACjB,2BAAO,MACL;IACE,CAAC,WAAW,QAAQ;IACpB,CAAC,KAAK,UAAW,CAAC,QAAQ,SAAS,CAAC;IACpC,CAAC,iBAAiB,QAAQ;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a,QAAQ,KAAK,EAAE,SAAS,EAAE,SAAS,YAAY;EAChF,MAAM,2BAAc,sBAAsB,CAAC,OAAO;EAElD,MAAM,SAAS,MAAM,QAAQ,SAAS,QAAQ,SAAS,OAAO,QAAQ,UAAU;AAEhF,MAAI,OAAO,OAAO,IAAI,OAAO;AAC3B,SAAM,qBAAqB,OAAO,KAAK,IAAI,MAAM;AACjD,SAAM,uBAAuB,OAAO,yBAAU,OAAO,KAAK,IAAI,MAAM,CAAC;;AAGvE,UAAQ,KAAKC,wBAAO,MAAM,CAAC,CAAC,kBAAkB,QAAQ,CAAC,EAAE,IAAI,MAAM,CAAC,CAAC,OAAO;AAC5E,QAAM,QAAQ,SAAS;AAEvB,UAAQ,KAAKA,wBAAO,MAAM,CAAC,CAAC,2BAA2B,QAAQ,CAAC,EAAE,IAAI,MAAM,CAAC,CAAC,OAAO;AACrF,QAAM,QAAQ,gBAAgB;AAE9B,UAAQ,QAAQA,wBAAO,MAAM,CAAC,CAAC,oCAAoC,QAAQ,CAAC,EAAE,IAAI,MAAM,CAAC;AAEzF,QAAM,QAAQ,SAAS,QAAQ;;;;;;ACnKnC,IAAM,cAAN,MAAkB;AAElBC,wBAAO,KAAK,IAAI,aAAa,EAAE,EAC7B,aAAa,uBACd,CAAC"}
|
package/bin/run.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/bin/run.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/bin/run.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command, Kernel } from "@h3ravel/musket";
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
import { AbortPromptError, ExitPromptError } from "@inquirer/core";
|
|
5
|
+
import path, { basename, join, relative } from "node:path";
|
|
6
|
+
import { Str } from "@h3ravel/support";
|
|
7
|
+
import { Logger, Resolver, packageJsonScript } from "@h3ravel/shared";
|
|
8
|
+
import { copyFile, readFile, readdir, rename, rm, unlink, writeFile } from "node:fs/promises";
|
|
9
|
+
import { detectPackageManager, installPackage } from "@antfu/install-pkg";
|
|
10
|
+
import { downloadTemplate } from "giget";
|
|
11
|
+
import { existsSync } from "node:fs";
|
|
12
|
+
import ora from "ora";
|
|
13
|
+
|
|
14
|
+
//#region src/logo.ts
|
|
15
|
+
const altLogo = String.raw`%c
|
|
16
|
+
_ __ _ _
|
|
17
|
+
/_\ _ __ ___/ _\ |_ __ _ ___| | __
|
|
18
|
+
//_\\| '__/ __\ \| __/ _\ |/ __| |/ /
|
|
19
|
+
/ _ \ | | (___\ \ || (_| | (__| <
|
|
20
|
+
\_/ \_/_| \___\__/\__\__,_|\___|_|\_\
|
|
21
|
+
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/templates.ts
|
|
26
|
+
/**
|
|
27
|
+
* List of first party templates
|
|
28
|
+
*/
|
|
29
|
+
const templates = [{
|
|
30
|
+
name: "Express Starter Kit",
|
|
31
|
+
alias: "express",
|
|
32
|
+
hint: "An Express application starter kit",
|
|
33
|
+
source: "github:toneflix/arcstack"
|
|
34
|
+
}, {
|
|
35
|
+
name: "H3 Starter Kit",
|
|
36
|
+
alias: "h3",
|
|
37
|
+
hint: "A H3 application starter kit",
|
|
38
|
+
source: "github:toneflix/arcstack"
|
|
39
|
+
}];
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/actions.ts
|
|
43
|
+
var actions_default = class {
|
|
44
|
+
skipInstallation;
|
|
45
|
+
constructor(location, appName, description) {
|
|
46
|
+
this.location = location;
|
|
47
|
+
this.appName = appName;
|
|
48
|
+
this.description = description;
|
|
49
|
+
if (!this.location) this.location = join(process.cwd(), ".temp");
|
|
50
|
+
}
|
|
51
|
+
async pm() {
|
|
52
|
+
return await detectPackageManager() ?? "npm";
|
|
53
|
+
}
|
|
54
|
+
async runCmd(npx = false) {
|
|
55
|
+
if (npx) return "npx";
|
|
56
|
+
const pm = await this.pm();
|
|
57
|
+
return pm === "npm" ? "npm run" : pm;
|
|
58
|
+
}
|
|
59
|
+
async download(template, install = false, auth, overwrite = false) {
|
|
60
|
+
if (this.location?.includes(".temp") || overwrite && existsSync(this.location)) await rm(this.location, {
|
|
61
|
+
force: true,
|
|
62
|
+
recursive: true
|
|
63
|
+
});
|
|
64
|
+
else if (existsSync(this.location)) {
|
|
65
|
+
console.log("\n");
|
|
66
|
+
Logger.parse([
|
|
67
|
+
[" ERROR ", "bgRed"],
|
|
68
|
+
[this.location, ["gray", "italic"]],
|
|
69
|
+
["is not empty.", "white"]
|
|
70
|
+
], " ");
|
|
71
|
+
console.log("");
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
this.skipInstallation = !install;
|
|
75
|
+
this.removeLockFile();
|
|
76
|
+
return await downloadTemplate(template, {
|
|
77
|
+
dir: this.location,
|
|
78
|
+
auth,
|
|
79
|
+
install,
|
|
80
|
+
registry: await this.pm(),
|
|
81
|
+
forceClean: false
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async installPackage(name) {
|
|
85
|
+
await installPackage(name, {
|
|
86
|
+
cwd: this.location,
|
|
87
|
+
silent: true
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
async complete(installed = false) {
|
|
91
|
+
console.log("");
|
|
92
|
+
Logger.success("Your Arcstack project has been created successfully");
|
|
93
|
+
Logger.parse([["cd", "cyan"], ["./" + relative(process.cwd(), this.location), "green"]]);
|
|
94
|
+
if (!installed) Logger.parse([[await Resolver.getPakageInstallCommand(), "cyan"]]);
|
|
95
|
+
Logger.parse([[await this.runCmd(), "cyan"], ["dev", "green"]], " ");
|
|
96
|
+
Logger.parse([["Open http://localhost:3000", "cyan"]]);
|
|
97
|
+
console.log("");
|
|
98
|
+
Logger.parse([["Have any questions", "white"]]);
|
|
99
|
+
Logger.parse([["Checkout our other projects -", "white"], ["https://toneflix.net/open-source", "yellow"]]);
|
|
100
|
+
}
|
|
101
|
+
async cleanup() {
|
|
102
|
+
const pkgPath = join(this.location, "package.json");
|
|
103
|
+
const pkg = await readFile(pkgPath, "utf-8").then(JSON.parse);
|
|
104
|
+
delete pkg.packageManager;
|
|
105
|
+
pkg.name = Str.slugify(this.appName ?? basename(this.location).replace(".", ""), "-");
|
|
106
|
+
pkg.scripts = packageJsonScript;
|
|
107
|
+
if (this.description) pkg.description = this.description;
|
|
108
|
+
await Promise.allSettled([
|
|
109
|
+
writeFile(pkgPath, JSON.stringify(pkg, null, 2)),
|
|
110
|
+
this.removeLockFile(),
|
|
111
|
+
rm(join(this.location, "pnpm-workspace.yaml"), { force: true }),
|
|
112
|
+
rm(join(this.location, "README.md"), { force: true }),
|
|
113
|
+
rm(join(this.location, ".github"), {
|
|
114
|
+
force: true,
|
|
115
|
+
recursive: true
|
|
116
|
+
})
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
async removeLockFile() {
|
|
120
|
+
if (!this.skipInstallation) return;
|
|
121
|
+
await Promise.allSettled([
|
|
122
|
+
unlink(join(this.location, "package-lock.json")),
|
|
123
|
+
unlink(join(this.location, "yarn.lock")),
|
|
124
|
+
unlink(join(this.location, "pnpm-lock.yaml"))
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
127
|
+
async getBanner() {
|
|
128
|
+
return await readFile(join(process.cwd(), "./logo.txt"), "utf-8");
|
|
129
|
+
}
|
|
130
|
+
async copyExampleEnv() {
|
|
131
|
+
const envPath = join(this.location, ".env");
|
|
132
|
+
const exampleEnvPath = join(this.location, ".env.example");
|
|
133
|
+
if (existsSync(exampleEnvPath)) await copyFile(exampleEnvPath, envPath);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/utils.ts
|
|
139
|
+
/**
|
|
140
|
+
* Removes all files in dirPath except the one specified by keepFileName
|
|
141
|
+
*
|
|
142
|
+
* @param dirPath
|
|
143
|
+
* @param keepFileName
|
|
144
|
+
*/
|
|
145
|
+
async function cleanDirectoryExcept(dirPath, keepFileName) {
|
|
146
|
+
const files = await readdir(dirPath);
|
|
147
|
+
for (const file of files) {
|
|
148
|
+
if (file === keepFileName) continue;
|
|
149
|
+
await rm(path.join(dirPath, file), {
|
|
150
|
+
recursive: true,
|
|
151
|
+
force: true
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Moves all files from dirPath to parent directory and removes dirPath
|
|
157
|
+
*
|
|
158
|
+
* @param dirPath
|
|
159
|
+
* @param parent
|
|
160
|
+
*/
|
|
161
|
+
async function hoistDirectoryContents(parent, dirPath) {
|
|
162
|
+
const source = path.isAbsolute(dirPath) ? dirPath : path.join(process.cwd(), dirPath);
|
|
163
|
+
const targetParent = path.isAbsolute(parent) ? parent : path.join(process.cwd(), parent);
|
|
164
|
+
if (!source.startsWith(targetParent)) throw new Error("Source must be inside the parent directory");
|
|
165
|
+
const entries = await readdir(source);
|
|
166
|
+
for (const entry of entries) await rename(path.join(source, entry), path.join(targetParent, entry));
|
|
167
|
+
await rm(source, { recursive: true });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/Commands/CreateArcstackCommand.ts
|
|
172
|
+
var CreateArcstackCommand = class extends Command {
|
|
173
|
+
signature = `create-arcstack
|
|
174
|
+
{location?: The location where this project should be created relative to the current dir.}
|
|
175
|
+
{--n|name?: The name of your project.}
|
|
176
|
+
{--i|install: Install node_modules right away}
|
|
177
|
+
{--t|token?: Kit repo authentication token.}
|
|
178
|
+
{--d|desc?: Project Description.}
|
|
179
|
+
{--k|kit?: Starter template kit.}
|
|
180
|
+
{--p|pre: Download prerelease version if available.}
|
|
181
|
+
{--o|overwrite: Overwrite the installation directory if it is not empty.}
|
|
182
|
+
`;
|
|
183
|
+
description = "Display a personalized greeting.";
|
|
184
|
+
async handle() {
|
|
185
|
+
const options = this.options();
|
|
186
|
+
const pathName = this.argument("location");
|
|
187
|
+
console.log(altLogo, `font-family: monospace`);
|
|
188
|
+
let { template } = await inquirer.prompt([{
|
|
189
|
+
type: "list",
|
|
190
|
+
name: "template",
|
|
191
|
+
message: "Choose starter template kit:",
|
|
192
|
+
choices: templates.map((e) => ({
|
|
193
|
+
name: e.name,
|
|
194
|
+
value: e.alias,
|
|
195
|
+
disabled: !e.source ? "(Unavailable at this time)" : false
|
|
196
|
+
})),
|
|
197
|
+
default: "full",
|
|
198
|
+
when: () => !options.kit
|
|
199
|
+
}]).catch((err) => {
|
|
200
|
+
if (err instanceof AbortPromptError || err instanceof ExitPromptError) {
|
|
201
|
+
this.info("Thanks for trying out our starter kit.");
|
|
202
|
+
process.exit(0);
|
|
203
|
+
}
|
|
204
|
+
return err;
|
|
205
|
+
});
|
|
206
|
+
let { appName, description } = await inquirer.prompt([{
|
|
207
|
+
type: "input",
|
|
208
|
+
name: "appName",
|
|
209
|
+
message: "What is the name of your project:",
|
|
210
|
+
default: `arcstack-${template}`,
|
|
211
|
+
when: () => !options.name
|
|
212
|
+
}, {
|
|
213
|
+
type: "input",
|
|
214
|
+
name: "description",
|
|
215
|
+
message: "Project Description:",
|
|
216
|
+
default: `Simple ${Str.of(template).ucfirst()}.js project created with Arcstack.`,
|
|
217
|
+
when: () => !options.desc
|
|
218
|
+
}]).catch((err) => {
|
|
219
|
+
if (err instanceof AbortPromptError || err instanceof ExitPromptError) {
|
|
220
|
+
this.info("Thanks for trying out our starter kit.");
|
|
221
|
+
process.exit(0);
|
|
222
|
+
}
|
|
223
|
+
return err;
|
|
224
|
+
});
|
|
225
|
+
let { location } = await inquirer.prompt([{
|
|
226
|
+
type: "input",
|
|
227
|
+
name: "location",
|
|
228
|
+
message: "Installation location relative to the current dir:",
|
|
229
|
+
default: Str.slugify(options.name ?? appName ?? basename(process.cwd()), "-"),
|
|
230
|
+
when: () => !pathName
|
|
231
|
+
}]).catch((err) => {
|
|
232
|
+
if (err instanceof AbortPromptError || err instanceof ExitPromptError) {
|
|
233
|
+
this.info("Thanks for trying out our starter kit.");
|
|
234
|
+
process.exit(0);
|
|
235
|
+
}
|
|
236
|
+
return err;
|
|
237
|
+
});
|
|
238
|
+
/**
|
|
239
|
+
* Find selected template kit
|
|
240
|
+
*/
|
|
241
|
+
const kit = templates.find((e) => e.alias === template);
|
|
242
|
+
let { install, token, pre } = await inquirer.prompt([
|
|
243
|
+
{
|
|
244
|
+
type: "confirm",
|
|
245
|
+
name: "pre",
|
|
246
|
+
message: `An alpha version of the ${kit.name.replace(/\s*kit$/i, "").trim()} kit is available. Would you like to use it instead?`,
|
|
247
|
+
default: false,
|
|
248
|
+
when: () => kit.prereleaseSource && !options.pre
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
type: "input",
|
|
252
|
+
name: "token",
|
|
253
|
+
message: "Authentication token:",
|
|
254
|
+
when: () => options.kit && !options.token
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
type: "confirm",
|
|
258
|
+
name: "install",
|
|
259
|
+
message: "Would you want to install node_modules right away:",
|
|
260
|
+
default: true,
|
|
261
|
+
when: () => !options.install
|
|
262
|
+
}
|
|
263
|
+
]).catch((err) => {
|
|
264
|
+
if (err instanceof AbortPromptError || err instanceof ExitPromptError) {
|
|
265
|
+
this.info("Thanks for trying out our starter kit.");
|
|
266
|
+
process.exit(0);
|
|
267
|
+
}
|
|
268
|
+
return err;
|
|
269
|
+
});
|
|
270
|
+
pre = options.pre ?? pre;
|
|
271
|
+
token = options.token ?? token;
|
|
272
|
+
appName = options.name ?? appName;
|
|
273
|
+
install = options.install ?? install;
|
|
274
|
+
template = options.kit ?? template;
|
|
275
|
+
location = pathName ?? location;
|
|
276
|
+
description = options.description ?? description;
|
|
277
|
+
/**
|
|
278
|
+
* Validate selected kit
|
|
279
|
+
*/
|
|
280
|
+
if (kit && !kit.source) {
|
|
281
|
+
this.error(`ERROR: The ${kit.name} kit is not currently available`);
|
|
282
|
+
process.exit(1);
|
|
283
|
+
}
|
|
284
|
+
const source = pre && kit.prereleaseSource ? kit.prereleaseSource : kit.source;
|
|
285
|
+
const actions = new actions_default(join(process.cwd(), location), appName, description);
|
|
286
|
+
const spinner = ora(`Loading Template...`).start();
|
|
287
|
+
const result = await actions.download(source, install, token, options.overwrite);
|
|
288
|
+
if (result.dir && kit.alias) {
|
|
289
|
+
await cleanDirectoryExcept(result.dir, kit.alias);
|
|
290
|
+
await hoistDirectoryContents(result.dir, join(result.dir, kit.alias));
|
|
291
|
+
}
|
|
292
|
+
spinner.info(Logger.parse([["Cleaning Up...", "green"]], "", false)).start();
|
|
293
|
+
await actions.cleanup();
|
|
294
|
+
spinner.info(Logger.parse([["Initializing Project...", "green"]], "", false)).start();
|
|
295
|
+
await actions.copyExampleEnv();
|
|
296
|
+
spinner.succeed(Logger.parse([["Project initialization complete!", "green"]], "", false));
|
|
297
|
+
await actions.complete(install);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/run.ts
|
|
303
|
+
var Application = class {};
|
|
304
|
+
Kernel.init(new Application(), { rootCommand: CreateArcstackCommand });
|
|
305
|
+
|
|
306
|
+
//#endregion
|
|
307
|
+
export { };
|
|
308
|
+
//# sourceMappingURL=run.js.map
|
package/bin/run.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","names":["templates: {\n name: string;\n alias: \"express\" | \"h3\";\n hint: string;\n source: string;\n prereleaseSource?: string;\n}[]","location?: string","appName?: string","description?: string","source: string","Actions"],"sources":["../src/logo.ts","../src/templates.ts","../src/actions.ts","../src/utils.ts","../src/Commands/CreateArcstackCommand.ts","../src/run.ts"],"sourcesContent":["export const altLogo = String.raw`%c\n _ __ _ _ \n /_\\ _ __ ___/ _\\ |_ __ _ ___| | __\n //_\\\\| '__/ __\\ \\| __/ _\\ |/ __| |/ /\n/ _ \\ | | (___\\ \\ || (_| | (__| < \n\\_/ \\_/_| \\___\\__/\\__\\__,_|\\___|_|\\_\\\n \n`;\n","/*\n * create-h3ravel\n *\n * (c) H3ravel Framework\n *\n * The H3ravel framework and all it's base packages are\n * open-sourced software licensed under the MIT license.\n */\n\n/**\n * List of first party templates\n */\nexport const templates: {\n name: string;\n alias: \"express\" | \"h3\";\n hint: string;\n source: string;\n prereleaseSource?: string;\n}[] = [\n {\n name: \"Express Starter Kit\",\n alias: \"express\",\n hint: \"An Express application starter kit\",\n source: \"github:toneflix/arcstack\",\n },\n {\n name: \"H3 Starter Kit\",\n alias: \"h3\",\n hint: \"A H3 application starter kit\",\n source: \"github:toneflix/arcstack\",\n },\n];\n","import { Logger, Resolver, packageJsonScript } from \"@h3ravel/shared\";\nimport { basename, join, relative } from \"node:path\";\nimport { copyFile, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { detectPackageManager, installPackage } from \"@antfu/install-pkg\";\n\nimport { Str } from \"@h3ravel/support\";\nimport { downloadTemplate } from \"giget\";\nimport { existsSync } from \"node:fs\";\nimport { unlink } from \"node:fs/promises\";\n\nexport default class {\n skipInstallation?: boolean;\n\n constructor(\n private location?: string,\n private appName?: string,\n private description?: string,\n ) {\n if (!this.location) {\n this.location = join(process.cwd(), \".temp\");\n }\n }\n\n async pm() {\n return (await detectPackageManager()) ?? \"npm\";\n }\n\n async runCmd(npx: boolean = false) {\n if (npx) return \"npx\";\n\n const pm = await this.pm();\n\n return pm === \"npm\" ? \"npm run\" : pm;\n }\n\n async download(template: string, install = false, auth?: string, overwrite = false) {\n if (this.location?.includes(\".temp\") || (overwrite && existsSync(this.location!))) {\n await rm(this.location!, { force: true, recursive: true });\n } else if (existsSync(this.location!)) {\n console.log(\"\\n\");\n Logger.parse(\n [\n [\" ERROR \", \"bgRed\"],\n [this.location!, [\"gray\", \"italic\"]],\n [\"is not empty.\", \"white\"],\n ],\n \" \",\n );\n console.log(\"\");\n process.exit(0);\n }\n\n this.skipInstallation = !install;\n this.removeLockFile();\n\n return await downloadTemplate(template, {\n dir: this.location,\n auth,\n install,\n registry: await this.pm(),\n forceClean: false,\n });\n }\n\n async installPackage(name: string) {\n await installPackage(name, {\n cwd: this.location,\n silent: true,\n });\n }\n\n async complete(installed = false) {\n console.log(\"\");\n\n Logger.success(\"Your Arcstack project has been created successfully\");\n Logger.parse([\n [\"cd\", \"cyan\"],\n [\"./\" + relative(process.cwd(), this.location!), \"green\"],\n ]);\n if (!installed) {\n Logger.parse([[await Resolver.getPakageInstallCommand(), \"cyan\"]]);\n }\n\n Logger.parse(\n [\n [await this.runCmd(), \"cyan\"],\n [\"dev\", \"green\"],\n ],\n \" \",\n );\n Logger.parse([[\"Open http://localhost:3000\", \"cyan\"]]);\n\n console.log(\"\");\n\n Logger.parse([[\"Have any questions\", \"white\"]]);\n // Logger.parse([\n // [\"Join our Discord server -\", \"white\"],\n // [\"https://discord.gg/hsG2A8PuGb\", \"yellow\"],\n // ]);\n Logger.parse([\n [\"Checkout our other projects -\", \"white\"],\n [\"https://toneflix.net/open-source\", \"yellow\"],\n ]);\n }\n\n async cleanup() {\n const pkgPath = join(this.location!, \"package.json\");\n const pkg = await readFile(pkgPath!, \"utf-8\").then(JSON.parse);\n\n delete pkg.packageManager;\n pkg.name = Str.slugify(this.appName ?? basename(this.location!).replace(\".\", \"\"), \"-\");\n pkg.scripts = packageJsonScript;\n if (this.description) {\n pkg.description = this.description;\n }\n\n await Promise.allSettled([\n writeFile(pkgPath, JSON.stringify(pkg, null, 2)),\n this.removeLockFile(),\n rm(join(this.location!, \"pnpm-workspace.yaml\"), { force: true }),\n rm(join(this.location!, \"README.md\"), { force: true }),\n rm(join(this.location!, \".github\"), { force: true, recursive: true }),\n ]);\n }\n\n async removeLockFile() {\n if (!this.skipInstallation) {\n return;\n }\n\n await Promise.allSettled([\n unlink(join(this.location!, \"package-lock.json\")),\n unlink(join(this.location!, \"yarn.lock\")),\n unlink(join(this.location!, \"pnpm-lock.yaml\")),\n ]);\n }\n\n async getBanner() {\n return await readFile(join(process.cwd(), \"./logo.txt\"), \"utf-8\");\n }\n\n async copyExampleEnv() {\n const envPath = join(this.location!, \".env\");\n const exampleEnvPath = join(this.location!, \".env.example\");\n\n if (existsSync(exampleEnvPath)) {\n await copyFile(exampleEnvPath, envPath);\n }\n }\n}\n","import { readdir, rename } from \"node:fs/promises\";\n\nimport path from \"node:path\";\nimport { rm } from \"node:fs/promises\";\n\n/**\n * Removes all files in dirPath except the one specified by keepFileName\n *\n * @param dirPath\n * @param keepFileName\n */\nexport async function cleanDirectoryExcept(dirPath: string, keepFileName: string) {\n const files = await readdir(dirPath);\n\n for (const file of files) {\n if (file === keepFileName) continue;\n\n const fullPath = path.join(dirPath, file);\n\n await rm(fullPath, { recursive: true, force: true });\n }\n}\n\n/**\n * Moves all files from dirPath to parent directory and removes dirPath\n *\n * @param dirPath\n * @param parent\n */\nexport async function hoistDirectoryContents(parent: string, dirPath: string) {\n const source = path.isAbsolute(dirPath) ? dirPath : path.join(process.cwd(), dirPath);\n\n const targetParent = path.isAbsolute(parent) ? parent : path.join(process.cwd(), parent);\n\n if (!source.startsWith(targetParent)) {\n throw new Error(\"Source must be inside the parent directory\");\n }\n\n const entries = await readdir(source);\n\n for (const entry of entries) {\n const from = path.join(source, entry);\n const to = path.join(targetParent, entry);\n\n await rename(from, to);\n }\n\n await rm(source, { recursive: true });\n}\n","import { Command } from \"@h3ravel/musket\";\nimport { altLogo } from \"src/logo\";\nimport inquirer from \"inquirer\";\nimport { AbortPromptError, ExitPromptError } from \"@inquirer/core\";\nimport { basename, join } from \"node:path\";\nimport { templates } from \"src/templates\";\nimport { Str } from \"@h3ravel/support\";\nimport Actions from \"src/actions\";\nimport ora from \"ora\";\nimport { Logger } from \"@h3ravel/shared\";\nimport { cleanDirectoryExcept, hoistDirectoryContents } from \"src/utils\";\n\nexport class CreateArcstackCommand extends Command {\n protected signature = `create-arcstack\n {location?: The location where this project should be created relative to the current dir.}\n {--n|name?: The name of your project.}\n {--i|install: Install node_modules right away}\n {--t|token?: Kit repo authentication token.}\n {--d|desc?: Project Description.}\n {--k|kit?: Starter template kit.}\n {--p|pre: Download prerelease version if available.}\n {--o|overwrite: Overwrite the installation directory if it is not empty.}\n `;\n protected description = \"Display a personalized greeting.\";\n\n async handle() {\n const options = this.options();\n const pathName = this.argument(\"location\");\n\n console.log(altLogo, `font-family: monospace`);\n\n let { template } = await inquirer\n .prompt([\n {\n type: \"list\",\n name: \"template\",\n message: \"Choose starter template kit:\",\n choices: <never>templates.map((e) => ({\n name: e.name,\n value: e.alias,\n disabled: !e.source ? \"(Unavailable at this time)\" : false,\n })),\n default: \"full\",\n when: () => !options.kit,\n },\n ])\n .catch((err) => {\n if (err instanceof AbortPromptError || err instanceof ExitPromptError) {\n this.info(\"Thanks for trying out our starter kit.\");\n process.exit(0);\n }\n return err;\n });\n\n let { appName, description } = await inquirer\n .prompt([\n {\n type: \"input\",\n name: \"appName\",\n message: \"What is the name of your project:\",\n default: `arcstack-${template}`,\n when: () => !options.name,\n },\n {\n type: \"input\",\n name: \"description\",\n message: \"Project Description:\",\n default: `Simple ${Str.of(template).ucfirst()}.js project created with Arcstack.`,\n when: () => !options.desc,\n },\n ])\n .catch((err) => {\n if (err instanceof AbortPromptError || err instanceof ExitPromptError) {\n this.info(\"Thanks for trying out our starter kit.\");\n process.exit(0);\n }\n return err;\n });\n\n let { location } = await inquirer\n .prompt([\n {\n type: \"input\",\n name: \"location\",\n message: \"Installation location relative to the current dir:\",\n default: Str.slugify(options.name ?? appName ?? basename(process.cwd()), \"-\"),\n when: () => !pathName,\n },\n ])\n .catch((err) => {\n if (err instanceof AbortPromptError || err instanceof ExitPromptError) {\n this.info(\"Thanks for trying out our starter kit.\");\n process.exit(0);\n }\n return err;\n });\n\n /**\n * Find selected template kit\n */\n const kit = templates.find((e) => e.alias === template)!;\n\n let { install, token, pre } = await inquirer\n .prompt([\n {\n type: \"confirm\",\n name: \"pre\",\n message: `An alpha version of the ${kit.name.replace(/\\s*kit$/i, \"\").trim()} kit is available. Would you like to use it instead?`,\n default: false,\n when: () => kit.prereleaseSource && !options.pre,\n } as never,\n {\n type: \"input\",\n name: \"token\",\n message: \"Authentication token:\",\n when: () => options.kit && !options.token,\n },\n {\n type: \"confirm\",\n name: \"install\",\n message: \"Would you want to install node_modules right away:\",\n default: true,\n when: () => !options.install,\n },\n ])\n .catch((err) => {\n if (err instanceof AbortPromptError || err instanceof ExitPromptError) {\n this.info(\"Thanks for trying out our starter kit.\");\n process.exit(0);\n }\n return err;\n });\n\n pre = options.pre ?? pre;\n token = options.token ?? token;\n appName = options.name ?? appName;\n install = options.install ?? install;\n template = options.kit ?? template;\n location = pathName ?? location;\n description = options.description ?? description;\n\n /**\n * Validate selected kit\n */\n if (kit && !kit.source) {\n this.error(`ERROR: The ${kit.name} kit is not currently available`);\n process.exit(1);\n }\n\n const source: string = pre && kit.prereleaseSource ? kit.prereleaseSource! : kit.source;\n const actions = new Actions(join(process.cwd(), location), appName, description);\n const spinner = ora(`Loading Template...`).start();\n\n const result = await actions.download(source, install, token, options.overwrite);\n\n if (result.dir && kit.alias) {\n await cleanDirectoryExcept(result.dir, kit.alias);\n await hoistDirectoryContents(result.dir, join(result.dir, kit.alias));\n }\n\n spinner.info(Logger.parse([[\"Cleaning Up...\", \"green\"]], \"\", false)).start();\n await actions.cleanup();\n\n spinner.info(Logger.parse([[\"Initializing Project...\", \"green\"]], \"\", false)).start();\n await actions.copyExampleEnv();\n\n spinner.succeed(Logger.parse([[\"Project initialization complete!\", \"green\"]], \"\", false));\n\n await actions.complete(install);\n }\n}\n","#!/usr/bin/env node\n\nimport { CreateArcstackCommand } from \"./Commands/CreateArcstackCommand\";\nimport { Kernel } from \"@h3ravel/musket\";\n\nclass Application {}\n\nKernel.init(new Application(), {\n rootCommand: CreateArcstackCommand,\n});\n"],"mappings":";;;;;;;;;;;;;;AAAA,MAAa,UAAU,OAAO,GAAG;;;;;;;;;;;;;;ACYjC,MAAaA,YAMP,CACJ;CACE,MAAM;CACN,OAAO;CACP,MAAM;CACN,QAAQ;CACT,EACD;CAC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BAAkB,QAAQ,CAAC,EAAE,IAAI,MAAM,CAAC,CAAC,OAAO;AAC5E,QAAM,QAAQ,SAAS;AAEvB,UAAQ,KAAK,OAAO,MAAM,CAAC,CAAC,2BAA2B,QAAQ,CAAC,EAAE,IAAI,MAAM,CAAC,CAAC,OAAO;AACrF,QAAM,QAAQ,gBAAgB;AAE9B,UAAQ,QAAQ,OAAO,MAAM,CAAC,CAAC,oCAAoC,QAAQ,CAAC,EAAE,IAAI,MAAM,CAAC;AAEzF,QAAM,QAAQ,SAAS,QAAQ;;;;;;ACnKnC,IAAM,cAAN,MAAkB;AAElB,OAAO,KAAK,IAAI,aAAa,EAAE,EAC7B,aAAa,uBACd,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-arcstack",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Scaffold new H3.js or Express.js applications using Toneflix's arcstack templates and starter kits",
|
|
6
|
+
"main": "build/index.js",
|
|
7
|
+
"private": false,
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"create-arcstack": "bin/run.js"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./bin/run.js"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"toneflix",
|
|
19
|
+
"create-arcstack",
|
|
20
|
+
"h3",
|
|
21
|
+
"express",
|
|
22
|
+
"scaffold",
|
|
23
|
+
"template",
|
|
24
|
+
"starter kit",
|
|
25
|
+
"cli"
|
|
26
|
+
],
|
|
27
|
+
"files": [
|
|
28
|
+
"bin",
|
|
29
|
+
"bin/run.d.ts",
|
|
30
|
+
"bin/run.js"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@antfu/install-pkg": "1.1.0",
|
|
34
|
+
"@h3ravel/collect.js": "^5.3.4",
|
|
35
|
+
"@h3ravel/musket": "^0.10.1",
|
|
36
|
+
"@h3ravel/shared": "^0.28.4",
|
|
37
|
+
"@h3ravel/support": "^0.16.1",
|
|
38
|
+
"@inquirer/core": "^10.2.2",
|
|
39
|
+
"giget": "^2.0.0",
|
|
40
|
+
"inquirer": "^12.9.6",
|
|
41
|
+
"ora": "^9.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@changesets/cli": "^2.29.5",
|
|
45
|
+
"eslint": "^9.32.0",
|
|
46
|
+
"ts-node": "^10.9.2",
|
|
47
|
+
"tsdown": "^0.15.4",
|
|
48
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
49
|
+
"vitest": "^3.2.4"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"quick:test": "pnpm vitest",
|
|
53
|
+
"test": "pnpm run quick:test",
|
|
54
|
+
"runner": "tsx --experimental-specifier-resolution=node src/run.ts",
|
|
55
|
+
"build": "tsdown",
|
|
56
|
+
"version": "pnpm run build",
|
|
57
|
+
"unlink": "npm unlink -g create-arcstack",
|
|
58
|
+
"release": "pnpm build && pnpm changeset version && pnpm changeset publish",
|
|
59
|
+
"publish-it": "pnpm build && pnpm publish --tag latest"
|
|
60
|
+
}
|
|
61
|
+
}
|