create-korlix 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 +33 -0
- package/bin/create-korlix.js +135 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# create-korlix
|
|
2
|
+
|
|
3
|
+
Create a new Korlix app.
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
|
|
7
|
+
npm create korlix@latest my-app
|
|
8
|
+
|
|
9
|
+
Or without a folder name:
|
|
10
|
+
|
|
11
|
+
npm create korlix@latest
|
|
12
|
+
|
|
13
|
+
If no folder name is provided, Korlix asks for the project name.
|
|
14
|
+
|
|
15
|
+
Korlix apps are created in SPA mode by default.
|
|
16
|
+
|
|
17
|
+
Publish:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
cd npm/create-korlix
|
|
21
|
+
npm login
|
|
22
|
+
npm run publish:dry
|
|
23
|
+
npm run publish:public
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If your npm account has two-factor authentication enabled, pass the current
|
|
27
|
+
6-digit authenticator code:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm run publish:public -- --otp=123456
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Publish `korlix` first, then publish `create-korlix`.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const readline = require("readline");
|
|
4
|
+
const { spawnSync } = require("child_process");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
|
|
8
|
+
function askProjectName(defaultValue = "my-korlix-app") {
|
|
9
|
+
const rl = readline.createInterface({
|
|
10
|
+
input: process.stdin,
|
|
11
|
+
output: process.stdout
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
rl.question(`Project name (${defaultValue}): `, (answer) => {
|
|
16
|
+
rl.close();
|
|
17
|
+
resolve(answer.trim() || defaultValue);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function run(command, args, cwd = process.cwd()) {
|
|
23
|
+
const result = spawnSync(command, args, {
|
|
24
|
+
cwd,
|
|
25
|
+
stdio: "inherit",
|
|
26
|
+
shell: process.platform === "win32"
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (result.status !== 0) {
|
|
30
|
+
process.exit(result.status ?? 1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function korlixCommand() {
|
|
35
|
+
const localCli = path.resolve(__dirname, "../../korlix/bin/korlix.js");
|
|
36
|
+
if (fs.existsSync(localCli)) {
|
|
37
|
+
return {
|
|
38
|
+
command: process.execPath,
|
|
39
|
+
args: [localCli]
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
return {
|
|
45
|
+
command: process.execPath,
|
|
46
|
+
args: [require.resolve("korlix/bin/korlix.js")]
|
|
47
|
+
};
|
|
48
|
+
} catch {
|
|
49
|
+
return { command: "korlix", args: [] };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function korlixPackageSpec() {
|
|
54
|
+
if (process.env.KORLIX_PACKAGE) {
|
|
55
|
+
return process.env.KORLIX_PACKAGE;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const localPackage = path.resolve(__dirname, "../../korlix");
|
|
59
|
+
if (fs.existsSync(path.join(localPackage, "package.json"))) {
|
|
60
|
+
return `file:${localPackage}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return "^0.1.0";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function writeJson(filePath, data) {
|
|
67
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + "\n");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function main() {
|
|
71
|
+
console.log("");
|
|
72
|
+
console.log("Korlix - frontend-first language");
|
|
73
|
+
console.log("");
|
|
74
|
+
|
|
75
|
+
let projectName = process.argv[2];
|
|
76
|
+
|
|
77
|
+
if (!projectName) {
|
|
78
|
+
projectName = await askProjectName();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const projectPath = path.resolve(process.cwd(), projectName);
|
|
82
|
+
|
|
83
|
+
if (fs.existsSync(projectPath)) {
|
|
84
|
+
console.error("");
|
|
85
|
+
console.error(`Error: folder already exists: ${projectName}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
console.log(`Creating Korlix app: ${projectName}`);
|
|
90
|
+
console.log("");
|
|
91
|
+
|
|
92
|
+
const korlix = korlixCommand();
|
|
93
|
+
run(korlix.command, [...korlix.args, "new", projectName]);
|
|
94
|
+
|
|
95
|
+
const configPath = path.join(projectPath, "korlix.config.json");
|
|
96
|
+
|
|
97
|
+
if (fs.existsSync(configPath)) {
|
|
98
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
99
|
+
config.mode = "spa";
|
|
100
|
+
writeJson(configPath, config);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const packagePath = path.join(projectPath, "package.json");
|
|
104
|
+
|
|
105
|
+
if (fs.existsSync(packagePath)) {
|
|
106
|
+
const pkg = JSON.parse(fs.readFileSync(packagePath, "utf8"));
|
|
107
|
+
|
|
108
|
+
pkg.scripts = {
|
|
109
|
+
dev: "korlix dev",
|
|
110
|
+
build: "korlix build",
|
|
111
|
+
preview: "korlix preview",
|
|
112
|
+
check: "korlix check"
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
pkg.devDependencies = {
|
|
116
|
+
...(pkg.devDependencies || {}),
|
|
117
|
+
korlix: korlixPackageSpec()
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
writeJson(packagePath, pkg);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
console.log("");
|
|
124
|
+
console.log("Korlix app created");
|
|
125
|
+
console.log("");
|
|
126
|
+
console.log("Next steps:");
|
|
127
|
+
console.log(` cd ${projectName}`);
|
|
128
|
+
console.log(" npm install");
|
|
129
|
+
console.log(" npm run dev");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
main().catch((err) => {
|
|
133
|
+
console.error(err);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-korlix",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a new Korlix app",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"korlix": "^0.1.0"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"create-korlix": "bin/create-korlix.js"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"verify": "node --check ./bin/create-korlix.js",
|
|
15
|
+
"prepack": "npm run verify",
|
|
16
|
+
"pack:dry": "npm pack --dry-run",
|
|
17
|
+
"publish:dry": "npm publish --dry-run --access public",
|
|
18
|
+
"publish:public": "npm publish --access public"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"bin",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"korlix",
|
|
32
|
+
"create-korlix",
|
|
33
|
+
"frontend",
|
|
34
|
+
"language",
|
|
35
|
+
"spa"
|
|
36
|
+
]
|
|
37
|
+
}
|