@docubook/create 1.7.5 → 1.8.5

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 +118 -95
  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,87 +11,93 @@ 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 util
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 CLI dependency
23
+ function checkInstalled(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() {
26
- try {
27
- execSync("bun --version", { stdio: "ignore" });
28
- return true;
29
- } catch {
30
- return false;
31
- }
32
- }
33
-
34
- // Fungsi untuk mengganti nama file postcss
32
+ // Rename postcss.config.js .cjs (untuk Bun)
35
33
  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."));
34
+ const oldPath = path.join(projectPath, "postcss.config.js");
35
+ const newPath = path.join(projectPath, "postcss.config.cjs");
36
+ if (fs.existsSync(oldPath)) {
37
+ fs.renameSync(oldPath, newPath);
38
+ log.info("Renamed postcss.config.js .cjs for bun compatibility");
43
39
  }
44
40
  }
45
41
 
46
- // Menampilkan ASCII Art untuk branding
42
+ // Tampilan awal
47
43
  function displayAsciiArt() {
48
- console.log(
49
- chalk.green(
50
- figlet.textSync("DocuBook", {
51
- horizontalLayout: "full",
52
- })
53
- )
54
- );
44
+ return new Promise((resolve, reject) => {
45
+ figlet.text("DocuBook", { horizontalLayout: "full" }, (err, data) => {
46
+ if (err) return reject(err);
47
+ console.log(chalk.green(data));
48
+ resolve();
49
+ });
50
+ });
55
51
  }
56
52
 
57
- // Menampilkan kotak pesan selamat datang
58
53
  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);
54
+ console.log(chalk.white("DocuBook Installer"));
66
55
  }
67
56
 
