@docubook/create 1.7.5 → 1.8.6

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 (3) hide show
  1. package/README.md +2 -3
  2. package/create.js +138 -86
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  > **Note**: This application is a fork of [AriaDocs](https://github.com/nisabmohd/Aria-Docs), created by [Nisab Mohd](https://github.com/nisabmohd). DocuBook provides an alternative to the documentation solution found on [Mintlify](https://mintlify.com/), utilizing `.mdx` (Markdown + JSX) for content creation and management.
6
6
 
7
- [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/mywildancloud/docubook)
7
+ [![Deploy with
8
+ Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/gitfromwildan/docubook)
8
9
 
9
10
  ## Features
10
11
 
@@ -36,5 +37,3 @@ Next steps:
36
37
  3. Start the development server:
37
38
  npm run dev
38
39
  ```
39
-
40
- Access the app on => http://localhost:3000
package/create.js CHANGED
@@ -11,89 +11,107 @@ import figlet from "figlet";
11
11
  import cliProgress from "cli-progress";
12
12
  import { execSync } from "child_process";
13
13
 
14
- // Cek apakah Node.js sudah terinstal
15
- function checkNodeInstalled() {
14
+ // ========== Logging ========== //
15
+ const log = {
16
+ info: (msg) => console.log(chalk.cyan("ℹ️ " + msg)),
17
+ success: (msg) => console.log(chalk.green("✔ " + msg)),
18
+ warn: (msg) => console.log(chalk.yellow("⚠️ " + msg)),
19
+ error: (msg) => console.log(chalk.red("✖ " + msg)),
20
+ };
21
+
22
+ // ========== Cek apakah package manager terinstal ========== //
23
+ function isInstalled(command) {
16
24
  try {
17
- execSync("node -v", { stdio: "ignore" });
25
+ execSync(`${command} --version`, { stdio: "ignore" });
18
26
  return true;
19
27
  } catch {
20
28
  return false;
21
29
  }
22
30
  }
23
31
 
24
- // Cek apakah Bun sudah terinstal
25
- function checkBunInstalled() {
32
+ // ========== Ambil versi package manager ========== //
33
+ function getPackageManagerVersion(pm) {
26
34
  try {
27
- execSync("bun --version", { stdio: "ignore" });
28
- return true;
35
+ return execSync(`${pm} --version`).toString().trim();
29
36
  } catch {
30
- return false;
37
+ return null;
31
38
  }
32
39
  }
33
40
 
34
- // Fungsi untuk mengganti nama file postcss
41
+ // ========== Rename postcss.config.js ke .cjs jika menggunakan bun ========== //
35
42
  function updatePostcssConfig(projectPath) {
36
- const oldConfigPath = path.join(projectPath, "postcss.config.js");
37
- const newConfigPath = path.join(projectPath, "postcss.config.cjs");
38
- if (fs.existsSync(oldConfigPath)) {
39
- fs.renameSync(oldConfigPath, newConfigPath);
40
- console.log(chalk.yellow("Renamed postcss.config.js to postcss.config.cjs for Bun compatibility."));
41
- } else {
42
- console.log(chalk.yellow("No postcss.config.js file found. Skipping rename."));
43
+ const oldPath = path.join(projectPath, "postcss.config.js");
44
+ const newPath = path.join(projectPath, "postcss.config.cjs");
45
+ if (fs.existsSync(oldPath)) {
46
+ fs.renameSync(oldPath, newPath);
47
+ log.info("Renamed postcss.config.js .cjs for bun compatibility");
43
48
  }
44
49
  }
45
50
 
46
- // Menampilkan ASCII Art untuk branding
51
+ // ========== ASCII welcome art ========== //
47
52
  function displayAsciiArt() {
48
- console.log(
49
- chalk.green(
50
- figlet.textSync("DocuBook", {
51
- horizontalLayout: "full",
52
- })
53
- )
54
- );
53
+ return new Promise((resolve, reject) => {
54
+ figlet.text("DocuBook", { horizontalLayout: "full" }, (err, data) => {
55
+ if (err) return reject(err);
56
+ console.log(chalk.green(data));
57
+ resolve();
58
+ });
59
+ });
55
60
  }
56
61
 
57
- // Menampilkan kotak pesan selamat datang
58
62
  function displayWelcomeMessage() {
59
- const welcomeMessage = boxen("DocuBook CLI Installer!", {
60
- padding: 1,
61
- margin: 1,
62
- borderStyle: "round",
63
- borderColor: "green",
64
- });
65
- console.log(welcomeMessage);
63
+ console.log(chalk.white("DocuBook Installer"));
66
64
  }
67
65
 
68
- // Simulasi progress bar untuk instalasi
66
+ // ========== Simulasi animasi setup ========== //
69
67
  async function simulateInstallation() {
70
- const progressBar = new cliProgress.SingleBar(
68
+ const bar = new cliProgress.SingleBar(
71
69
  {
72
- format: 'Installation |' + chalk.green('{bar}') + '| {percentage}% || {value}/{total}',
70
+ format: 'Finishing Setup |' + chalk.green('{bar}') + '| {percentage}% || {value}/{total}',
73
71
  barCompleteChar: '\u2588',
74
72
  barIncompleteChar: '\u2591',
75
73
  },
76
74
  cliProgress.Presets.shades_classic
77
75
  );
78
76
 
79
- progressBar.start(100, 0);
80
-
77
+ bar.start(100, 0);
81
78
  for (let i = 0; i <= 100; i++) {
82
- await new Promise((resolve) => setTimeout(resolve, 50));
83
- progressBar.update(i);
79
+ await new Promise((r) => setTimeout(r, 50));
80
+ bar.update(i);
84
81
  }
82
+ bar.stop();
83
+ }
84
+
85
+ // ========== Jika user batal install, tunjukkan langkah manual ========== //
86
+ function manualSteps(projectDirectory, packageManager) {
87
+ const manualInstructions = `
88
+ You chose not to continue with the installation.
89
+ Please follow these steps manually to finish setting up your project:
85
90
 
86
- progressBar.stop();
91
+ 1. ${chalk.cyan(`cd ${projectDirectory}`)}
92
+ 2. ${chalk.cyan(`${packageManager} install`)}
93
+ 3. ${chalk.cyan(`${packageManager} run dev`)}
94
+ `;
95
+
96
+ console.log(
97
+ boxen(manualInstructions, {
98
+ padding: 0.5,
99
+ borderStyle: "round",
100
+ borderColor: "cyan",
101
+ })
102
+ );
87
103
  }
88
104
 
105
+ // ========== Entry CLI ========== //
89
106
  program
90
- .version("1.7.5")
107
+ .version("1.8.6")
91
108
  .description("CLI to create a new Docubook project")
92
109
  .argument("[project-directory]", "Directory to create the new Docubook project")
93
110
  .action(async (projectDirectory) => {
94
- displayAsciiArt();
111
+ await displayAsciiArt();
95
112
  displayWelcomeMessage();
96
113
 
114
+ // Tanya nama direktori jika belum diisi
97
115
  if (!projectDirectory) {
98
116
  const { directoryName } = await inquirer.prompt([
99
117
  {
@@ -106,6 +124,7 @@ program
106
124
  projectDirectory = directoryName;
107
125
  }
108
126
 
127
+ // Pilihan package manager
109
128
  const { packageManager } = await inquirer.prompt([
110
129
  {
111
130
  type: "list",
@@ -115,67 +134,100 @@ program
115
134
  default: "npm",
116
135
  },
117
136
  ]);
118
- // --- cloning from gitlab ---
137
+
138
+ const version = getPackageManagerVersion(packageManager);
139
+ if (!version) {
140
+ log.error(`${packageManager} is not installed on your system.`);
141
+ process.exit(1);
142
+ }
143
+
144
+ // Clone repositori starter
119
145
  const repo = "https://gitlab.com/mywildancloud/docubook.git";
120
146
  const branch = "starter";
121
147
  const projectPath = path.resolve(process.cwd(), projectDirectory);
122
- const cloneCommand = `git clone --branch ${branch} ${repo} ${projectPath}`;
123
- const spinner = ora(`Cloning ${chalk.yellow(branch)} from GitLab...`).start();
148
+ const cloneCommand = `git clone --quiet --branch ${branch} ${repo} ${projectPath}`;
149
+ const spinner = ora("Cloning DocuBook starter...").start();
124
150
 
125
151
  try {
126
- execSync(cloneCommand, { stdio: "inherit" });
127
- spinner.succeed(`Docubook project successfully created in ${projectPath}!`);
152
+ execSync(cloneCommand);
153
+ spinner.succeed(`Project created in ${projectDirectory}/`);
128
154
 
129
- if (checkBunInstalled()) {
155
+ // Rename config jika menggunakan bun
156
+ if (packageManager === "bun") {
130
157
  updatePostcssConfig(projectPath);
131
- } else {
132
- console.log(chalk.yellow("Skipping rename postcss.config.js because Bun is not installed."));
133
158
  }
134
159
 
135
- // Baca versi Docubook dari package.json
136
- const packageJsonPath = path.join(projectPath, "package.json");
137
- if (fs.existsSync(packageJsonPath)) {
138
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
139
- const versionMessage = boxen(
140
- chalk.yellow("DocuBook Version") + "\n\n" + chalk.white(`v${packageJson.version}`),
141
- {
142
- padding: 1,
143
- margin: 1,
144
- borderStyle: "round",
145
- borderColor: "yellow",
146
- }
147
- );
148
- console.log(versionMessage);
149
- }
150
-
151
- console.log(chalk.yellow("\nStarting the installation process..."));
152
- await simulateInstallation();
160
+ // Validasi packageManager dari project yang di-clone
161
+ const pkgPath = path.join(projectPath, "package.json");
162
+ if (fs.existsSync(pkgPath)) {
163
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
164
+ const existingPM = pkg.packageManager?.split("@")[0];
153
165
 
154
- try {
155
- execSync(`${packageManager} install`, { cwd: projectPath, stdio: "inherit" });
156
- console.log(chalk.green(`Dependencies installed successfully using ${packageManager}!`));
157
- } catch (err) {
158
- console.error(chalk.red(`Failed to install dependencies using ${packageManager}.`));
166
+ // Jika berbeda, tampilkan peringatan & timpa packageManager
167
+ if (existingPM && existingPM !== packageManager) {
168
+ log.warn(`This project recommends ${existingPM}, but you chose ${packageManager}. Overriding...`);
169
+ }
170
+
171
+ pkg.packageManager = `${packageManager}@${version}`;
172
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
173
+ log.info(`Updated packageManager to "${pkg.packageManager}" in package.json`);
174
+
175
+ console.log(
176
+ chalk.green(
177
+ `=================\nDocuBook v${pkg.version}\n=================`
178
+ )
179
+ );
159
180
  }
160
181
 
161
- const nextStepsMessage = boxen(
162
- `Next Steps:\n\n` +
163
- `1. Navigate to your project directory:\n ${chalk.green(`cd ${projectDirectory}`)}\n\n` +
164
- `2. Install dependencies (if not installed automatically):\n ${chalk.green(`${packageManager} install`)}\n\n` +
165
- `3. Start the development server:\n ${chalk.green(`${packageManager} run dev`)}`,
182
+ // Tanya apakah lanjut install dependencies
183
+ const { continueInstallation } = await inquirer.prompt([
166
184
  {
167
- padding: 1,
168
- margin: 1,
169
- borderStyle: "round",
170
- borderColor: "blue",
171
- }
185
+ type: "confirm",
186
+ name: "continueInstallation",
187
+ message: "Do you want to continue with the installation of dependencies?",
188
+ default: true,
189
+ },
190
+ ]);
191
+
192
+ if (!continueInstallation) {
193
+ manualSteps(projectDirectory, packageManager);
194
+ return;
195
+ }
196
+
197
+ log.info("Installing dependencies...");
198
+ console.log(chalk.yellow("This is a joke for you:"));
199
+ console.log(chalk.white("When you install the package manager, the installation speed depends on the hardware you have."));
200
+ const installSpinner = ora(`Using ${packageManager}...`).start();
201
+
202
+ try {
203
+ execSync(`${packageManager} install`, { cwd: projectPath, stdio: "ignore" });
204
+ installSpinner.succeed("Dependencies installed.");
205
+ } catch {
206
+ installSpinner.fail("Failed to install dependencies.");
207
+ process.exit(1);
208
+ }
209
+
210
+ await simulateInstallation();
211
+
212
+ // Saran langkah selanjutnya
213
+ console.log(
214
+ boxen(
215
+ `Next Steps:\n\n` +
216
+ `1. ${chalk.cyan(`cd ${projectDirectory}`)}\n` +
217
+ `2. ${chalk.cyan(`${packageManager} install (if not automatically installed)`)}\n` +
218
+ `3. ${chalk.cyan(`${packageManager} run dev`)}`,
219
+ {
220
+ padding: 0.5,
221
+ borderStyle: "round",
222
+ borderColor: "cyan",
223
+ }
224
+ )
172
225
  );
173
- console.log(nextStepsMessage);
174
226
 
175
227
  process.exit(0);
176
228
  } catch (err) {
177
- spinner.fail("Failed to create project:");
178
- console.error(err.message);
229
+ spinner.fail("Failed to create project.");
230
+ log.error(err.message);
179
231
  process.exit(1);
180
232
  }
181
233
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docubook/create",
3
- "version": "1.7.5",
3
+ "version": "1.8.6",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,5 +23,6 @@
23
23
  "figlet": "^1.8.0",
24
24
  "inquirer": "^11.0.2",
25
25
  "ora": "^8.1.0"
26
- }
26
+ },
27
+ "packageManager": "pnpm@10.10.0"
27
28
  }