@hapico/cli 0.0.22 → 0.0.23

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.
package/bin/index.js CHANGED
@@ -123,6 +123,18 @@ const tryJSONParse = (str) => {
123
123
  }
124
124
  };
125
125
  exports.tryJSONParse = tryJSONParse;
126
+ // only support .ts, .tsx, .js, .jsx, .json, .css, .html, .env files
127
+ const supportedExtensions = [
128
+ ".ts",
129
+ ".tsx",
130
+ ".js",
131
+ ".jsx",
132
+ ".json",
133
+ ".css",
134
+ ".html",
135
+ ".env",
136
+ ];
137
+ const ignoreFolders = ["node_modules", ".git", ".hg", ".svn"];
126
138
  const compileES5 = (code, filePath) => {
127
139
  if (filePath && !filePath.endsWith(".ts") && !filePath.endsWith(".tsx")) {
128
140
  return code;
@@ -143,7 +155,7 @@ const compileES5 = (code, filePath) => {
143
155
  return result.code;
144
156
  }
145
157
  catch (error) {
146
- console.log(chalk_1.default.red(`Error compiling code: ${error === null || error === void 0 ? void 0 : error.message}`));
158
+ console.log(chalk_1.default.red(`Error compiling code at ${filePath}`));
147
159
  return "";
148
160
  }
149
161
  };
@@ -172,12 +184,23 @@ class FileManager {
172
184
  traverseDirectory(fullPath);
173
185
  }
174
186
  else if (entry.isFile()) {
187
+ // skip các file trong thư mục bị ignore
188
+ if (ignoreFolders.some((folder) => fullPath.includes(folder))) {
189
+ return;
190
+ }
191
+ // chỉ hổ trợ các files nằm trong ./src
192
+ if (!fullPath.includes("/src/") && !fullPath.includes("\\src\\")) {
193
+ return;
194
+ }
175
195
  const content = fs.readFileSync(fullPath, { encoding: "utf8" });
176
- files.push({
177
- path: this.replaceSplashWithSeparator(fullPath.replace(this.basePath + path.sep, "./")),
178
- content,
179
- es5: (_a = (0, exports.compileES5)(content, fullPath)) !== null && _a !== void 0 ? _a : "",
180
- });
196
+ const extname = path.extname(fullPath);
197
+ if (supportedExtensions.includes(extname)) {
198
+ files.push({
199
+ path: this.replaceSplashWithSeparator(fullPath.replace(this.basePath + path.sep, "./")),
200
+ content,
201
+ es5: (_a = (0, exports.compileES5)(content, fullPath)) !== null && _a !== void 0 ? _a : "",
202
+ });
203
+ }
181
204
  }
182
205
  });
183
206
  };
@@ -371,7 +394,7 @@ class RoomState {
371
394
  return this.isConnected;
372
395
  }
373
396
  }
374
- commander_1.program.version("0.0.22").description("Hapico CLI for project management");
397
+ commander_1.program.version("0.0.23").description("Hapico CLI for project management");
375
398
  commander_1.program
376
399
  .command("clone <id>")
377
400
  .description("Clone a project by ID")
@@ -462,7 +485,7 @@ commander_1.program
462
485
  commander_1.program
463
486
  .command("dev")
464
487
  .description("Start the project in development mode")
