@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.
Files changed (2) hide show
  1. package/create.js +59 -87
  2. 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
- // ========== Logging ========== //
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
- // ========== Cek apakah package manager terinstal ========== //
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
- // ========== Ambil versi package manager ========== //
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
- // ========== Rename postcss.config.js ke .cjs jika menggunakan bun ========== //
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
- // ========== ASCII welcome art ========== //
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
- function displayWelcomeMessage() {
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
- // ========== Jika user batal install, tunjukkan langkah manual ========== //
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
- // Deteksi default package manager dari eksekusi CLI
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
- // ========== Entry CLI ========== //
108
+ // Entry point utama CLI
114
109
  program
115
- .version("1.8.9")
110
+ .version("1.9.0")
116
111
  .description("CLI to create a new Docubook project")
117
- .argument("[project-directory]", "Directory to create the new Docubook project")
118
- .action(async (projectDirectory) => {
112
+ .action(async () => {
119
113
  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
- {
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: "Choose a package manager:",
127
+ message: "📦 Package manager",
142
128
  choices: ["npm", "pnpm", "yarn", "bun"],
143
- default: defaultPM,
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("Cloning DocuBook starter...").start();
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 menggunakan bun
165
- if (packageManager === "bun") {
166
- updatePostcssConfig(projectPath);
167
- }
156
+ // Rename config jika pakai bun
157
+ if (packageManager === "bun") updatePostcssConfig(projectPath);
168
158
 
169
- // Validasi packageManager dari project yang di-clone
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
- // 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);
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(chalk.white("When you install the package manager, the installation speed depends on the hardware you have."));
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
- // Tambahkan konfigurasi khusus untuk yarn
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
- } catch {
195
+ } catch {
221
196
  installSpinner.fail("Failed to install dependencies.");
222
- manualSteps(projectDirectory, packageManager); // Jika gagal install otomatis
197
+ manualSteps(directoryName, packageManager);
223
198
  process.exit(1);
224
- }
199
+ }
225
200
 
226
201
  await simulateInstallation();
227
202
 
228
- // Saran langkah selanjutnya
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 ${projectDirectory}`)}\n` +
233
- `2. ${chalk.cyan(`${packageManager} install (if not automatically installed)`)}\n` +
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docubook/create",
3
- "version": "1.8.9",
3
+ "version": "1.9.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {