@dolphjs/cli 1.1.17 → 1.1.18

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.
@@ -33,19 +33,12 @@ export class ${capitalizedString}Component {}
33
33
  const fileContent = readFileSync(componentPath, "utf8");
34
34
  const newComponentInstance = `${capitalizedString}Controller`;
35
35
  if (!fileContent.includes(importStatement)) {
36
- const controllersArrayMatch = fileContent.match(/@Component\(\s*{\s*controllers:\s*\[([^\]]*)\]\s*}\s*\)/);
37
- if (controllersArrayMatch) {
38
- const existingCode = controllersArrayMatch[1].trim();
39
- let fileContents;
40
- fileContents = fileContent.replace(existingCode, `${existingCode.length > 0
41
- ? existingCode + `, ${newComponentInstance}`
42
- : newComponentInstance}`);
43
- const updatedContents = `${importStatement}\n${fileContents}`;
44
- writeFileSync(componentPath, updatedContents);
45
- }
36
+ // If import statement is not present, add it along with the new controller
37
+ const updatedContents = `${importStatement}\n${fileContent.replace(/@Component\(\s*{\s*controllers:\s*\[([^\]]*)\]\s*}\s*\)/, `@Component({ controllers: [${newComponentInstance}] })`)}`;
38
+ writeFileSync(componentPath, updatedContents);
46
39
  }
47
- if (fileContent.includes(`const dolph`)) {
48
- // add new controller class to the existing array
40
+ else if (fileContent.includes(`const dolph`)) {
41
+ // If import statement is present and contains `const dolph`
49
42
  const controllersArrayMatch = fileContent.match(/@Component\(\s*{\s*controllers:\s*\[([^\]]*)\]\s*}\s*\)/);
50
43
  if (controllersArrayMatch) {
51
44
  const existingCode = controllersArrayMatch[1].trim();
@@ -58,10 +51,11 @@ export class ${capitalizedString}Component {}
58
51
  }
59
52
  }
60
53
  }
61
- dolphMsg.info(`registerd ${capitalizedString}Controller in ${capitalizedString}Component`);
54
+ dolphMsg.info(`registered ${capitalizedString}Controller in ${capitalizedString}Component`);
62
55
  process.exit(0);
63
56
  }
64
- catch (e) {
65
- dolphMsg.errorRed(e.toString());
57
+ catch (error) {
58
+ console.error(error);
59
+ process.exit(1);
66
60
  }
67
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolphjs/cli",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "description": "The dolphjs-cli is a tool for efficient intialization and management of a dolphjs project",
5
5
  "main": "./dist/index.js",
6
6
  "repository": "https://github.com/dolphjs/dolph-cli.git",