create-asajs 4.1.14
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/dist/index.js +107 -0
- package/package.json +35 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const os_1 = __importDefault(require("os"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
async function setup({ path, name, npmName, useTypeScript, allowCompiler, autoInstall, installToPreview, nightly, }) {
|
|
12
|
+
await Promise.all([
|
|
13
|
+
promises_1.default.mkdir(path_1.default.join(path, "src"), { recursive: true }),
|
|
14
|
+
promises_1.default.mkdir(path_1.default.join(path, "build"), { recursive: true }),
|
|
15
|
+
]);
|
|
16
|
+
const mapping = {
|
|
17
|
+
projectname: name,
|
|
18
|
+
allowCompiler,
|
|
19
|
+
autoInstall,
|
|
20
|
+
installToPreview,
|
|
21
|
+
};
|
|
22
|
+
let pkg = "asajs";
|
|
23
|
+
if (nightly)
|
|
24
|
+
pkg += "@indev";
|
|
25
|
+
await promises_1.default.writeFile(path_1.default.join(path, "package.json"), JSON.stringify({
|
|
26
|
+
name: npmName,
|
|
27
|
+
description: "Create your Minecraft JSON-UI resource packs using JavaScript.",
|
|
28
|
+
type: "module",
|
|
29
|
+
main: "src/index.js",
|
|
30
|
+
}, null, 4));
|
|
31
|
+
(0, child_process_1.spawnSync)("npm.cmd", ["install", pkg], {
|
|
32
|
+
cwd: path,
|
|
33
|
+
stdio: "inherit",
|
|
34
|
+
shell: true,
|
|
35
|
+
});
|
|
36
|
+
await Promise.all([
|
|
37
|
+
promises_1.default.copyFile(path_1.default.join(__dirname, "../resources/code.js"), path_1.default.join(path, "src", useTypeScript ? "index.ts" : "index.js")),
|
|
38
|
+
promises_1.default.copyFile(path_1.default.join(__dirname, "../resources/pack_icon.png"), path_1.default.join(path, "build/pack_icon.png")),
|
|
39
|
+
promises_1.default.writeFile(path_1.default.join(path, "asajs.config.js"), await promises_1.default.readFile(path_1.default.join(__dirname, "../resources/config.txt"), "utf-8").then(v => {
|
|
40
|
+
return v.replace(/{\w+}/g, v => {
|
|
41
|
+
return `${mapping[v.slice(1, -1)] || v}`;
|
|
42
|
+
});
|
|
43
|
+
}), "utf-8"),
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
async function run() {
|
|
47
|
+
const { path, name } = (await (0, prompts_1.input)({
|
|
48
|
+
message: "What is your project name?",
|
|
49
|
+
default: "my-project",
|
|
50
|
+
}).then(async (v) => {
|
|
51
|
+
const name = v
|
|
52
|
+
.match(/[a-zA-Z0-9]+/g)
|
|
53
|
+
?.join("-")
|
|
54
|
+
.toLowerCase();
|
|
55
|
+
if (!name) {
|
|
56
|
+
console.error("Invalid project name");
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
if (await promises_1.default.stat(name)) {
|
|
61
|
+
console.error("Project name already exists");
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return {
|
|
67
|
+
path: name,
|
|
68
|
+
name: v,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
const useTypeScript = await (0, prompts_1.confirm)({
|
|
73
|
+
message: "Do you want to use TypeScript?",
|
|
74
|
+
default: true,
|
|
75
|
+
});
|
|
76
|
+
const nightly = await (0, prompts_1.confirm)({
|
|
77
|
+
message: "Do you want to use nightly version?",
|
|
78
|
+
default: false,
|
|
79
|
+
});
|
|
80
|
+
const allowCompiler = await (0, prompts_1.confirm)({
|
|
81
|
+
message: "Do you want to allow the compiler to build the project into output files?",
|
|
82
|
+
default: true,
|
|
83
|
+
});
|
|
84
|
+
const autoInstall = allowCompiler && ["win32"].includes(os_1.default.platform())
|
|
85
|
+
? await (0, prompts_1.confirm)({
|
|
86
|
+
message: "Do you want the pack to be automatically installed into the game after it finishes building?",
|
|
87
|
+
default: true,
|
|
88
|
+
})
|
|
89
|
+
: false;
|
|
90
|
+
const installToPreview = autoInstall
|
|
91
|
+
? await (0, prompts_1.confirm)({
|
|
92
|
+
message: "Do you want the pack to be installed into the Minecraft Preview version?",
|
|
93
|
+
default: false,
|
|
94
|
+
})
|
|
95
|
+
: false;
|
|
96
|
+
await setup({
|
|
97
|
+
path: path_1.default.resolve(process.cwd(), path),
|
|
98
|
+
name,
|
|
99
|
+
npmName: path,
|
|
100
|
+
useTypeScript,
|
|
101
|
+
allowCompiler,
|
|
102
|
+
autoInstall,
|
|
103
|
+
installToPreview,
|
|
104
|
+
nightly,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
run();
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-asajs",
|
|
3
|
+
"version": "4.1.14",
|
|
4
|
+
"description": "Create an AsaJS projects",
|
|
5
|
+
"bin": {
|
|
6
|
+
"create-asajs": "./dist/index.js"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"Minecraft",
|
|
10
|
+
"JSON-UI"
|
|
11
|
+
],
|
|
12
|
+
"license": "GPL-3.0-only",
|
|
13
|
+
"author": "Asaki Yuki",
|
|
14
|
+
"type": "commonjs",
|
|
15
|
+
"main": "index.js",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@inquirer/prompts": "^8.3.0",
|
|
18
|
+
"@types/node": "^25.3.3"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"dev": "tsc -w",
|
|
23
|
+
"test": "bun src/index.ts"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"resource"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"typescript": "^5.9.3"
|
|
34
|
+
}
|
|
35
|
+
}
|