@emberkit/cli 0.1.2 â 0.2.1-alpha.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/dist/cli.js +19 -19
- package/dist/commands/build.js +9 -9
- package/dist/commands/create.js +12 -12
- package/dist/commands/dev.js +8 -8
- package/dist/commands/preview.js +8 -8
- package/dist/index.js +1 -1
- package/dist/templates/index.js +2 -2
- package/dist/templates/starter.js +9 -9
- package/dist/utils/filesystem.js +20 -20
- package/dist/utils/generator.js +8 -8
- package/package.json +8 -3
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { dev } from
|
|
2
|
-
import { build } from
|
|
3
|
-
import { preview } from
|
|
4
|
-
import { create } from
|
|
1
|
+
import { dev } from "./commands/dev.js";
|
|
2
|
+
import { build } from "./commands/build.js";
|
|
3
|
+
import { preview } from "./commands/preview.js";
|
|
4
|
+
import { create } from "./commands/create.js";
|
|
5
5
|
export async function runCLI(args) {
|
|
6
6
|
const [command, ...restArgs] = args.slice(2);
|
|
7
7
|
if (!command) {
|
|
@@ -9,27 +9,27 @@ export async function runCLI(args) {
|
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
switch (command) {
|
|
12
|
-
case
|
|
12
|
+
case "dev":
|
|
13
13
|
await dev(restArgs);
|
|
14
14
|
break;
|
|
15
|
-
case
|
|
15
|
+
case "build":
|
|
16
16
|
await build(restArgs);
|
|
17
17
|
break;
|
|
18
|
-
case
|
|
18
|
+
case "preview":
|
|
19
19
|
await preview(restArgs);
|
|
20
20
|
break;
|
|
21
|
-
case
|
|
21
|
+
case "create":
|
|
22
22
|
await handleCreate(restArgs);
|
|
23
23
|
break;
|
|
24
|
-
case
|
|
24
|
+
case "generate":
|
|
25
25
|
await runGenerate(restArgs);
|
|
26
26
|
break;
|
|
27
|
-
case
|
|
28
|
-
case
|
|
29
|
-
console.log(
|
|
27
|
+
case "--version":
|
|
28
|
+
case "-v":
|
|
29
|
+
console.log("EmberKit CLI v0.1.0");
|
|
30
30
|
break;
|
|
31
|
-
case
|
|
32
|
-
case
|
|
31
|
+
case "--help":
|
|
32
|
+
case "-h":
|
|
33
33
|
showHelp();
|
|
34
34
|
break;
|
|
35
35
|
default:
|
|
@@ -65,11 +65,11 @@ Examples:
|
|
|
65
65
|
async function handleCreate(args) {
|
|
66
66
|
const name = args[0];
|
|
67
67
|
if (!name) {
|
|
68
|
-
console.error(
|
|
69
|
-
console.error(
|
|
68
|
+
console.error("Error: Project name is required.");
|
|
69
|
+
console.error("Usage: emberkit create <project-name>");
|
|
70
70
|
process.exit(1);
|
|
71
71
|
}
|
|
72
|
-
const noInstall = args.includes(
|
|
72
|
+
const noInstall = args.includes("--no-install");
|
|
73
73
|
await create({
|
|
74
74
|
name,
|
|
75
75
|
noInstall,
|
|
@@ -78,9 +78,9 @@ async function handleCreate(args) {
|
|
|
78
78
|
async function runGenerate(args) {
|
|
79
79
|
const [type, name] = args;
|
|
80
80
|
if (!type || !name) {
|
|
81
|
-
console.error(
|
|
81
|
+
console.error("Usage: emberkit generate <type> <name>");
|
|
82
82
|
process.exit(1);
|
|
83
83
|
}
|
|
84
84
|
console.log(`đ¨ Generating ${type}: ${name}`);
|
|
85
|
-
console.log(
|
|
85
|
+
console.log("(Not yet implemented)");
|
|
86
86
|
}
|
package/dist/commands/build.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { spawn } from
|
|
2
|
-
import { platform } from
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { platform } from "os";
|
|
3
3
|
export async function build(args) {
|
|
4
|
-
console.log(
|
|
5
|
-
const isWindows = platform() ===
|
|
6
|
-
const vite = spawn(
|
|
7
|
-
stdio:
|
|
4
|
+
console.log("đ¨ Building for production...\n");
|
|
5
|
+
const isWindows = platform() === "win32";
|
|
6
|
+
const vite = spawn("vite", ["build", ...args], {
|
|
7
|
+
stdio: "inherit",
|
|
8
8
|
shell: isWindows,
|
|
9
9
|
});
|
|
10
10
|
return new Promise((resolve, reject) => {
|
|
11
|
-
vite.on(
|
|
11
|
+
vite.on("exit", (code) => {
|
|
12
12
|
if (code === 0) {
|
|
13
|
-
console.log(
|
|
13
|
+
console.log("\n⨠Build complete!");
|
|
14
14
|
resolve();
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
17
|
reject(new Error(`Build failed with code ${code}`));
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
vite.on(
|
|
20
|
+
vite.on("error", (error) => {
|
|
21
21
|
reject(error);
|
|
22
22
|
});
|
|
23
23
|
});
|
package/dist/commands/create.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from
|
|
2
|
-
import { join, resolve } from
|
|
3
|
-
import { execSync } from
|
|
4
|
-
import { starterFiles } from
|
|
5
|
-
import { getPackageManager, getInstallCommand } from
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
+
import { join, resolve } from "path";
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
import { starterFiles } from "../templates/starter.js";
|
|
5
|
+
import { getPackageManager, getInstallCommand } from "../utils/filesystem.js";
|
|
6
6
|
function formatTemplate(template, vars) {
|
|
7
7
|
let result = template;
|
|
8
8
|
for (const [key, value] of Object.entries(vars)) {
|
|
9
|
-
result = result.replace(new RegExp(`\\{\\{${key}\\}\\}`,
|
|
9
|
+
result = result.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), value);
|
|
10
10
|
}
|
|
11
11
|
return result;
|
|
12
12
|
}
|
|
13
13
|
function toKebabCase(str) {
|
|
14
14
|
return str
|
|
15
|
-
.replace(/([a-z])([A-Z])/g,
|
|
16
|
-
.replace(/[\s_]+/g,
|
|
15
|
+
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
16
|
+
.replace(/[\s_]+/g, "-")
|
|
17
17
|
.toLowerCase();
|
|
18
18
|
}
|
|
19
19
|
function getNpmPackageName(name) {
|
|
20
20
|
const kebab = toKebabCase(name);
|
|
21
|
-
return kebab.startsWith(
|
|
21
|
+
return kebab.startsWith("@") ? kebab : kebab.replace(/^emberkit-/, "");
|
|
22
22
|
}
|
|
23
23
|
export async function create(options) {
|
|
24
24
|
const { name, noInstall = false } = options;
|
|
@@ -38,11 +38,11 @@ export async function create(options) {
|
|
|
38
38
|
mkdirSync(targetDir, { recursive: true });
|
|
39
39
|
for (const [filePath, content] of Object.entries(starterFiles)) {
|
|
40
40
|
const fullPath = join(targetDir, filePath);
|
|
41
|
-
const dir = join(targetDir, filePath.split(
|
|
41
|
+
const dir = join(targetDir, filePath.split("/").slice(0, -1).join("/"));
|
|
42
42
|
if (!existsSync(dir)) {
|
|
43
43
|
mkdirSync(dir, { recursive: true });
|
|
44
44
|
}
|
|
45
|
-
writeFileSync(fullPath, formatTemplate(content, templateVars),
|
|
45
|
+
writeFileSync(fullPath, formatTemplate(content, templateVars), "utf-8");
|
|
46
46
|
}
|
|
47
47
|
console.log(` Project created successfully!\n`);
|
|
48
48
|
if (!noInstall) {
|
|
@@ -50,7 +50,7 @@ export async function create(options) {
|
|
|
50
50
|
const installCmd = getInstallCommand();
|
|
51
51
|
console.log(` Installing dependencies with ${pm}...`);
|
|
52
52
|
try {
|
|
53
|
-
execSync(installCmd, { cwd: targetDir, stdio:
|
|
53
|
+
execSync(installCmd, { cwd: targetDir, stdio: "inherit" });
|
|
54
54
|
console.log(`\n Dependencies installed!\n`);
|
|
55
55
|
}
|
|
56
56
|
catch {
|
package/dist/commands/dev.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { spawn } from
|
|
2
|
-
import { platform } from
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { platform } from "os";
|
|
3
3
|
export async function dev(args) {
|
|
4
|
-
console.log(
|
|
5
|
-
const isWindows = platform() ===
|
|
6
|
-
const vite = spawn(
|
|
7
|
-
stdio:
|
|
4
|
+
console.log("đĽ Starting EmberKit dev server...\n");
|
|
5
|
+
const isWindows = platform() === "win32";
|
|
6
|
+
const vite = spawn("vite", args, {
|
|
7
|
+
stdio: "inherit",
|
|
8
8
|
shell: isWindows,
|
|
9
9
|
});
|
|
10
10
|
return new Promise((resolve, reject) => {
|
|
11
|
-
vite.on(
|
|
11
|
+
vite.on("exit", (code) => {
|
|
12
12
|
if (code === 0) {
|
|
13
13
|
resolve();
|
|
14
14
|
}
|
|
@@ -16,7 +16,7 @@ export async function dev(args) {
|
|
|
16
16
|
reject(new Error(`Vite exited with code ${code}`));
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
vite.on(
|
|
19
|
+
vite.on("error", (error) => {
|
|
20
20
|
reject(error);
|
|
21
21
|
});
|
|
22
22
|
});
|
package/dist/commands/preview.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { spawn } from
|
|
2
|
-
import { platform } from
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { platform } from "os";
|
|
3
3
|
export async function preview(args) {
|
|
4
|
-
console.log(
|
|
5
|
-
const isWindows = platform() ===
|
|
6
|
-
const vite = spawn(
|
|
7
|
-
stdio:
|
|
4
|
+
console.log("đ Previewing production build...\n");
|
|
5
|
+
const isWindows = platform() === "win32";
|
|
6
|
+
const vite = spawn("vite", ["preview", ...args], {
|
|
7
|
+
stdio: "inherit",
|
|
8
8
|
shell: isWindows,
|
|
9
9
|
});
|
|
10
10
|
return new Promise((resolve, reject) => {
|
|
11
|
-
vite.on(
|
|
11
|
+
vite.on("exit", (code) => {
|
|
12
12
|
if (code === 0) {
|
|
13
13
|
resolve();
|
|
14
14
|
}
|
|
@@ -16,7 +16,7 @@ export async function preview(args) {
|
|
|
16
16
|
reject(new Error(`Preview exited with code ${code}`));
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
vite.on(
|
|
19
|
+
vite.on("error", (error) => {
|
|
20
20
|
reject(error);
|
|
21
21
|
});
|
|
22
22
|
});
|
package/dist/index.js
CHANGED
package/dist/templates/index.js
CHANGED
|
@@ -126,7 +126,7 @@ export function formatTemplate(template, params) {
|
|
|
126
126
|
}
|
|
127
127
|
export function toKebabCase(str) {
|
|
128
128
|
return str
|
|
129
|
-
.replace(/([a-z])([A-Z])/g,
|
|
130
|
-
.replace(/[\s_]+/g,
|
|
129
|
+
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
130
|
+
.replace(/[\s_]+/g, "-")
|
|
131
131
|
.toLowerCase();
|
|
132
132
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const starterFiles = {
|
|
2
|
-
|
|
2
|
+
"package.json": `{
|
|
3
3
|
"name": "{{name}}",
|
|
4
4
|
"version": "0.1.0",
|
|
5
5
|
"private": true,
|
|
@@ -20,7 +20,7 @@ export const starterFiles = {
|
|
|
20
20
|
"vite": "^6.0.0"
|
|
21
21
|
}
|
|
22
22
|
}`,
|
|
23
|
-
|
|
23
|
+
"tsconfig.json": `{
|
|
24
24
|
"compilerOptions": {
|
|
25
25
|
"target": "ES2022",
|
|
26
26
|
"module": "ESNext",
|
|
@@ -42,7 +42,7 @@ export const starterFiles = {
|
|
|
42
42
|
"include": ["src"],
|
|
43
43
|
"exclude": ["node_modules", "dist"]
|
|
44
44
|
}`,
|
|
45
|
-
|
|
45
|
+
"emberkit.config.ts": `import { defineConfig } from '@emberkit/core';
|
|
46
46
|
|
|
47
47
|
export default defineConfig({
|
|
48
48
|
mode: 'spa',
|
|
@@ -51,7 +51,7 @@ export default defineConfig({
|
|
|
51
51
|
target: 'esnext',
|
|
52
52
|
},
|
|
53
53
|
});`,
|
|
54
|
-
|
|
54
|
+
"vite.config.ts": `import { defineConfig } from 'vite';
|
|
55
55
|
import { emberkitVitePlugin } from '@emberkit/core/vite-plugin';
|
|
56
56
|
|
|
57
57
|
export default defineConfig({
|
|
@@ -64,7 +64,7 @@ export default defineConfig({
|
|
|
64
64
|
jsxImportSource: '@emberkit/core',
|
|
65
65
|
},
|
|
66
66
|
});`,
|
|
67
|
-
|
|
67
|
+
"index.html": `<!DOCTYPE html>
|
|
68
68
|
<html lang="en">
|
|
69
69
|
<head>
|
|
70
70
|
<meta charset="UTF-8">
|
|
@@ -76,7 +76,7 @@ export default defineConfig({
|
|
|
76
76
|
<script type="module" src="/src/index.tsx"></script>
|
|
77
77
|
</body>
|
|
78
78
|
</html>`,
|
|
79
|
-
|
|
79
|
+
"src/index.tsx": `import { render } from '@emberkit/core';
|
|
80
80
|
import App from './routes/_layout';
|
|
81
81
|
|
|
82
82
|
const root = document.getElementById('app');
|
|
@@ -84,7 +84,7 @@ const root = document.getElementById('app');
|
|
|
84
84
|
if (root) {
|
|
85
85
|
render(App, root);
|
|
86
86
|
}`,
|
|
87
|
-
|
|
87
|
+
"src/routes/_layout.tsx": `import type { RouteComponent } from '@emberkit/core';
|
|
88
88
|
import { Head } from '@emberkit/core';
|
|
89
89
|
|
|
90
90
|
const Layout: RouteComponent = ({ children }) => {
|
|
@@ -111,7 +111,7 @@ const Layout: RouteComponent = ({ children }) => {
|
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
export default Layout;`,
|
|
114
|
-
|
|
114
|
+
"src/routes/index.tsx": `import type { RouteComponent } from '@emberkit/core';
|
|
115
115
|
|
|
116
116
|
const HomePage: RouteComponent = () => {
|
|
117
117
|
return (
|
|
@@ -158,7 +158,7 @@ const HomePage: RouteComponent = () => {
|
|
|
158
158
|
};
|
|
159
159
|
|
|
160
160
|
export default HomePage;`,
|
|
161
|
-
|
|
161
|
+
"src/routes/about.tsx": `import type { RouteComponent } from '@emberkit/core';
|
|
162
162
|
import { Head } from '@emberkit/core';
|
|
163
163
|
|
|
164
164
|
const AboutPage: RouteComponent = () => {
|
package/dist/utils/filesystem.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
export { generate, toPascalCase, toKebabCase } from
|
|
1
|
+
export { generate, toPascalCase, toKebabCase } from "./generator.js";
|
|
2
2
|
export function ensureDirSync(dirPath) {
|
|
3
|
-
const { mkdirSync, existsSync } = require(
|
|
3
|
+
const { mkdirSync, existsSync } = require("fs");
|
|
4
4
|
if (!existsSync(dirPath)) {
|
|
5
5
|
mkdirSync(dirPath, { recursive: true });
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
export function readFileSync(filePath) {
|
|
9
|
-
const { readFileSync } = require(
|
|
10
|
-
return readFileSync(filePath,
|
|
9
|
+
const { readFileSync } = require("fs");
|
|
10
|
+
return readFileSync(filePath, "utf-8");
|
|
11
11
|
}
|
|
12
12
|
export function writeFileSync(filePath, content, options) {
|
|
13
|
-
const fs = require(
|
|
14
|
-
const dir = require(
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const dir = require("path").dirname(filePath);
|
|
15
15
|
ensureDirSync(dir);
|
|
16
|
-
fs.writeFileSync(filePath, content, options ?? { encoding:
|
|
16
|
+
fs.writeFileSync(filePath, content, options ?? { encoding: "utf-8" });
|
|
17
17
|
}
|
|
18
18
|
export function fileExists(filePath) {
|
|
19
|
-
const { existsSync } = require(
|
|
19
|
+
const { existsSync } = require("fs");
|
|
20
20
|
return existsSync(filePath);
|
|
21
21
|
}
|
|
22
22
|
export function resolvePath(...segments) {
|
|
23
|
-
return require(
|
|
23
|
+
return require("path").resolve(...segments);
|
|
24
24
|
}
|
|
25
25
|
export function getPackageManager() {
|
|
26
|
-
const userAgent = process.env.npm_config_user_agent ??
|
|
27
|
-
if (userAgent.startsWith(
|
|
28
|
-
return
|
|
29
|
-
if (userAgent.startsWith(
|
|
30
|
-
return
|
|
31
|
-
return
|
|
26
|
+
const userAgent = process.env.npm_config_user_agent ?? "";
|
|
27
|
+
if (userAgent.startsWith("pnpm"))
|
|
28
|
+
return "pnpm";
|
|
29
|
+
if (userAgent.startsWith("yarn"))
|
|
30
|
+
return "yarn";
|
|
31
|
+
return "npm";
|
|
32
32
|
}
|
|
33
33
|
export function getInstallCommand() {
|
|
34
34
|
const pm = getPackageManager();
|
|
35
35
|
switch (pm) {
|
|
36
|
-
case
|
|
37
|
-
return
|
|
38
|
-
case
|
|
39
|
-
return
|
|
36
|
+
case "pnpm":
|
|
37
|
+
return "pnpm install";
|
|
38
|
+
case "yarn":
|
|
39
|
+
return "yarn";
|
|
40
40
|
default:
|
|
41
|
-
return
|
|
41
|
+
return "npm install";
|
|
42
42
|
}
|
|
43
43
|
}
|
package/dist/utils/generator.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from
|
|
2
|
-
import { dirname, join } from
|
|
3
|
-
import { getTemplate, formatTemplate, toKebabCase } from
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
import { getTemplate, formatTemplate, toKebabCase, } from "../templates/index.js";
|
|
4
4
|
export async function generate(options) {
|
|
5
5
|
const { name, path, template, params = {} } = options;
|
|
6
6
|
const fullPath = join(process.cwd(), path);
|
|
@@ -23,7 +23,7 @@ export async function generate(options) {
|
|
|
23
23
|
error: `File already exists: ${fullPath}`,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
writeFileSync(fullPath, content,
|
|
26
|
+
writeFileSync(fullPath, content, "utf-8");
|
|
27
27
|
return {
|
|
28
28
|
success: true,
|
|
29
29
|
path: fullPath,
|
|
@@ -34,14 +34,14 @@ export async function generate(options) {
|
|
|
34
34
|
return {
|
|
35
35
|
success: false,
|
|
36
36
|
path: fullPath,
|
|
37
|
-
error: err instanceof Error ? err.message :
|
|
37
|
+
error: err instanceof Error ? err.message : "Unknown error",
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
export async function initProject(options) {
|
|
42
|
-
const { template =
|
|
42
|
+
const { template = "basic", targetDir = process.cwd(), name } = options;
|
|
43
43
|
console.log(`Initializing EmberKit project with ${template} template...`);
|
|
44
|
-
const projectName = name ??
|
|
44
|
+
const projectName = name ?? "emberkit-app";
|
|
45
45
|
console.log(`Project: ${projectName}`);
|
|
46
46
|
console.log(`Location: ${targetDir}`);
|
|
47
47
|
}
|
|
@@ -49,6 +49,6 @@ function toPascalCase(str) {
|
|
|
49
49
|
return str
|
|
50
50
|
.split(/[-_\s]+/)
|
|
51
51
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
52
|
-
.join(
|
|
52
|
+
.join("");
|
|
53
53
|
}
|
|
54
54
|
export { toPascalCase, toKebabCase };
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emberkit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.2.1-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"private": false,
|
|
5
6
|
"description": "CLI tool for EmberKit projects",
|
|
6
7
|
"license": "Apache-2.0",
|
|
7
8
|
"repository": {
|
|
@@ -22,6 +23,9 @@
|
|
|
22
23
|
},
|
|
23
24
|
"main": "./dist/index.js",
|
|
24
25
|
"types": "./dist/index.d.ts",
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
25
29
|
"files": [
|
|
26
30
|
"dist",
|
|
27
31
|
"bin"
|
|
@@ -41,7 +45,8 @@
|
|
|
41
45
|
},
|
|
42
46
|
"scripts": {
|
|
43
47
|
"build": "tsc",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
48
|
+
"lint": "eslint src --ext .ts",
|
|
49
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
50
|
+
"typecheck": "tsc --noEmit"
|
|
46
51
|
}
|
|
47
52
|
}
|