465
- .option('--zversion <version>', 'Zalo version for QR code', '75')
488
+ .option("--zversion <version>", "Zalo version for QR code")
466
489
  .action((options) => {
467
490
  var _a;
468
491
  const { accessToken } = getStoredToken();
@@ -535,19 +558,10 @@ commander_1.program
535
558
  ".jsx",
536
559
  ".json",
537
560
  ".css",
538
- ".html",
539
561
  ".env",
540
562
  ".env.local",
541
563
  ".env.development",
542
564
  ".env.production",
543
- ".jsonc",
544
- ".yml",
545
- ".yaml",
546
- ".md",
547
- ".markdown",
548
- ".txt",
549
- ".xml",
550
- ".config",
551
565
  ];
552
566
  const filteredFiles = initialFiles.filter((file) => {
553
567
  return supportExtensions.some((ext) => file.path.endsWith(ext));
@@ -586,12 +600,21 @@ commander_1.program
586
600
  return;
587
601
  }
588
602
  const projectType = project.data.type || "view";
589
- const zversion = options.zversion || '75';
603
+ const zversion = options.zversion;
590
604
  if (projectType === "zalominiapp") {
591
- qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version=${zversion}`, { small: true }, (qrcode) => {
592
- console.log(chalk_1.default.cyan("📱 Scan this QR code to connect to the project:"));
593
- console.log(qrcode);
594
- });
605
+ console.log("zversion", zversion);
606
+ if (!zversion) {
607
+ qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}`, { small: true }, (qrcode) => {
608
+ console.log(chalk_1.default.cyan("📱 Scan this QR code to connect to the project:"));
609
+ console.log(qrcode);
610
+ });
611
+ }
612
+ else {
613
+ qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version=${zversion}`, { small: true }, (qrcode) => {
614
+ console.log(chalk_1.default.cyan("📱 Scan this QR code to connect to the project:"));
615
+ console.log(qrcode);
616
+ });
617
+ }
595
618
  return;
596
619
  }
597
620
  else {
package/dist/index.js CHANGED
@@ -123,6 +123,18 @@ const tryJSONParse = (str) => {
123
123
  }
124
124
  };
125
125
  exports.tryJSONParse = tryJSONParse;
126
+ // only support .ts, .tsx, .js, .jsx, .json, .css, .html, .env files
127
+ const supportedExtensions = [
128
+ ".ts",
129
+ ".tsx",
130
+ ".js",
131
+ ".jsx",
132
+ ".json",
133
+ ".css",
134
+ ".html",
135
+ ".env",
136
+ ];
137
+ const ignoreFolders = ["node_modules", ".git", ".hg", ".svn"];
126
138
  const compileES5 = (code, filePath) => {
127
139
  if (filePath && !filePath.endsWith(".ts") && !filePath.endsWith(".tsx")) {
128
140
  return code;
@@ -143,7 +155,7 @@ const compileES5 = (code, filePath) => {
143
155
  return result.code;
144
156
  }
145
157
  catch (error) {
146
- console.log(chalk_1.default.red(`Error compiling code: ${error === null || error === void 0 ? void 0 : error.message}`));
158
+ console.log(chalk_1.default.red(`Error compiling code at ${filePath}`));
147
159
  return "";
148
160
  }
149
161
  };
@@ -172,12 +184,23 @@ class FileManager {
172
184
  traverseDirectory(fullPath);
173
185
  }
174
186
  else if (entry.isFile()) {
187
+ // skip các file trong thư mục bị ignore
188
+ if (ignoreFolders.some((folder) => fullPath.includes(folder))) {
189
+ return;
190
+ }
191
+ // chỉ hổ trợ các files nằm trong ./src
192
+ if (!fullPath.includes("/src/") && !fullPath.includes("\\src\\")) {
193
+ return;
194
+ }
175
195
  const content = fs.readFileSync(fullPath, { encoding: "utf8" });
176
- files.push({
177
- path: this.replaceSplashWithSeparator(fullPath.replace(this.basePath + path.sep, "./")),
178
- content,
179
- es5: (_a = (0, exports.compileES5)(content, fullPath)) !== null && _a !== void 0 ? _a : "",
180
- });
196
+ const extname = path.extname(fullPath);
197
+ if (supportedExtensions.includes(extname)) {
198
+ files.push({
199
+ path: this.replaceSplashWithSeparator(fullPath.replace(this.basePath + path.sep, "./")),
200
+ content,
201
+ es5: (_a = (0, exports.compileES5)(content, fullPath)) !== null && _a !== void 0 ? _a : "",
202
+ });
203
+ }
181
204
  }
182
205
  });
183
206
  };
@@ -371,7 +394,7 @@ class RoomState {
371
394
  return this.isConnected;
372
395
  }
373
396
  }
374
- commander_1.program.version("0.0.22").description("Hapico CLI for project management");
397
+ commander_1.program.version("0.0.23").description("Hapico CLI for project management");
375
398
  commander_1.program
376
399
  .command("clone <id>")
377
400
  .description("Clone a project by ID")
@@ -462,7 +485,7 @@ commander_1.program
462
485
  commander_1.program
463
486
  .command("dev")
464
487
  .description("Start the project in development mode")
465
- .option('--zversion <version>', 'Zalo version for QR code', '75')
488
+ .option("--zversion <version>", "Zalo version for QR code")
466
489
  .action((options) => {
467
490
  var _a;
468
491
  const { accessToken } = getStoredToken();
@@ -535,19 +558,10 @@ commander_1.program
535
558
  ".jsx",
536
559
  ".json",
537
560
  ".css",
538
- ".html",
539
561
  ".env",
540
562
  ".env.local",
541
563
  ".env.development",
542
564
  ".env.production",
543
- ".jsonc",
544
- ".yml",
545
- ".yaml",
546
- ".md",
547
- ".markdown",
548
- ".txt",
549
- ".xml",
550
- ".config",
551
565
  ];
552
566
  const filteredFiles = initialFiles.filter((file) => {
553
567
  return supportExtensions.some((ext) => file.path.endsWith(ext));
@@ -586,12 +600,21 @@ commander_1.program
586
600
  return;
587
601
  }
588
602
  const projectType = project.data.type || "view";
589
- const zversion = options.zversion || '75';
603
+ const zversion = options.zversion;
590
604
  if (projectType === "zalominiapp") {
591
- qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version=${zversion}`, { small: true }, (qrcode) => {
592
- console.log(chalk_1.default.cyan("📱 Scan this QR code to connect to the project:"));
593
- console.log(qrcode);
594
- });
605
+ console.log("zversion", zversion);
606
+ if (!zversion) {
607
+ qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}`, { small: true }, (qrcode) => {
608
+ console.log(chalk_1.default.cyan("📱 Scan this QR code to connect to the project:"));
609
+ console.log(qrcode);
610
+ });
611
+ }
612
+ else {
613
+ qrcode_terminal_1.default.generate(`https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version=${zversion}`, { small: true }, (qrcode) => {
614
+ console.log(chalk_1.default.cyan("📱 Scan this QR code to connect to the project:"));
615
+ console.log(qrcode);
616
+ });
617
+ }
595
618
  return;
596
619
  }
597
620
  else {
package/index.ts CHANGED
@@ -130,6 +130,20 @@ export const tryJSONParse = (str: string): any => {
130
130
  }
131
131
  };
132
132
 
133
+ // only support .ts, .tsx, .js, .jsx, .json, .css, .html, .env files
134
+ const supportedExtensions = [
135
+ ".ts",
136
+ ".tsx",
137
+ ".js",
138
+ ".jsx",
139
+ ".json",
140
+ ".css",
141
+ ".html",
142
+ ".env",
143
+ ];
144
+
145
+ const ignoreFolders = ["node_modules", ".git", ".hg", ".svn"];
146
+
133
147
  export const compileES5 = (code: string, filePath?: string) => {
134
148
  if (filePath && !filePath.endsWith(".ts") && !filePath.endsWith(".tsx")) {
135
149
  return code;
@@ -151,7 +165,7 @@ export const compileES5 = (code: string, filePath?: string) => {
151
165
  compileCache.set(code, result.code || "");
152
166
  return result.code;
153
167
  } catch (error: any) {
154
- console.log(chalk.red(`Error compiling code: ${error?.message}`));
168
+ console.log(chalk.red(`Error compiling code at ${filePath}`));
155
169
  return "";
156
170
  }
157
171
  };
@@ -188,14 +202,27 @@ class FileManager {
188
202
  if (entry.isDirectory()) {
189
203
  traverseDirectory(fullPath);
190
204
  } else if (entry.isFile()) {
205
+ // skip các file trong thư mục bị ignore
206
+ if (ignoreFolders.some((folder) => fullPath.includes(folder))) {
207
+ return;
208
+ }
209
+
210
+ // chỉ hổ trợ các files nằm trong ./src
211
+ if (!fullPath.includes("/src/") && !fullPath.includes("\\src\\")) {
212
+ return;
213
+ }
214
+
191
215
  const content = fs.readFileSync(fullPath, { encoding: "utf8" });
192
- files.push({
193
- path: this.replaceSplashWithSeparator(
194
- fullPath.replace(this.basePath + path.sep, "./")
195
- ),
196
- content,
197
- es5: compileES5(content, fullPath) ?? "",
198
- });
216
+ const extname = path.extname(fullPath);
217
+ if (supportedExtensions.includes(extname)) {
218
+ files.push({
219
+ path: this.replaceSplashWithSeparator(
220
+ fullPath.replace(this.basePath + path.sep, "./")
221
+ ),
222
+ content,
223
+ es5: compileES5(content, fullPath) ?? "",
224
+ });
225
+ }
199
226
  }
200
227
  });
201
228
  };
@@ -447,7 +474,7 @@ class RoomState {
447
474
  }
448
475
  }
449
476
 
450
- program.version("0.0.22").description("Hapico CLI for project management");
477
+ program.version("0.0.23").description("Hapico CLI for project management");
451
478
 
452
479
  program
453
480
  .command("clone <id>")
@@ -549,18 +576,23 @@ program
549
576
 
550
577
  const pullCode = pullResponse?.data?.code;
551
578
  if (!pullCode) {
552
- pullSpinner.info(chalk.cyan("No draft version found – using published version."));
579
+ pullSpinner.info(
580
+ chalk.cyan("No draft version found – using published version.")
581
+ );
553
582
  } else {
554
583
  const pullDecompressed = pako.inflate(
555
584
  Uint8Array.from(atob(pullCode), (c) => c.charCodeAt(0)),
556
585
  { to: "string" }
557
586
  );
558
- const latestFiles: FileContent[] = tryJSONParse(pullDecompressed)?.files || [];
587
+ const latestFiles: FileContent[] =
588
+ tryJSONParse(pullDecompressed)?.files || [];
559
589
 
560
590
  const fileManager = new FileManager(path.join(outputDir, "src"));
561
591
  fileManager.syncFiles(latestFiles);
562
592
 
563
- pullSpinner.succeed(chalk.green("✓ Latest changes pulled successfully!"));
593
+ pullSpinner.succeed(
594
+ chalk.green("✓ Latest changes pulled successfully!")
595
+ );
564
596
  }
565
597
  } catch (pullErr: any) {
566
598
  pullSpinner.warn(
@@ -584,7 +616,7 @@ program
584
616
  program
585
617
  .command("dev")
586
618
  .description("Start the project in development mode")
587
- .option('--zversion <version>', 'Zalo version for QR code', '75')
619
+ .option("--zversion <version>", "Zalo version for QR code")
588
620
  .action((options) => {
589
621
  const { accessToken } = getStoredToken();
590
622
  if (!accessToken) {
@@ -680,19 +712,10 @@ program
680
712
  ".jsx",
681
713
  ".json",
682
714
  ".css",
683
- ".html",
684
715
  ".env",
685
716
  ".env.local",
686
717
  ".env.development",
687
718
  ".env.production",
688
- ".jsonc",
689
- ".yml",
690
- ".yaml",
691
- ".md",
692
- ".markdown",
693
- ".txt",
694
- ".xml",
695
- ".config",
696
719
  ];
697
720
  const filteredFiles = initialFiles.filter((file) => {
698
721
  return supportExtensions.some((ext) => file.path.endsWith(ext));
@@ -748,19 +771,33 @@ program
748
771
  }
749
772
 
750
773
  const projectType = project.data.type || "view";
751
- const zversion = options.zversion || '75';
774
+ const zversion = options.zversion;
752
775
 
753
776
  if (projectType === "zalominiapp") {
754
- QRCode.generate(
755
- `https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version=${zversion}`,
756
- { small: true },
757
- (qrcode) => {
758
- console.log(
759
- chalk.cyan("📱 Scan this QR code to connect to the project:")
760
- );
761
- console.log(qrcode);
762
- }
763
- );
777
+ console.log("zversion", zversion);
778
+ if (!zversion) {
779
+ QRCode.generate(
780
+ `https://zalo.me/s/3218692650896662017/player/${projectId}`,
781
+ { small: true },
782
+ (qrcode) => {
783
+ console.log(
784
+ chalk.cyan("📱 Scan this QR code to connect to the project:")
785
+ );
786
+ console.log(qrcode);
787
+ }
788
+ );
789
+ } else {
790
+ QRCode.generate(
791
+ `https://zalo.me/s/3218692650896662017/player/${projectId}?env=TESTING&version=${zversion}`,
792
+ { small: true },
793
+ (qrcode) => {
794
+ console.log(
795
+ chalk.cyan("📱 Scan this QR code to connect to the project:")
796
+ );
797
+ console.log(qrcode);
798
+ }
799
+ );
800
+ }
764
801
  return;
765
802
  } else {
766
803
  const previewUrl = `https://com.ai.vn/dev_preview/${projectId}`;
@@ -1533,4 +1570,4 @@ ${file.content}
1533
1570
  console.log(chalk.green(`✓ File list saved to ${outputFile}`));
1534
1571
  });
1535
1572
 
1536
- program.parse(process.argv);
1573
+ program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hapico/cli",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "A simple CLI tool for project management",
5
5
  "main": "index.js",
6
6
  "bin": {