@docubook/create 1.8.8 → 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 -88
- 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,10 +77,9 @@ 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
|
-
You chose not to continue with the installation.
|
|
89
83
|
Please follow these steps manually to finish setting up your project:
|
|
90
84
|
|
|
91
85
|
1. ${chalk.cyan(`cd ${projectDirectory}`)}
|
|
@@ -102,7 +96,7 @@ function manualSteps(projectDirectory, packageManager) {
|
|
|
102
96
|
);
|
|
103
97
|
}
|
|
104
98
|
|
|
105
|
-
//
|
|
99
|
+
// Mendeteksi default package manager dari environment user
|
|
106
100
|
function detectDefaultPackageManager() {
|
|
107
101
|
const userAgent = process.env.npm_config_user_agent || "";
|
|
108
102
|
if (userAgent.includes("pnpm")) return "pnpm";
|
|
@@ -111,128 +105,107 @@ function detectDefaultPackageManager() {
|
|
|
111
105
|
return "npm";
|
|
112
106
|
}
|
|
113
107
|
|
|
114
|
-
//
|
|
108
|
+
// Entry point utama CLI
|
|
115
109
|
program
|
|
116
|
-
.version("1.
|
|
110
|
+
.version("1.9.0")
|
|
117
111
|
.description("CLI to create a new Docubook project")
|
|
118
|
-
.
|
|
119
|
-
.action(async (projectDirectory) => {
|
|
112
|
+
.action(async () => {
|
|
120
113
|
await displayAsciiArt();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
]);
|
|
133
|
-
projectDirectory = directoryName;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Pilihan package manager
|
|
137
|
-
const defaultPM = detectDefaultPackageManager();
|
|
138
|
-
const { packageManager } = await inquirer.prompt([
|
|
139
|
-
{
|
|
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
|
+
{
|
|
140
125
|
type: "list",
|
|
141
126
|
name: "packageManager",
|
|
142
|
-
message: "
|
|
127
|
+
message: "📦 Package manager",
|
|
143
128
|
choices: ["npm", "pnpm", "yarn", "bun"],
|
|
144
|
-
default:
|
|
145
|
-
|
|
129
|
+
default: detectDefaultPackageManager(),
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
type: "confirm",
|
|
133
|
+
name: "installNow",
|
|
134
|
+
message: "🛠️ Install dependencies now?",
|
|
135
|
+
default: true,
|
|
136
|
+
},
|
|
146
137
|
]);
|
|
147
138
|
|
|
139
|
+
const { directoryName, packageManager, installNow } = answers;
|
|
140
|
+
const projectPath = path.resolve(process.cwd(), directoryName);
|
|
148
141
|
const version = getPackageManagerVersion(packageManager);
|
|
142
|
+
|
|
149
143
|
if (!version) {
|
|
150
144
|
log.error(`${packageManager} is not installed on your system.`);
|
|
151
145
|
process.exit(1);
|
|
152
146
|
}
|
|
153
147
|
|
|
154
|
-
// Clone repositori starter
|
|
155
148
|
const repo = "https://gitlab.com/mywildancloud/docubook.git";
|
|
156
149
|
const branch = "starter";
|
|
157
|
-
const projectPath = path.resolve(process.cwd(), projectDirectory);
|
|
158
150
|
const cloneCommand = `git clone --quiet --branch ${branch} ${repo} ${projectPath}`;
|
|
159
|
-
const spinner = ora("
|
|
151
|
+
const spinner = ora("Creating your DocuBook project...").start();
|
|
160
152
|
|
|
161
153
|
try {
|
|
162
154
|
execSync(cloneCommand);
|
|
163
|
-
spinner.succeed(`Project created in ${projectDirectory}/`);
|
|
164
155
|
|
|
165
|
-
// Rename config jika
|
|
166
|
-
if (packageManager === "bun")
|
|
167
|
-
updatePostcssConfig(projectPath);
|
|
168
|
-
}
|
|
156
|
+
// Rename config jika pakai bun
|
|
157
|
+
if (packageManager === "bun") updatePostcssConfig(projectPath);
|
|
169
158
|
|
|
170
|
-
//
|
|
159
|
+
// Update packageManager di package.json
|
|
171
160
|
const pkgPath = path.join(projectPath, "package.json");
|
|
161
|
+
let pkgVersion = "";
|
|
172
162
|
if (fs.existsSync(pkgPath)) {
|
|
173
163
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
174
|
-
const existingPM = pkg.packageManager?.split("@")[0];
|
|
175
|
-
|
|
176
|
-
// Jika berbeda, tampilkan peringatan & timpa packageManager
|
|
177
|
-
if (existingPM && existingPM !== packageManager) {
|
|
178
|
-
log.warn(`This project recommends ${existingPM}, but you chose ${packageManager}. Overriding...`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
164
|
pkg.packageManager = `${packageManager}@${version}`;
|
|
165
|
+
pkgVersion = pkg.version || "";
|
|
182
166
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
183
|
-
log.info(`Updated packageManager to "${pkg.packageManager}" in package.json`);
|
|
184
|
-
|
|
185
|
-
console.log(
|
|
186
|
-
chalk.green(
|
|
187
|
-
`=================\nDocuBook v${pkg.version}\n=================`
|
|
188
|
-
)
|
|
189
|
-
);
|
|
190
167
|
}
|
|
191
168
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
message: "Do you want to continue with the installation of dependencies?",
|
|
198
|
-
default: true,
|
|
199
|
-
},
|
|
200
|
-
]);
|
|
201
|
-
|
|
202
|
-
if (!continueInstallation) {
|
|
203
|
-
manualSteps(projectDirectory, packageManager);
|
|
169
|
+
spinner.succeed();
|
|
170
|
+
log.success(`DocuBook v${pkgVersion} in \"${directoryName}\" using \"${packageManager}\"`);
|
|
171
|
+
|
|
172
|
+
if (!installNow) {
|
|
173
|
+
manualSteps(directoryName, packageManager);
|
|
204
174
|
return;
|
|
205
175
|
}
|
|
206
176
|
|
|
207
177
|
log.info("Installing dependencies...");
|
|
208
178
|
console.log(chalk.yellow("This is a joke for you:"));
|
|
209
|
-
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
|
+
|
|
210
185
|
const installSpinner = ora(`Using ${packageManager}...`).start();
|
|
211
186
|
|
|
212
|
-
|
|
213
|
-
if (packageManager === "yarn") {
|
|
187
|
+
if (packageManager === "yarn") {
|
|
214
188
|
const yarnrcPath = path.join(projectPath, ".yarnrc.yml");
|
|
215
189
|
fs.writeFileSync(yarnrcPath, "nodeLinker: node-modules\n");
|
|
216
|
-
|
|
190
|
+
}
|
|
217
191
|
|
|
218
192
|
try {
|
|
219
193
|
execSync(`${packageManager} install`, { cwd: projectPath, stdio: "ignore" });
|
|
220
194
|
installSpinner.succeed("Dependencies installed.");
|
|
221
|
-
|
|
195
|
+
} catch {
|
|
222
196
|
installSpinner.fail("Failed to install dependencies.");
|
|
223
|
-
manualSteps(
|
|
197
|
+
manualSteps(directoryName, packageManager);
|
|
224
198
|
process.exit(1);
|
|
225
|
-
|
|
199
|
+
}
|
|
226
200
|
|
|
227
201
|
await simulateInstallation();
|
|
228
202
|
|
|
229
|
-
//
|
|
203
|
+
// Tampilkan langkah selanjutnya setelah setup selesai
|
|
230
204
|
console.log(
|
|
231
205
|
boxen(
|
|
232
206
|
`Next Steps:\n\n` +
|
|
233
|
-
`1. ${chalk.cyan(`cd ${
|
|
234
|
-
`2. ${chalk.cyan(`${packageManager}
|
|
235
|
-
`3. ${chalk.cyan(`${packageManager} run dev`)}`,
|
|
207
|
+
`1. ${chalk.cyan(`cd ${directoryName}`)}\n` +
|
|
208
|
+
`2. ${chalk.cyan(`${packageManager} run dev`)}`,
|
|
236
209
|
{
|
|
237
210
|
padding: 0.5,
|
|
238
211
|
borderStyle: "round",
|
|
@@ -240,8 +213,6 @@ program
|
|
|
240
213
|
}
|
|
241
214
|
)
|
|
242
215
|
);
|
|
243
|
-
|
|
244
|
-
process.exit(0);
|
|
245
216
|
} catch (err) {
|
|
246
217
|
spinner.fail("Failed to create project.");
|
|
247
218
|
log.error(err.message);
|