@dolphjs/cli 1.0.26 → 1.1.1
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/dist/daemon/watcher.js +50 -18
- package/dist/daemon/watcherConfig.js +5 -1
- package/dist/index.js +1 -1
- package/dist/utils/get_user_config_path.js +3 -3
- package/dist/utils/init_helper_function.js +4 -1
- package/dist/utils/package_description.js +1 -1
- package/dist/utils/package_init.js +1 -1
- package/dist/utils/read_user_config.js +59 -45
- package/dist/utils/read_user_config_path.js +1 -2
- package/dist/utils/write_package_json.js +6 -12
- package/dist/utils/write_user_config.js +1 -1
- package/package.json +2 -2
package/dist/daemon/watcher.js
CHANGED
|
@@ -4,11 +4,6 @@ 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 = () => {
|
|
@@ -25,6 +20,10 @@ export const startApp = () => {
|
|
|
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
29
|
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting watch mode ...")}`;
|
|
@@ -32,27 +31,60 @@ export const startApp = () => {
|
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
33
|
};
|
|
35
|
-
export const
|
|
34
|
+
export const buildApp = () => {
|
|
36
35
|
fileExtension = readConfig().language;
|
|
37
36
|
if (fileExtension === "ts") {
|
|
38
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
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
90
|
`${chalk.bold(chalk.red("[DOLPH ERROR]: "))} ${chalk.redBright("exiting watch mode ...")}`;
|
|
@@ -60,7 +92,7 @@ export const startProdApp = () => {
|
|
|
60
92
|
}
|
|
61
93
|
});
|
|
62
94
|
};
|
|
63
|
-
const watcher = chokidar.watch(
|
|
95
|
+
const watcher = chokidar.watch([], {
|
|
64
96
|
ignored: "/node_modules",
|
|
65
97
|
persistent: true,
|
|
66
98
|
ignoreInitial: false,
|
|
@@ -73,7 +105,7 @@ export const watchFile = () => {
|
|
|
73
105
|
fileExtension = readConfig().language;
|
|
74
106
|
const srcDirectory = join(getRootDirectory(), "src");
|
|
75
107
|
watcher.add(srcDirectory);
|
|
76
|
-
watcher.on("
|
|
108
|
+
watcher.on("", (_event, path) => {
|
|
77
109
|
`${chalk.bold(chalk.green("[DOLPH INFO]: "))} ${chalk.greenBright("file changed" + `[${path}]`)}`;
|
|
78
110
|
if (path.endsWith(".ts") || path.endsWith(".js")) {
|
|
79
111
|
startApp();
|
|
@@ -1,5 +1,5 @@
|
|
|
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")
|
|
@@ -9,4 +9,8 @@ export const watcherConfig = () => {
|
|
|
9
9
|
.command("watch")
|
|
10
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("
|
|
10
|
+
figlet.text("dolph cli", {
|
|
11
11
|
font: "Big",
|
|
12
12
|
horizontalLayout: "default",
|
|
13
13
|
verticalLayout: "default",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { existsSync } from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { getRootDirectory } from "./get_root_dir_path.js";
|
|
3
4
|
export const getUserConfigFilePath = () => {
|
|
4
|
-
const
|
|
5
|
-
const userConfigFilePath = path.join(userConfigFolderPath, "dolph-cli.yaml");
|
|
5
|
+
const userConfigFilePath = path.join(getRootDirectory(), "dolph_cli.yaml");
|
|
6
6
|
if (existsSync(userConfigFilePath)) {
|
|
7
7
|
return userConfigFilePath;
|
|
8
8
|
}
|
|
9
|
-
return path.join(userConfigFilePath, "../../", "
|
|
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, "
|
|
26
|
+
const userConfigFilePath = path.join(configFolderPath, "dolph_cli.yaml");
|
|
27
27
|
if (!existsSync(configFolderPath)) {
|
|
28
28
|
mkdirSync(configFolderPath);
|
|
29
29
|
}
|
|
@@ -70,6 +70,8 @@ export const initDolphCli = (appname) => {
|
|
|
70
70
|
// },
|
|
71
71
|
])
|
|
72
72
|
.then((replies) => {
|
|
73
|
+
// TODO: add this to the config file:
|
|
74
|
+
// # this is an auto generate file, please do not edit manually
|
|
73
75
|
const userConfig = { ...defaultConfig, ...replies };
|
|
74
76
|
const yamlString = yaml.dump(userConfig);
|
|
75
77
|
writeFileSync(userConfigFilePath, yamlString, "utf8");
|
|
@@ -82,6 +84,7 @@ export const initDolphCli = (appname) => {
|
|
|
82
84
|
writeGitignore();
|
|
83
85
|
console.log(chalk.green(chalk.bold("dolph cli configurations have been initialized successfully 😎.")));
|
|
84
86
|
console.log(chalk.green(chalk.bold("run yarn install to install dependencies in project directory and start coding 😉.")));
|
|
87
|
+
process.exit(0);
|
|
85
88
|
});
|
|
86
89
|
}
|
|
87
90
|
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
|
|
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
|
};
|
|
@@ -8,60 +8,74 @@ export const configurePackage = () => {
|
|
|
8
8
|
.command("config")
|
|
9
9
|
.alias("cf")
|
|
10
10
|
.description("Set default configurations")
|
|
11
|
-
.option("-
|
|
12
|
-
.option("-
|
|
13
|
-
.option("-
|
|
11
|
+
.option("-lg, --language" + chalk.bold(chalk.blue("<language>")), "Set the default coding language (ts or js)")
|
|
12
|
+
.option("-pd, --paradigm" + chalk.bold(chalk.blue("<paradigm>")), "Set the default programming paradigm (oop or functional)")
|
|
13
|
+
.option("-db, --database" + chalk.bold(chalk.blue("<database>")), "Set the default project database (mongo, mysql, postresql or other)")
|
|
14
14
|
.option("-gf, --generateFolder" + chalk.bold(chalk.blue("<boolean>")), "Generates a folder file for the Services, Models, Controllers and Routes (true or false)")
|
|
15
|
-
.action((options) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
.action(async (name, options) => {
|
|
16
|
+
let config = readConfig();
|
|
17
|
+
Object.entries(name).forEach(([key, value]) => {
|
|
18
|
+
if (key && key.toLocaleLowerCase().includes("language") && value) {
|
|
19
|
+
console.log(value.toString(), value);
|
|
20
|
+
if (value.toString() !== "js" && value.toString() !== "ts") {
|
|
21
|
+
console.log(chalk.red(`Invalid project language, format must be either ${chalk.bold("js")} or ${chalk.bold("ts")}`));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
config.language = value;
|
|
25
|
+
writeConfig(config);
|
|
26
|
+
console.log(chalk.cyan(`Default project language is now ${chalk.bold(config.language)}`));
|
|
22
27
|
return;
|
|
23
28
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
console.log(chalk.red(`Invalid programming paradigm, must be either ${chalk.bold("oop")} or ${chalk.bold("functional")}`));
|
|
29
|
+
if (key && key.toLocaleLowerCase().includes("paradigm") && value) {
|
|
30
|
+
if (value.toString() !== "oop" && value.toString() !== "functional") {
|
|
31
|
+
console.log(chalk.red(`Invalid programming paradigm, must be either ${chalk.bold("oop")} or ${chalk.bold("functional")}`));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
config.paradigm = value;
|
|
35
|
+
writeConfig(config);
|
|
36
|
+
console.log(chalk.cyan(`Default programming paradigm is now ${chalk.bold(config.paradigm)}`));
|
|
33
37
|
return;
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
console.log(chalk.red(`Invalid database value, must be either of these: ${dbOptions.join(", ")} `));
|
|
39
|
+
if (key && key.toLocaleLowerCase().includes("database") && value) {
|
|
40
|
+
if (!dbOptions.includes(value.toString())) {
|
|
41
|
+
console.log(chalk.red(`Invalid database value, must be either of these: ${dbOptions.join(", ")} `));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
config.database = value;
|
|
45
|
+
writeConfig(config);
|
|
46
|
+
console.log(chalk.cyan(`Default project database is now ${chalk.bold(config.database)}`));
|
|
44
47
|
return;
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
writeConfig(config);
|
|
48
|
-
console.log(chalk.cyan(`Default project database is now ${chalk.bold(config.database)}`));
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
49
|
+
});
|
|
51
50
|
// validate generateFolder
|
|
52
|
-
if (options.generateFolder) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
// if (options.generateFolder) {
|
|
52
|
+
// if (
|
|
53
|
+
// options.generateFolder !== "true" &&
|
|
54
|
+
// options.generateFolder !== "false"
|
|
55
|
+
// ) {
|
|
56
|
+
// console.log(
|
|
57
|
+
// chalk.red(
|
|
58
|
+
// `Invalid folder generation value, value must be ${chalk.bold(
|
|
59
|
+
// "true"
|
|
60
|
+
// )} or ${chalk.bold("false")}`
|
|
61
|
+
// )
|
|
62
|
+
// );
|
|
63
|
+
// return;
|
|
64
|
+
// }
|
|
65
|
+
// config.generateFolder = options.generateFolder;
|
|
66
|
+
// writeConfig(config);
|
|
67
|
+
// console.log(
|
|
68
|
+
// chalk.cyan(
|
|
69
|
+
// `Generation of folder files for the Services, Models, Controllers and Routes set to ${chalk.bold(
|
|
70
|
+
// config.generateFolder
|
|
71
|
+
// )}`
|
|
72
|
+
// )
|
|
73
|
+
// );
|
|
74
|
+
// return;
|
|
75
|
+
// }
|
|
63
76
|
if (Object.keys(options).length === 0) {
|
|
64
|
-
console.log(chalk.yellow(chalk.bold(`No configurations applied, run ${chalk.white("dolph
|
|
77
|
+
console.log(chalk.yellow(chalk.bold(`No configurations applied, run ${chalk.white("dolph config --help")} to see available commands`)));
|
|
65
78
|
}
|
|
79
|
+
process.exit(0);
|
|
66
80
|
});
|
|
67
81
|
};
|
|
@@ -12,8 +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
|
|
15
|
+
console.log(chalk.bold(chalk.red("Error encountered reading config file, please run 'dolph cf' to initialize config file 🥹")));
|
|
16
16
|
process.exit(1);
|
|
17
|
-
return {};
|
|
18
17
|
}
|
|
19
18
|
};
|
|
@@ -13,14 +13,13 @@ export function writePackageJsonFile(name, extension) {
|
|
|
13
13
|
"node": ">=18.0.0"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"dev:start": "
|
|
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": "
|
|
19
|
+
"build": "dolph build",
|
|
20
20
|
"build:tsc": "tsc && tsc-alias",
|
|
21
|
-
"
|
|
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": "
|
|
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": "
|
|
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
|
|
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.
|
|
3
|
+
"version": "1.1.1",
|
|
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
|
|
38
|
+
"dolph": "./dist/index.js",
|
|
39
39
|
"dc": "./dist/index.js"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|