create-omnify 0.0.1
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/index.mjs +103 -0
- package/package.json +12 -0
package/index.mjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execSync, spawn } from "child_process";
|
|
4
|
+
import { existsSync, mkdirSync, rmSync } from "fs";
|
|
5
|
+
import { resolve, basename } from "path";
|
|
6
|
+
|
|
7
|
+
const REPO = "git@github.com:omnify-jp/boilerplate.git";
|
|
8
|
+
|
|
9
|
+
// ── Colors ──────────────────────────────────────────────────
|
|
10
|
+
const cyan = (s) => `\x1b[36m${s}\x1b[0m`;
|
|
11
|
+
const green = (s) => `\x1b[32m${s}\x1b[0m`;
|
|
12
|
+
const yellow = (s) => `\x1b[33m${s}\x1b[0m`;
|
|
13
|
+
const red = (s) => `\x1b[31m${s}\x1b[0m`;
|
|
14
|
+
const bold = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
15
|
+
|
|
16
|
+
function log(msg) {
|
|
17
|
+
console.log(`${cyan("[omnify]")} ${msg}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function run(cmd, opts = {}) {
|
|
21
|
+
return execSync(cmd, { encoding: "utf8", stdio: "inherit", ...opts });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function runQuiet(cmd, opts = {}) {
|
|
25
|
+
return execSync(cmd, { encoding: "utf8", ...opts }).trim();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ── Parse args ──────────────────────────────────────────────
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
const projectName = args[0];
|
|
31
|
+
|
|
32
|
+
if (!projectName) {
|
|
33
|
+
console.log(`
|
|
34
|
+
${bold("Usage:")}
|
|
35
|
+
${yellow("pnpm create omnify")} ${cyan("<project-name>")}
|
|
36
|
+
|
|
37
|
+
${bold("Example:")}
|
|
38
|
+
${yellow("pnpm create omnify my-service")}
|
|
39
|
+
`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const projectDir = resolve(process.cwd(), projectName);
|
|
44
|
+
|
|
45
|
+
if (existsSync(projectDir)) {
|
|
46
|
+
console.error(red(` ✗ Directory "${projectName}" already exists.`));
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ── Get latest tag ──────────────────────────────────────────
|
|
51
|
+
log("Fetching latest version...");
|
|
52
|
+
|
|
53
|
+
let latestTag;
|
|
54
|
+
try {
|
|
55
|
+
const tags = runQuiet(`git ls-remote --tags --sort=-v:refname ${REPO}`, {
|
|
56
|
+
stdio: "pipe",
|
|
57
|
+
});
|
|
58
|
+
const match = tags.match(/refs\/tags\/(v[\d.]+)/);
|
|
59
|
+
latestTag = match ? match[1] : null;
|
|
60
|
+
} catch {
|
|
61
|
+
latestTag = null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const ref = latestTag || "main";
|
|
65
|
+
log(`Using ${green(ref)}`);
|
|
66
|
+
|
|
67
|
+
// ── Clone ───────────────────────────────────────────────────
|
|
68
|
+
log(`Creating ${cyan(projectName)}...`);
|
|
69
|
+
run(`git clone --branch ${ref} --depth 1 ${REPO} ${projectDir}`);
|
|
70
|
+
|
|
71
|
+
// Clean git history — fresh start
|
|
72
|
+
rmSync(resolve(projectDir, ".git"), { recursive: true, force: true });
|
|
73
|
+
|
|
74
|
+
// ── Install ─────────────────────────────────────────────────
|
|
75
|
+
log("Running composer install...");
|
|
76
|
+
run("composer install --no-interaction --no-scripts", { cwd: projectDir });
|
|
77
|
+
run("composer run post-autoload-dump --no-interaction", { cwd: projectDir });
|
|
78
|
+
|
|
79
|
+
log("Running pnpm install...");
|
|
80
|
+
run("pnpm install", { cwd: projectDir });
|
|
81
|
+
|
|
82
|
+
// ── Init git ────────────────────────────────────────────────
|
|
83
|
+
log("Initializing git...");
|
|
84
|
+
run("git init", { cwd: projectDir });
|
|
85
|
+
run("git add -A", { cwd: projectDir });
|
|
86
|
+
run('git commit -m "init: scaffold from omnify boilerplate"', {
|
|
87
|
+
cwd: projectDir,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// ── Setup Laravel ───────────────────────────────────────────
|
|
91
|
+
log("Setting up Laravel...");
|
|
92
|
+
run("cp .env.example .env", { cwd: projectDir });
|
|
93
|
+
run("php artisan key:generate", { cwd: projectDir });
|
|
94
|
+
|
|
95
|
+
// ── Done ────────────────────────────────────────────────────
|
|
96
|
+
console.log(`
|
|
97
|
+
${green(bold(" ✓ Project created!"))}
|
|
98
|
+
|
|
99
|
+
${bold("Next steps:")}
|
|
100
|
+
${yellow(`cd ${projectName}`)}
|
|
101
|
+
${yellow("php artisan migrate")}
|
|
102
|
+
${yellow("pnpm dev")}
|
|
103
|
+
`);
|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-omnify",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Scaffold a new Omnify service from boilerplate",
|
|
5
|
+
"bin": "index.mjs",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": ["omnify", "laravel", "boilerplate", "scaffold"],
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
}
|
|
12
|
+
}
|