@docubook/create 1.8.9 → 1.9.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/create.js +59 -87
- package/package.json +1 -1
package/create.js
CHANGED
|
@@ -11,7 +11,7 @@ import figlet from "figlet";
|
|
|
11
11
|
import cliProgress from "cli-progress";
|
|
12
12
|
import { execSync } from "child_process";
|
|
13
13
|
|
|
14
|
-
//
|
|
14
|
+
// Logging helper with styles
|
|
15
15
|
const log = {
|
|
16
16
|
info: (msg) => console.log(chalk.cyan("ℹ️ " + msg)),
|
|
17
17
|
success: (msg) => console.log(chalk.green("✔ " + msg)),
|
|
@@ -19,7 +19,7 @@ const log = {
|
|
|
19
19
|
error: (msg) => console.log(chalk.red("✖ " + msg)),
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
//
|
|
22
|
+
// Cek apakah package manager terinstal di sistem
|
|
23
23
|
function isInstalled(command) {
|
|
24
24
|
try {
|
|
25
25
|
execSync(`${command} --version`, { stdio: "ignore" });
|
|
@@ -29,7 +29,7 @@ function isInstalled(command) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// Ambil versi package manager
|
|
33
33
|
function getPackageManagerVersion(pm) {
|
|
34
34
|
try {
|
|
35
35
|
return execSync(`${pm} --version`).toString().trim();
|
|
@@ -38,17 +38,16 @@ function getPackageManagerVersion(pm) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
//
|
|
41
|
+
// Rename file postcss.config.js → .cjs jika menggunakan bun
|
|
42
42
|
function updatePostcssConfig(projectPath) {
|
|
43
43
|
const oldPath = path.join(projectPath, "postcss.config.js");
|
|
44
44
|
const newPath = path.join(projectPath, "postcss.config.cjs");
|
|
45
45
|
if (fs.existsSync(oldPath)) {
|
|
46
46
|
fs.renameSync(oldPath, newPath);
|
|
47
|
-
log.info("Renamed postcss.config.js → .cjs for bun compatibility");
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
//
|
|
50
|
+
// Menampilkan ASCII art "DocuBook" saat CLI dijalankan
|
|
52
51
|
function displayAsciiArt() {
|
|
53
52
|
return new Promise((resolve, reject) => {
|
|
54
53
|
figlet.text("DocuBook", { horizontalLayout: "full" }, (err, data) => {
|
|
@@ -59,11 +58,7 @@ function displayAsciiArt() {
|
|
|
59
58
|
});
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
console.log(chalk.white("DocuBook Installer"));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// ========== Simulasi animasi setup ========== //
|
|
61
|
+
// Menampilkan progress bar saat simulasi setup akhir
|
|
67
62
|
async function simulateInstallation() {
|
|
68
63
|
const bar = new cliProgress.SingleBar(
|
|
69
64
|
{
|
|
@@ -82,7 +77,7 @@ async function simulateInstallation() {
|
|
|
82
77
|
bar.stop();
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
//
|
|
80
|
+
// Menampilkan langkah manual jika instalasi otomatis dibatalkan/gagal
|
|
86
81
|
function manualSteps(projectDirectory, packageManager) {
|
|
87
82
|
const manualInstructions = `
|
|
88
83
|
Please follow these steps manually to finish setting up your project:
|
|
@@ -101,7 +96,7 @@ function manualSteps(projectDirectory, packageManager) {
|
|
|
101
96
|
);
|
|
102
97
|
}
|
|
103
98
|
|
|
104
|
-
//
|
|
99
|
+
// Mendeteksi default package manager dari environment user
|
|
105
100
|
function detectDefaultPackageManager() {
|
|
106
101
|
const userAgent = process.env.npm_config_user_agent || "";
|
|
107
102
|
if (userAgent.includes("pnpm")) return "pnpm";
|
|
@@ -110,128 +105,107 @@ function detectDefaultPackageManager() {
|
|
|
110
105
|
return "npm";
|
|
111
106
|
}
|
|
112
107
|
|
|
113
|
-
//
|
|
108
|
+
// Entry point utama CLI
|
|
114
109
|
program
|
|
115
|
-
.version("1.
|
|
110
|
+
.version("1.9.0")
|
|
116
111
|
.description("CLI to create a new Docubook project")
|
|
117
|
-
.
|
|
118
|
-
.action(async (projectDirectory) => {
|
|
112
|
+
.action(async () => {
|
|
119
113
|
await displayAsciiArt();
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
]);
|
|
132
|
-
projectDirectory = directoryName;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Pilihan package manager
|
|
136
|
-
const defaultPM = detectDefaultPackageManager();
|
|
137
|
-
const { packageManager } = await inquirer.prompt([
|
|
138
|
-
{
|
|
114
|
+
console.log(chalk.white("DocuBook Installer\n"));
|
|
115
|
+
|
|
116
|
+
// Multistep prompt: nama project, package manager, content source, dan pilihan install
|
|
117
|
+
const answers = await inquirer.prompt([
|
|
118
|
+
{
|
|
119
|
+
type: "input",
|
|
120
|
+
name: "directoryName",
|
|
121
|
+
message: "📁 Project name",
|
|
122
|
+
default: "docubook",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
139
125
|
type: "list",
|
|
140
126
|
name: "packageManager",
|
|
141
|
-
message: "
|
|
127
|
+
message: "📦 Package manager",
|
|
142
128
|
choices: ["npm", "pnpm", "yarn", "bun"],
|
|
143
|
-
default:
|
|
144
|
-
|
|
129
|
+
default: detectDefaultPackageManager(),
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
type: "confirm",
|
|
133
|
+
name: "installNow",
|
|
134
|
+
message: "🛠️ Install dependencies now?",
|
|
135
|
+
default: true,
|
|
136
|
+
},
|
|
145
137
|
]);
|
|
146
138
|
|
|
139
|
+
const { directoryName, packageManager, installNow } = answers;
|
|
140
|
+
const projectPath = path.resolve(process.cwd(), directoryName);
|
|
147
141
|
const version = getPackageManagerVersion(packageManager);
|
|
142
|
+
|
|
148
143
|
if (!version) {
|
|
149
144
|
log.error(`${packageManager} is not installed on your system.`);
|
|
150
145
|
process.exit(1);
|
|
151
146
|
}
|
|
152
147
|
|
|
153
|
-
// Clone repositori starter
|
|
154
148
|
const repo = "https://gitlab.com/mywildancloud/docubook.git";
|
|
155
149
|
const branch = "starter";
|
|
156
|
-
const projectPath = path.resolve(process.cwd(), projectDirectory);
|
|
157
150
|
const cloneCommand = `git clone --quiet --branch ${branch} ${repo} ${projectPath}`;
|
|
158
|
-
const spinner = ora("
|
|
151
|
+
const spinner = ora("Creating your DocuBook project...").start();
|
|
159
152
|
|
|
160
153
|
try {
|
|
161
154
|
execSync(cloneCommand);
|
|
162
|
-
spinner.succeed(`Project created in ${projectDirectory}/`);
|
|
163
155
|
|
|
164
|
-
// Rename config jika
|
|
165
|
-
if (packageManager === "bun")
|
|
166
|
-
updatePostcssConfig(projectPath);
|
|
167
|
-
}
|
|
156
|
+
// Rename config jika pakai bun
|
|
157
|
+
if (packageManager === "bun") updatePostcssConfig(projectPath);
|
|
168
158
|
|
|
169
|
-
//
|
|
159
|
+
// Update packageManager di package.json
|
|
170
160
|
const pkgPath = path.join(projectPath, "package.json");
|
|
161
|
+
let pkgVersion = "";
|
|
171
162
|
if (fs.existsSync(pkgPath)) {
|
|
172
163
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
173
|
-
const existingPM = pkg.packageManager?.split("@")[0];
|
|
174
|
-
|
|
175
|
-
// Jika berbeda, tampilkan peringatan & timpa packageManager
|
|
176
|
-
if (existingPM && existingPM !== packageManager) {
|
|
177
|
-
log.warn(`This project recommends ${existingPM}, but you chose ${packageManager}. Overriding...`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
164
|
pkg.packageManager = `${packageManager}@${version}`;
|
|
165
|
+
pkgVersion = pkg.version || "";
|
|
181
166
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
182
|
-
log.info(`Updated packageManager to "${pkg.packageManager}" in package.json`);
|
|
183
|
-
|
|
184
|
-
console.log(
|
|
185
|
-
chalk.green(
|
|
186
|
-
`=================\nDocuBook v${pkg.version}\n=================`
|
|
187
|
-
)
|
|
188
|
-
);
|
|
189
167
|
}
|
|
190
168
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
message: "Do you want to continue with the installation of dependencies?",
|
|
197
|
-
default: true,
|
|
198
|
-
},
|
|
199
|
-
]);
|
|
200
|
-
|
|
201
|
-
if (!continueInstallation) {
|
|
202
|
-
manualSteps(projectDirectory, packageManager);
|
|
169
|
+
spinner.succeed();
|
|
170
|
+
log.success(`DocuBook v${pkgVersion} in \"${directoryName}\" using \"${packageManager}\"`);
|
|
171
|
+
|
|
172
|
+
if (!installNow) {
|
|
173
|
+
manualSteps(directoryName, packageManager);
|
|
203
174
|
return;
|
|
204
175
|
}
|
|
205
176
|
|
|
206
177
|
log.info("Installing dependencies...");
|
|
207
178
|
console.log(chalk.yellow("This is a joke for you:"));
|
|
208
|
-
console.log(
|
|
179
|
+
console.log(
|
|
180
|
+
chalk.white(
|
|
181
|
+
"When you install the package manager, the installation speed depends on the hardware you have."
|
|
182
|
+
)
|
|
183
|
+
);
|
|
184
|
+
|
|
209
185
|
const installSpinner = ora(`Using ${packageManager}...`).start();
|
|
210
186
|
|
|
211
|
-
|
|
212
|
-
if (packageManager === "yarn") {
|
|
187
|
+
if (packageManager === "yarn") {
|
|
213
188
|
const yarnrcPath = path.join(projectPath, ".yarnrc.yml");
|
|
214
189
|
fs.writeFileSync(yarnrcPath, "nodeLinker: node-modules\n");
|
|
215
|
-
|
|
190
|
+
}
|
|
216
191
|
|
|
217
192
|
try {
|
|
218
193
|
execSync(`${packageManager} install`, { cwd: projectPath, stdio: "ignore" });
|
|
219
194
|
installSpinner.succeed("Dependencies installed.");
|
|
220
|
-
|
|
195
|
+
} catch {
|
|
221
196
|
installSpinner.fail("Failed to install dependencies.");
|
|
222
|
-
manualSteps(
|
|
197
|
+
manualSteps(directoryName, packageManager);
|
|
223
198
|
process.exit(1);
|
|
224
|
-
|
|
199
|
+
}
|
|
225
200
|
|
|
226
201
|
await simulateInstallation();
|
|
227
202
|
|
|
228
|
-
//
|
|
203
|
+
// Tampilkan langkah selanjutnya setelah setup selesai
|
|
229
204
|
console.log(
|
|
230
205
|
boxen(
|
|
231
206
|
`Next Steps:\n\n` +
|
|
232
|
-
`1. ${chalk.cyan(`cd ${
|
|
233
|
-
`2. ${chalk.cyan(`${packageManager}
|
|
234
|
-
`3. ${chalk.cyan(`${packageManager} run dev`)}`,
|
|
207
|
+
`1. ${chalk.cyan(`cd ${directoryName}`)}\n` +
|
|
208
|
+
`2. ${chalk.cyan(`${packageManager} run dev`)}`,
|
|
235
209
|
{
|
|
236
210
|
padding: 0.5,
|
|
237
211
|
borderStyle: "round",
|
|
@@ -239,8 +213,6 @@ program
|
|
|
239
213
|
}
|
|
240
214
|
)
|
|
241
215
|
);
|
|
242
|
-
|
|
243
|
-
process.exit(0);
|
|
244
216
|
} catch (err) {
|
|
245
217
|
spinner.fail("Failed to create project.");
|
|
246
218
|
log.error(err.message);
|