68
- // Simulasi progress bar untuk instalasi
57
+ // Simulasi progress bar setup
69
58
  async function simulateInstallation() {
70
- const progressBar = new cliProgress.SingleBar(
59
+ const bar = new cliProgress.SingleBar(
71
60
  {
72
- format: 'Installation |' + chalk.green('{bar}') + '| {percentage}% || {value}/{total}',
61
+ format: 'Finishing Setup |' + chalk.green('{bar}') + '| {percentage}% || {value}/{total}',
73
62
  barCompleteChar: '\u2588',
74
63
  barIncompleteChar: '\u2591',
75
64
  },
76
65
  cliProgress.Presets.shades_classic
77
66
  );
78
67
 
79
- progressBar.start(100, 0);
80
-
68
+ bar.start(100, 0);
81
69
  for (let i = 0; i <= 100; i++) {
82
- await new Promise((resolve) => setTimeout(resolve, 50));
83
- progressBar.update(i);
70
+ await new Promise((r) => setTimeout(r, 50));
71
+ bar.update(i);
84
72
  }
73
+ bar.stop();
74
+ }
75
+
76
+ function manualSteps(projectDirectory, packageManager) {
77
+ const manualInstructions = `
78
+ You chose not to continue with the installation.
79
+ Please follow these steps manually to finish setting up your project:
85
80
 
86
- progressBar.stop();
81
+ 1. ${chalk.cyan(`cd ${projectDirectory}`)}
82
+ 2. ${chalk.cyan(`${packageManager} install`)}
83
+ 3. ${chalk.cyan(`${packageManager} run dev`)}
84
+ `;
85
+
86
+ console.log(
87
+ boxen(manualInstructions, {
88
+ padding: 1,
89
+ borderStyle: "round",
90
+ borderColor: "cyan",
91
+ })
92
+ );
87
93
  }
88
94
 
89
95
  program
90
- .version("1.7.5")
96
+ .version("1.8.5")
91
97
  .description("CLI to create a new Docubook project")
92
98
  .argument("[project-directory]", "Directory to create the new Docubook project")
93
99
  .action(async (projectDirectory) => {
94
- displayAsciiArt();
100
+ await displayAsciiArt();
95
101
  displayWelcomeMessage();
96
102
 
97
103
  if (!projectDirectory) {
@@ -106,76 +112,93 @@ program
106
112
  projectDirectory = directoryName;
107
113
  }
108
114
 
109
- const { packageManager } = await inquirer.prompt([
110
- {
115
+ let { packageManager } = await inquirer.prompt([
116
+ {
111
117
  type: "list",
112
118
  name: "packageManager",
113
119
  message: "Choose a package manager:",
114
120
  choices: ["npm", "pnpm", "yarn", "bun"],
115
121
  default: "npm",
116
- },
122
+ },
117
123
  ]);
118
- // --- cloning from gitlab ---
124
+
125
+ if (!checkInstalled(packageManager)) {
126
+ log.warn(`${packageManager} is not installed. Falling back to npm.`);
127
+ packageManager = "npm";
128
+ }
129
+
119
130
  const repo = "https://gitlab.com/mywildancloud/docubook.git";
120
131
  const branch = "starter";
121
132
  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();
133
+ const cloneCommand = `git clone --quiet --branch ${branch} ${repo} ${projectPath}`;
134
+ const spinner = ora("Cloning DocuBook starter...").start();
124
135
 
125
136
  try {
126
- execSync(cloneCommand, { stdio: "inherit" });
127
- spinner.succeed(`Docubook project successfully created in ${projectPath}!`);
137
+ execSync(cloneCommand);
138
+ spinner.succeed(`Project created in ${projectDirectory}/`);
128
139
 
129
- if (checkBunInstalled()) {
130
- updatePostcssConfig(projectPath);
131
- } else {
132
- console.log(chalk.yellow("Skipping rename postcss.config.js because Bun is not installed."));
140
+ if (packageManager === "bun" && checkInstalled("bun")) {
141
+ updatePostcssConfig(projectPath);
142
+ }
143
+
144
+ const pkgPath = path.join(projectPath, "package.json");
145
+ if (fs.existsSync(pkgPath)) {
146
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
147
+ console.log(
148
+ chalk.green(
149
+ `=================\nDocuBook v${pkg.version}\n=================`
150
+ )
151
+ );
133
152
  }
134
153
 
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();
154
+ // Tanya apakah pengguna ingin melanjutkan instalasi
155
+ const { continueInstallation } = await inquirer.prompt([
156
+ {
157
+ type: "confirm",
158
+ name: "continueInstallation",
159
+ message: "Do you want to continue with the installation of dependencies?",
160
+ default: true,
161
+ },
162
+ ]);
163
+
164
+ if (!continueInstallation) {
165
+ manualSteps(projectDirectory, packageManager);
166
+ return;
167
+ }
168
+
169
+ log.info("Installing dependencies...");
170
+ console.log(chalk.yellow("This is a joke for you:"));
171
+ console.log(chalk.white("When you install the package manager, the installation speed depends on the device and hardware you have."));
172
+ const installSpinner = ora(`Using ${packageManager}...`).start();
153
173
 
154
174
  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}.`));
175
+ execSync(`${packageManager} install`, { cwd: projectPath, stdio: "ignore" });
176
+ installSpinner.succeed("Dependencies installed.");
177
+ } catch {
178
+ installSpinner.fail("Failed to install dependencies.");
179
+ process.exit(1);
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`)}`,
166
- {
167
- padding: 1,
168
- margin: 1,
169
- borderStyle: "round",
170
- borderColor: "blue",
171
- }
182
+ await simulateInstallation();
183
+
184
+ console.log(
185
+ boxen(
186
+ `Next Steps:\n\n` +
187
+ `1. ${chalk.cyan(`cd ${projectDirectory}`)}\n` +
188
+ `2. ${chalk.cyan(`${packageManager} install (if not automatically installed)`)}\n` +
189
+ `3. ${chalk.cyan(`${packageManager} run dev`)}`,
190
+ {
191
+ padding: 1,
192
+ borderStyle: "round",
193
+ borderColor: "cyan",
194
+ }
195
+ )
172
196
  );
173
- console.log(nextStepsMessage);
174
197
 
175
198
  process.exit(0);
176
199
  } catch (err) {
177
- spinner.fail("Failed to create project:");
178
- console.error(err.message);
200
+ spinner.fail("Failed to create project.");
201
+ log.error(err.message);
179
202
  process.exit(1);
180
203
  }
181
204
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docubook/create",
3
- "version": "1.7.5",
3
+ "version": "1.8.5",
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
  }