@docubook/create 1.8.9 → 1.9.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.
Files changed (2) hide show
  1. package/create.js +58 -98
  2. package/package.json +4 -3
package/create.js CHANGED
@@ -5,13 +5,14 @@ import path from "path";
5
5
  import fs from "fs";
6
6
  import ora from "ora";
7
7
  import chalk from "chalk";
8
- import inquirer from "inquirer";
9
8
  import boxen from "boxen";
10
9
  import figlet from "figlet";
11
10
  import cliProgress from "cli-progress";
12
11
  import { execSync } from "child_process";
12
+ import enquirer from "enquirer";
13
+ const { prompt } = enquirer;
13
14
 
14
- // ========== Logging ========== //
15
+ // Logging helper with styles
15
16
  const log = {
16
17
  info: (msg) => console.log(chalk.cyan("ℹ️ " + msg)),
17
18
  success: (msg) => console.log(chalk.green("✔ " + msg)),
@@ -19,17 +20,7 @@ const log = {
19
20
  error: (msg) => console.log(chalk.red("✖ " + msg)),
20
21
  };
21
22
 
22
- // ========== Cek apakah package manager terinstal ========== //
23
- function isInstalled(command) {
24
- try {
25
- execSync(`${command} --version`, { stdio: "ignore" });
26
- return true;
27
- } catch {
28
- return false;
29
- }
30
- }
31
-
32
- // ========== Ambil versi package manager ========== //
23
+ // Ambil versi package manager
33
24
  function getPackageManagerVersion(pm) {
34
25
  try {
35
26
  return execSync(`${pm} --version`).toString().trim();
@@ -38,17 +29,16 @@ function getPackageManagerVersion(pm) {
38
29
  }
39
30
  }
40
31
 
41
- // ========== Rename postcss.config.js ke .cjs jika menggunakan bun ========== //
32
+ // Rename file postcss.config.js .cjs jika menggunakan bun
42
33
  function updatePostcssConfig(projectPath) {
43
34
  const oldPath = path.join(projectPath, "postcss.config.js");
44
35
  const newPath = path.join(projectPath, "postcss.config.cjs");
45
36
  if (fs.existsSync(oldPath)) {
46
37
  fs.renameSync(oldPath, newPath);
47
- log.info("Renamed postcss.config.js → .cjs for bun compatibility");
48
38
  }
49
39
  }
50
40
 
51
- // ========== ASCII welcome art ========== //
41
+ // Menampilkan ASCII art "DocuBook" saat CLI dijalankan
52
42
  function displayAsciiArt() {
53
43
  return new Promise((resolve, reject) => {
54
44
  figlet.text("DocuBook", { horizontalLayout: "full" }, (err, data) => {
@@ -59,11 +49,7 @@ function displayAsciiArt() {
59
49
  });
60
50
  }
61
51
 
62
- function displayWelcomeMessage() {
63
- console.log(chalk.white("DocuBook Installer"));
64
- }
65
-
66
- // ========== Simulasi animasi setup ========== //
52
+ // Menampilkan progress bar saat simulasi setup akhir
67
53
  async function simulateInstallation() {
68
54
  const bar = new cliProgress.SingleBar(
69
55
  {
@@ -82,7 +68,7 @@ async function simulateInstallation() {
82
68
  bar.stop();
83
69
  }
84
70
 
85
- // ========== Jika user batal install, tunjukkan langkah manual ========== //
71
+ // Menampilkan langkah manual jika instalasi otomatis dibatalkan/gagal
86
72
  function manualSteps(projectDirectory, packageManager) {
87
73
  const manualInstructions = `
88
74
  Please follow these steps manually to finish setting up your project:
@@ -101,7 +87,7 @@ function manualSteps(projectDirectory, packageManager) {
101
87
  );
102
88
  }
103
89
 
104
- // Deteksi default package manager dari eksekusi CLI
90
+ // Mendeteksi default package manager dari environment user
105
91
  function detectDefaultPackageManager() {
106
92
  const userAgent = process.env.npm_config_user_agent || "";
107
93
  if (userAgent.includes("pnpm")) return "pnpm";
@@ -110,128 +96,104 @@ function detectDefaultPackageManager() {
110
96
  return "npm";
111
97
  }
112
98
 
113
- // ========== Entry CLI ========== //
99
+ // Entry point utama CLI
114
100
  program
115
- .version("1.8.9")
101
+ .version("1.9.1")
116
102
  .description("CLI to create a new Docubook project")
117
- .argument("[project-directory]", "Directory to create the new Docubook project")
118
- .action(async (projectDirectory) => {
103
+ .action(async () => {
119
104
  await displayAsciiArt();
120
- displayWelcomeMessage();
121
-
122
- // Tanya nama direktori jika belum diisi
123
- if (!projectDirectory) {
124
- const { directoryName } = await inquirer.prompt([
125
- {
126
- type: "input",
127
- name: "directoryName",
128
- message: "Enter your project directory name:",
129
- default: "docubook",
130
- },
131
- ]);
132
- projectDirectory = directoryName;
133
- }
134
-
135
- // Pilihan package manager
136
- const defaultPM = detectDefaultPackageManager();
137
- const { packageManager } = await inquirer.prompt([
138
- {
139
- type: "list",
105
+ console.log(chalk.white("DocuBook Installer\n"));
106
+
107
+ // Menggunakan enquirer untuk pengalaman mirip `npm create`
108
+ const answers = await prompt([
109
+ {
110
+ type: "input",
111
+ name: "directoryName",
112
+ message: "📁 Project name",
113
+ initial: "docubook",
114
+ },
115
+ {
116
+ type: "select",
140
117
  name: "packageManager",
141
- message: "Choose a package manager:",
118
+ message: "📦 Package manager",
142
119
  choices: ["npm", "pnpm", "yarn", "bun"],
143
- default: defaultPM,
144
- },
120
+ initial: detectDefaultPackageManager(),
121
+ },
122
+ {
123
+ type: "confirm",
124
+ name: "installNow",
125
+ message: "🛠️ Install dependencies now?",
126
+ initial: true,
127
+ },
145
128
  ]);
146
129
 
130
+ const { directoryName, packageManager, installNow } = answers;
131
+ const projectPath = path.resolve(process.cwd(), directoryName);
147
132
  const version = getPackageManagerVersion(packageManager);
133
+
148
134
  if (!version) {
149
135
  log.error(`${packageManager} is not installed on your system.`);
150
136
  process.exit(1);
151
137
  }
152
138
 
153
- // Clone repositori starter
154
139
  const repo = "https://gitlab.com/mywildancloud/docubook.git";
155
140
  const branch = "starter";
156
- const projectPath = path.resolve(process.cwd(), projectDirectory);
157
141
  const cloneCommand = `git clone --quiet --branch ${branch} ${repo} ${projectPath}`;
158
- const spinner = ora("Cloning DocuBook starter...").start();
142
+ const spinner = ora("Creating your DocuBook project...").start();
159
143
 
160
144
  try {
161
145
  execSync(cloneCommand);
162
- spinner.succeed(`Project created in ${projectDirectory}/`);
163
146
 
164
- // Rename config jika menggunakan bun
165
- if (packageManager === "bun") {
166
- updatePostcssConfig(projectPath);
167
- }
147
+ if (packageManager === "bun") updatePostcssConfig(projectPath);
168
148
 
169
- // Validasi packageManager dari project yang di-clone
170
149
  const pkgPath = path.join(projectPath, "package.json");
150
+ let pkgVersion = "";
171
151
  if (fs.existsSync(pkgPath)) {
172
152
  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
153
  pkg.packageManager = `${packageManager}@${version}`;
154
+ pkgVersion = pkg.version || "";
181
155
  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
156
  }
190
157
 
191
- // Tanya apakah lanjut install dependencies
192
- const { continueInstallation } = await inquirer.prompt([
193
- {
194
- type: "confirm",
195
- name: "continueInstallation",
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);
158
+ spinner.succeed();
159
+ log.success(`DocuBook v${pkgVersion} using \"${packageManager}\"`);
160
+
161
+ if (!installNow) {
162
+ manualSteps(directoryName, packageManager);
203
163
  return;
204
164
  }
205
165
 
206
166
  log.info("Installing dependencies...");
207
167
  console.log(chalk.yellow("This is a joke for you:"));
208
- console.log(chalk.white("When you install the package manager, the installation speed depends on the hardware you have."));
168
+ console.log(
169
+ chalk.white(
170
+ "You don't need to worry about this process not running, you just need the latest device for a faster installation process."
171
+ )
172
+ );
173
+
209
174
  const installSpinner = ora(`Using ${packageManager}...`).start();
210
175
 
211
- // Tambahkan konfigurasi khusus untuk yarn
212
- if (packageManager === "yarn") {
176
+ if (packageManager === "yarn") {
213
177
  const yarnrcPath = path.join(projectPath, ".yarnrc.yml");
214
178
  fs.writeFileSync(yarnrcPath, "nodeLinker: node-modules\n");
215
- }
179
+ }
216
180
 
217
181
  try {
218
182
  execSync(`${packageManager} install`, { cwd: projectPath, stdio: "ignore" });
219
183
  installSpinner.succeed("Dependencies installed.");
220
- } catch {
184
+ } catch {
221
185
  installSpinner.fail("Failed to install dependencies.");
222
- manualSteps(projectDirectory, packageManager); // Jika gagal install otomatis
186
+ manualSteps(directoryName, packageManager);
223
187
  process.exit(1);
224
- }
188
+ }
225
189
 
226
190
  await simulateInstallation();
227
191
 
228
- // Saran langkah selanjutnya
229
192
  console.log(
230
193
  boxen(
231
194
  `Next Steps:\n\n` +
232
- `1. ${chalk.cyan(`cd ${projectDirectory}`)}\n` +
233
- `2. ${chalk.cyan(`${packageManager} install (if not automatically installed)`)}\n` +
234
- `3. ${chalk.cyan(`${packageManager} run dev`)}`,
195
+ `1. ${chalk.cyan(`cd ${directoryName}`)}\n` +
196
+ `2. ${chalk.cyan(`${packageManager} run dev`)}`,
235
197
  {
236
198
  padding: 0.5,
237
199
  borderStyle: "round",
@@ -239,8 +201,6 @@ program
239
201
  }
240
202
  )
241
203
  );
242
-
243
- process.exit(0);
244
204
  } catch (err) {
245
205
  spinner.fail("Failed to create project.");
246
206
  log.error(err.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docubook/create",
3
- "version": "1.8.9",
3
+ "version": "1.9.1",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,9 +20,10 @@
20
20
  "cli-progress": "^3.12.0",
21
21
  "commander": "^12.1.0",
22
22
  "degit": "^2.8.4",
23
+ "enquirer": "^2.4.1",
23
24
  "figlet": "^1.8.0",
24
- "inquirer": "^11.0.2",
25
- "ora": "^8.1.0"
25
+ "ora": "^8.1.0",
26
+ "prompts": "^2.4.2"
26
27
  },
27
28
  "packageManager": "pnpm@10.10.0"
28
29
  }