@docubook/create 1.8.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 (2) hide show
  1. package/create.js +49 -20
  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 util
14
+ // ========== Logging ========== //
15
15
  const log = {
16
16
  info: (msg) => console.log(chalk.cyan("ℹ️ " + msg)),
17
17
  success: (msg) => console.log(chalk.green("✔ " + msg)),
@@ -19,8 +19,8 @@ const log = {
19
19
  error: (msg) => console.log(chalk.red("✖ " + msg)),
20
20
  };
21
21
 
22
- // Cek CLI dependency
23
- function checkInstalled(command) {
22
+ // ========== Cek apakah package manager terinstal ========== //
23
+ function isInstalled(command) {
24
24
  try {
25
25
  execSync(`${command} --version`, { stdio: "ignore" });
26
26
  return true;
@@ -29,7 +29,16 @@ function checkInstalled(command) {
29
29
  }
30
30
  }
31
31
 
32
- // Rename postcss.config.js .cjs (untuk Bun)
32
+ // ========== Ambil versi package manager ========== //
33
+ function getPackageManagerVersion(pm) {
34
+ try {
35
+ return execSync(`${pm} --version`).toString().trim();
36
+ } catch {
37
+ return null;
38
+ }
39
+ }
40
+
41
+ // ========== Rename postcss.config.js ke .cjs jika menggunakan bun ========== //
33
42
  function updatePostcssConfig(projectPath) {
34
43
  const oldPath = path.join(projectPath, "postcss.config.js");
35
44
  const newPath = path.join(projectPath, "postcss.config.cjs");
@@ -39,7 +48,7 @@ function updatePostcssConfig(projectPath) {
39
48
  }
40
49
  }
41
50
 
42
- // Tampilan awal
51
+ // ========== ASCII welcome art ========== //
43
52
  function displayAsciiArt() {
44
53
  return new Promise((resolve, reject) => {
45
54
  figlet.text("DocuBook", { horizontalLayout: "full" }, (err, data) => {
@@ -54,7 +63,7 @@ function displayWelcomeMessage() {
54
63
  console.log(chalk.white("DocuBook Installer"));
55
64
  }
56
65
 
57
- // Simulasi progress bar setup
66
+ // ========== Simulasi animasi setup ========== //
58
67
  async function simulateInstallation() {
59
68
  const bar = new cliProgress.SingleBar(
60
69
  {
@@ -73,6 +82,7 @@ async function simulateInstallation() {
73
82
  bar.stop();
74
83
  }
75
84
 
85
+ // ========== Jika user batal install, tunjukkan langkah manual ========== //
76
86
  function manualSteps(projectDirectory, packageManager) {
77
87
  const manualInstructions = `
78
88
  You chose not to continue with the installation.
@@ -85,21 +95,23 @@ function manualSteps(projectDirectory, packageManager) {
85
95
 
86
96
  console.log(
87
97
  boxen(manualInstructions, {
88
- padding: 1,
98
+ padding: 0.5,
89
99
  borderStyle: "round",
90
100
  borderColor: "cyan",
91
101
  })
92
102
  );
93
103
  }
94
104
 
105
+ // ========== Entry CLI ========== //
95
106
  program
96
- .version("1.8.5")
107
+ .version("1.8.6")
97
108
  .description("CLI to create a new Docubook project")
98
109
  .argument("[project-directory]", "Directory to create the new Docubook project")
99
110
  .action(async (projectDirectory) => {
100
111
  await displayAsciiArt();
101
112
  displayWelcomeMessage();
102
113
 
114
+ // Tanya nama direktori jika belum diisi
103
115
  if (!projectDirectory) {
104
116
  const { directoryName } = await inquirer.prompt([
105
117
  {
@@ -112,21 +124,24 @@ program
112
124
  projectDirectory = directoryName;
113
125
  }
114
126
 
115
- let { packageManager } = await inquirer.prompt([
116
- {
127
+ // Pilihan package manager
128
+ const { packageManager } = await inquirer.prompt([
129
+ {
117
130
  type: "list",
118
131
  name: "packageManager",
119
132
  message: "Choose a package manager:",
120
133
  choices: ["npm", "pnpm", "yarn", "bun"],
121
134
  default: "npm",
122
- },
135
+ },
123
136
  ]);
124
137
 
125
- if (!checkInstalled(packageManager)) {
126
- log.warn(`${packageManager} is not installed. Falling back to npm.`);
127
- packageManager = "npm";
138
+ const version = getPackageManagerVersion(packageManager);
139
+ if (!version) {
140
+ log.error(`${packageManager} is not installed on your system.`);
141
+ process.exit(1);
128
142
  }
129
143
 
144
+ // Clone repositori starter
130
145
  const repo = "https://gitlab.com/mywildancloud/docubook.git";
131
146
  const branch = "starter";
132
147
  const projectPath = path.resolve(process.cwd(), projectDirectory);
@@ -137,13 +152,26 @@ program
137
152
  execSync(cloneCommand);
138
153
  spinner.succeed(`Project created in ${projectDirectory}/`);
139
154
 
140
- if (packageManager === "bun" && checkInstalled("bun")) {
141
- updatePostcssConfig(projectPath);
142
- }
155
+ // Rename config jika menggunakan bun
156
+ if (packageManager === "bun") {
157
+ updatePostcssConfig(projectPath);
158
+ }
143
159
 
160
+ // Validasi packageManager dari project yang di-clone
144
161
  const pkgPath = path.join(projectPath, "package.json");
145
162
  if (fs.existsSync(pkgPath)) {
146
163
  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
164
+ const existingPM = pkg.packageManager?.split("@")[0];
165
+
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
+
147
175
  console.log(
148
176
  chalk.green(
149
177
  `=================\nDocuBook v${pkg.version}\n=================`
@@ -151,7 +179,7 @@ program
151
179
  );
152
180
  }
153
181
 
154
- // Tanya apakah pengguna ingin melanjutkan instalasi
182
+ // Tanya apakah lanjut install dependencies
155
183
  const { continueInstallation } = await inquirer.prompt([
156
184
  {
157
185
  type: "confirm",
@@ -168,7 +196,7 @@ program
168
196
 
169
197
  log.info("Installing dependencies...");
170
198
  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."));
199
+ console.log(chalk.white("When you install the package manager, the installation speed depends on the hardware you have."));
172
200
  const installSpinner = ora(`Using ${packageManager}...`).start();
173
201
 
174
202
  try {
@@ -181,6 +209,7 @@ program
181
209
 
182
210
  await simulateInstallation();
183
211
 
212
+ // Saran langkah selanjutnya
184
213
  console.log(
185
214
  boxen(
186
215
  `Next Steps:\n\n` +
@@ -188,7 +217,7 @@ program
188
217
  `2. ${chalk.cyan(`${packageManager} install (if not automatically installed)`)}\n` +
189
218
  `3. ${chalk.cyan(`${packageManager} run dev`)}`,
190
219
  {
191
- padding: 1,
220
+ padding: 0.5,
192
221
  borderStyle: "round",
193
222
  borderColor: "cyan",
194
223
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docubook/create",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {