@dolphjs/cli 1.0.25 → 1.1.0

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.
@@ -4,15 +4,10 @@ import chalk from "chalk";
4
4
  import { getRootDirectory } from "../utils/get_root_dir_path.js";
5
5
  import { readConfig } from "../utils/read_user_config_path.js";
6
6
  import { join } from "path";
7
- /**
8
- * TODO: add child2.on('error', (err) => {
9
- console.error('Error spawning child process:', err);
10
- });
11
- */
12
7
  let fileExtension = "";
13
8
  let indexFilePath = "";
14
9
  export const startApp = () => {
15
- console.log(chalk.bold(`${chalk.yellow("[DOLPH INFO]: ")} ${chalk.yellowBright("starting dolph server ...")}`));
10
+ console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("starting dolph server ...")}`);
16
11
  fileExtension = readConfig().language;
17
12
  indexFilePath = join(getRootDirectory(), "src", `server.${fileExtension}`);
18
13
  const additionalOptions = [
@@ -21,41 +16,78 @@ export const startApp = () => {
21
16
  "--transpile-only",
22
17
  ];
23
18
  const spawnArgs = [...additionalOptions, indexFilePath];
24
- console.log(chalk.bold(`${chalk.green("[DOLPH INFO]: ")} ${chalk.greenBright("starting dolph server ...")}`));
19
+ console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("starting dolph server ...")}`);
25
20
  const child = spawn(fileExtension === "ts" ? "ts-node" : "node", spawnArgs, {
26
21
  stdio: "inherit",
27
22
  });
23
+ child.on("error", (err) => {
24
+ `${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`;
25
+ process.exit(1);
26
+ });
28
27
  child.on("close", (code) => {
29
28
  if (code === 1) {
30
- console.log(chalk.bold(`${chalk.red("[DOLPH ERROR]: ")} ${chalk.redBright("exiting watch mode ...")}`));
29
+ `${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting watch mode ...")}`;
31
30
  process.exit(1);
32
31
  }
33
32
  });
34
33
  };
35
- export const startProdApp = () => {
34
+ export const buildApp = () => {
36
35
  fileExtension = readConfig().language;
37
36
  if (fileExtension === "ts") {
38
- console.log(chalk.bold(`${chalk.yellow("[DOLPH INFO]: ")} ${chalk.yellowBright("compiling to javascript ...")}`));
37
+ console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("compiling to javascript ...")}`);
38
+ indexFilePath = join(getRootDirectory(), "src", "server.ts");
39
+ const spawnArgs = ["src", "-d", "app", "--source-maps", "--copy-files"];
40
+ const child = spawn("swc", spawnArgs, {
41
+ stdio: "inherit",
42
+ });
43
+ console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("compilation successful")}`);
44
+ child.on("error", (err) => {
45
+ `${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`;
46
+ process.exit(1);
47
+ });
48
+ child.on("close", (code) => {
49
+ if (code === 1) {
50
+ console.log(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting compilation ...")}`);
51
+ process.exit(1);
52
+ }
53
+ });
39
54
  }
40
- indexFilePath = join(getRootDirectory(), "src", `server.${fileExtension}`);
41
- const spawnArgs = ["src", "-d", "app", "--source-maps", "--copy-files"];
42
- const child = spawn("swc", spawnArgs, {
43
- stdio: "inherit",
44
- });
45
- child.on("close", (code) => {
46
- if (code === 1) {
47
- console.log(chalk.bold(`${chalk.red("[DOLPH ERROR]: ")} ${chalk.redBright("exiting compilation ...")}`));
55
+ else {
56
+ console.log(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("cannot compile javascript file, exiting compilation ...")}`);
57
+ }
58
+ };
59
+ export const startProdApp = () => {
60
+ fileExtension = readConfig().language;
61
+ if (fileExtension === "ts") {
62
+ console.log(`${chalk.bold(chalk.yellow("[DOLPH INFO]: "))} ${chalk.yellowBright("compiling to javascript ...")}`);
63
+ indexFilePath = join(getRootDirectory(), "src", `server.${fileExtension}`);
64
+ const spawnArgs = ["src", "-d", "app", "--source-maps", "--copy-files"];
65
+ const child = spawn("swc", spawnArgs, {
66
+ stdio: "inherit",
67
+ });
68
+ child.on("error", (err) => {
69
+ `${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`;
48
70
  process.exit(1);
49
- }
50
- });
71
+ });
72
+ child.on("close", (code) => {
73
+ if (code === 1) {
74
+ console.log(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting compilation ...")}`);
75
+ process.exit(1);
76
+ }
77
+ });
78
+ }
51
79
  indexFilePath = join(getRootDirectory(), "app", `server.js`);
52
- console.log(chalk.bold(`${chalk.green("[DOLPH INFO]: ")} ${chalk.greenBright("starting dolph server ...")}`));
80
+ console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("starting dolph server ...")}`);
53
81
  const child2 = spawn("node", [indexFilePath], {
54
82
  stdio: "inherit",
55
83
  });
84
+ child2.on("error", (err) => {
85
+ `${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright(`${err}`)}`;
86
+ process.exit(1);
87
+ });
56
88
  child2.on("close", (code) => {
57
89
  if (code === 1) {
58
- console.log(chalk.bold(`${chalk.red("[DOLPH ERROR]: ")} ${chalk.redBright("exiting watch mode ...")}`));
90
+ `${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting watch mode ...")}`;
59
91
  process.exit(1);
60
92
  }
61
93
  });
@@ -68,12 +100,16 @@ const watcher = chokidar.watch(indexFilePath, {
68
100
  let isWatcherActive = false;
69
101
  export const watchFile = () => {
70
102
  if (!isWatcherActive) {
71
- console.log(chalk.bold(`${chalk.green("[DOLPH INFO]: ")} ${chalk.greenBright("watching files for changes ...")}`));
103
+ console.log(`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("watching files for changes ...")}`);
72
104
  isWatcherActive = true;
73
105
  fileExtension = readConfig().language;
106
+ const srcDirectory = join(getRootDirectory(), "src");
107
+ watcher.add(srcDirectory);
74
108
  watcher.on("all", (_event, path) => {
75
- chalk.bold(`${chalk.green("[DOLPH INFO]: ")} ${chalk.greenBright("file changed" + `[${path}]`)}`);
76
- startApp();
109
+ `${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("file changed" + `[${path}]`)}`;
110
+ if (path.endsWith(".ts") || path.endsWith(".js")) {
111
+ startApp();
112
+ }
77
113
  });
78
114
  process.on("SIGINT", () => {
79
115
  watcher.close();
@@ -81,8 +117,6 @@ export const watchFile = () => {
81
117
  });
82
118
  }
83
119
  else {
84
- console.log(chalk.bold(`${chalk.red("[DOLPH ERROR]: ")} ${chalk.redBright("watcher is already active.")}`));
120
+ console.log(`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("watcher is already active.")}`);
85
121
  }
86
122
  };
87
- // startApp();
88
- // watchFile();
@@ -1,12 +1,16 @@
1
1
  import { program } from "commander";
2
- import { startProdApp, watchFile } from "./watcher.js";
2
+ import { buildApp, startProdApp, watchFile } from "./watcher.js";
3
3
  export const watcherConfig = () => {
4
4
  program
5
5
  .command("start")
6
- .description("starts the dolphjs application")
6
+ .description("starts the dolph application")
7
7
  .action(() => startProdApp());
8
8
  program
9
9
  .command("watch")
10
- .description("starts the dolphjs application in watch mode")
10
+ .description("starts the dolph application in watch mode")
11
11
  .action(() => watchFile());
12
+ program
13
+ .command("build")
14
+ .description("compile a typescript project to javascript")
15
+ .action(() => buildApp());
12
16
  };
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { configurePackage } from "./utils/read_user_config.js";
7
7
  import { InitDolphCli } from "./utils/package_init.js";
8
8
  import { packageGenerator } from "./utils/package_generator.js";
9
9
  import { watcherConfig } from "./daemon/watcherConfig.js";
10
- figlet.text("dolphjs cli", {
10
+ figlet.text("dolph cli", {
11
11
  font: "Big",
12
12
  horizontalLayout: "default",
13
13
  verticalLayout: "default",
@@ -2,9 +2,9 @@ import { existsSync } from "fs";
2
2
  import path from "path";
3
3
  export const getUserConfigFilePath = () => {
4
4
  const userConfigFolderPath = path.join(process.cwd());
5
- const userConfigFilePath = path.join(userConfigFolderPath, "dolph-cli.yaml");
5
+ const userConfigFilePath = path.join(userConfigFolderPath, "dolph_cli.yaml");
6
6
  if (existsSync(userConfigFilePath)) {
7
7
  return userConfigFilePath;
8
8
  }
9
- return path.join(userConfigFilePath, "../../", "dolph-cli.yaml");
9
+ return path.join(userConfigFilePath, "../../", "dolph_cli.yaml");
10
10
  };
@@ -23,7 +23,7 @@ export const initDolphCli = (appname) => {
23
23
  }
24
24
  const configFolderPath = path.join(process.cwd());
25
25
  const srcPath = path.join(configFolderPath, "src");
26
- const userConfigFilePath = path.join(configFolderPath, "dolph-cli.yaml");
26
+ const userConfigFilePath = path.join(configFolderPath, "dolph_cli.yaml");
27
27
  if (!existsSync(configFolderPath)) {
28
28
  mkdirSync(configFolderPath);
29
29
  }
@@ -82,6 +82,7 @@ export const initDolphCli = (appname) => {
82
82
  writeGitignore();
83
83
  console.log(chalk.green(chalk.bold("dolph cli configurations have been initialized successfully 😎.")));
84
84
  console.log(chalk.green(chalk.bold("run yarn install to install dependencies in project directory and start coding 😉.")));
85
+ process.exit(0);
85
86
  });
86
87
  }
87
88
  else {
@@ -2,6 +2,6 @@ import chalk from "chalk";
2
2
  import { program } from "commander";
3
3
  export const packageDescription = () => {
4
4
  program
5
- .version("1.0.3")
5
+ .version("1.1.0")
6
6
  .description(chalk.cyan("The dolphjs-cli is a tool for efficient intialization and management of a dolphjs project"));
7
7
  };
@@ -4,7 +4,7 @@ export const InitDolphCli = () => {
4
4
  program
5
5
  .command("new <project-name>")
6
6
  .alias("nw")
7
- .description("Creates a new dolphjs app")
7
+ .description("Creates a new dolph app")
8
8
  .action((appname) => {
9
9
  initDolphCli(appname);
10
10
  });
@@ -61,7 +61,7 @@ export const configurePackage = () => {
61
61
  return;
62
62
  }
63
63
  if (Object.keys(options).length === 0) {
64
- console.log(chalk.yellow(chalk.bold(`No configurations applied, run ${chalk.white("dolph-cli config --help")} to see available commands`)));
64
+ console.log(chalk.yellow(chalk.bold(`No configurations applied, run ${chalk.white("dolph config --help")} to see available commands`)));
65
65
  }
66
66
  });
67
67
  };
@@ -12,7 +12,7 @@ export const readConfig = () => {
12
12
  }
13
13
  catch (e) {
14
14
  console.log(e);
15
- console.log(chalk.bold(chalk.red("Error encountered reading config file, please run 'dolph-cli tr' to initialize config file 🥹")));
15
+ console.log(chalk.bold(chalk.red("Error encountered reading config file, please run 'dolph tr' to initialize config file 🥹")));
16
16
  process.exit(1);
17
17
  return {};
18
18
  }
@@ -13,14 +13,13 @@ export function writePackageJsonFile(name, extension) {
13
13
  "node": ">=18.0.0"
14
14
  },
15
15
  "scripts": {
16
- "dev:start": "cross-env NODE_ENV=development nodemon",
16
+ "dev:start": "dolph watch",
17
17
  "dev:docker:start": "docker-compose -f docker-compose-dev.yml up",
18
18
  "dev:docker:stop": "docker-compose -f docker-compose-dev.yml down",
19
- "build": "swc src -d app --source-maps --copy-files",
19
+ "build": "dolph build",
20
20
  "build:tsc": "tsc && tsc-alias",
21
- "prod:start": "node app/server.js",
22
- "clean": "rm -r app && rm -r logs",
23
- "start": "npm run build && npm run prod:start"
21
+ "start": "dolph start",
22
+ "clean": "rm -r app && rm -r logs"
24
23
  },
25
24
  "dependencies": {
26
25
  "@dolphjs/dolph": "^1.1.0"
@@ -30,7 +29,6 @@ export function writePackageJsonFile(name, extension) {
30
29
  "@swc/core": "^1.3.91",
31
30
  "@types/express": "^4.17.18",
32
31
  "@types/node": "^20.8.2",
33
- "cross-env": "^7.0.3",
34
32
  "ts-node": "^10.9.1",
35
33
  "tsc-alias": "^1.8.8",
36
34
  "tsconfig-paths": "^4.2.0",
@@ -48,18 +46,14 @@ export function writePackageJsonFile(name, extension) {
48
46
  "node": ">=18.0.0"
49
47
  },
50
48
  "scripts": {
51
- "dev:start": "cross-env NODE_ENV=development nodemon",
49
+ "dev:start": "dolph watch",
52
50
  "dev:docker:start": "docker-compose -f docker-compose-dev.yml up",
53
51
  "dev:docker:stop": "docker-compose -f docker-compose-dev.yml down",
54
- "prod:start": "node src/server.js",
55
52
  "clean": "rm -r logs",
56
- "start": "npm run prod:start"
53
+ "start": "dolph start"
57
54
  },
58
55
  "dependencies": {
59
56
  "@dolphjs/dolph": "^1.1.0"
60
- },
61
- "devDependencies": {
62
- "cross-env": "^7.0.3"
63
57
  }
64
58
  }
65
59
  `;
@@ -10,7 +10,7 @@ export const writeConfig = (config) => {
10
10
  console.log(chalk.green("Configurations saved successfully! 😎."));
11
11
  }
12
12
  catch (e) {
13
- console.log(chalk.bold(chalk.red("Error encountered reading config file, please run 'dolph-cli tr' to initialize config file 🥹")));
13
+ console.log(chalk.bold(chalk.red("Error encountered reading config file, please run 'dolph tr' to initialize config file 🥹")));
14
14
  process.exit(1);
15
15
  }
16
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolphjs/cli",
3
- "version": "1.0.25",
3
+ "version": "1.1.0",
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",
@@ -35,7 +35,7 @@
35
35
  "dist/**/*"
36
36
  ],
37
37
  "bin": {
38
- "dolph-cli": "./dist/index.js",
38
+ "dolph": "./dist/index.js",
39
39
  "dc": "./dist/index.js"
40
40
  },
41
41
  "dependencies": {