@dolphjs/cli 1.4.1 → 2.0.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/README.md +60 -35
- package/dist/daemon/watcher.d.ts +4 -0
- package/dist/daemon/watcher.js +82 -53
- package/dist/daemon/watcherConfig.d.ts +1 -0
- package/dist/daemon/watcherConfig.js +13 -9
- package/dist/generators/generate_controller.d.ts +2 -0
- package/dist/generators/generate_controller.js +38 -30
- package/dist/generators/generate_model.d.ts +2 -0
- package/dist/generators/generate_model.js +35 -27
- package/dist/generators/generate_mysql.d.ts +2 -0
- package/dist/generators/generate_mysql.js +33 -25
- package/dist/generators/generate_routes.d.ts +2 -0
- package/dist/generators/generate_routes.js +33 -25
- package/dist/generators/generate_service.d.ts +2 -0
- package/dist/generators/generate_service.js +36 -28
- package/dist/generators/resolvers/resolve_controller_content.d.ts +1 -0
- package/dist/generators/resolvers/resolve_controller_content.js +29 -3
- package/dist/generators/resolvers/resolve_model_content.d.ts +2 -0
- package/dist/generators/resolvers/resolve_model_content.js +32 -5
- package/dist/generators/resolvers/resolve_routes_content.d.ts +1 -0
- package/dist/generators/resolvers/resolve_routes_content.js +29 -3
- package/dist/generators/resolvers/resolve_service_content.d.ts +1 -0
- package/dist/generators/resolvers/resolve_service_content.js +29 -3
- package/dist/generators/spring/generate_spring_component.d.ts +2 -0
- package/dist/generators/spring/generate_spring_component.js +30 -22
- package/dist/generators/spring/generate_spring_controller.d.ts +2 -0
- package/dist/generators/spring/generate_spring_controller.js +30 -22
- package/dist/generators/spring/generate_spring_model.d.ts +2 -0
- package/dist/generators/spring/generate_spring_model.js +30 -22
- package/dist/generators/spring/generate_spring_mysql.d.ts +2 -0
- package/dist/generators/spring/generate_spring_mysql.js +30 -22
- package/dist/generators/spring/generate_spring_service.d.ts +2 -0
- package/dist/generators/spring/generate_spring_service.js +30 -22
- package/dist/generators/spring/generate_spring_socket_service.d.ts +2 -0
- package/dist/generators/spring/generate_spring_socket_service.js +29 -21
- package/dist/generators/templates/controller_template.d.ts +5 -0
- package/dist/generators/templates/controller_template.js +7 -1
- package/dist/generators/templates/model_template.d.ts +5 -0
- package/dist/generators/templates/model_template.js +7 -1
- package/dist/generators/templates/mysql_config_template.d.ts +5 -0
- package/dist/generators/templates/mysql_config_template.js +7 -1
- package/dist/generators/templates/routes_template.d.ts +5 -0
- package/dist/generators/templates/routes_template.js +7 -1
- package/dist/generators/templates/service_template.d.ts +5 -0
- package/dist/generators/templates/service_template.js +7 -1
- package/dist/generators/templates/socket_service_template.d.ts +1 -0
- package/dist/generators/templates/socket_service_template.js +5 -1
- package/dist/generators/templates/spring_component_template.d.ts +1 -0
- package/dist/generators/templates/spring_component_template.js +5 -1
- package/dist/generators/templates/spring_controller_template.d.ts +1 -0
- package/dist/generators/templates/spring_controller_template.js +5 -1
- package/dist/generators/templates/spring_model_template.d.ts +1 -0
- package/dist/generators/templates/spring_model_template.js +5 -1
- package/dist/generators/templates/spring_service_template.d.ts +1 -0
- package/dist/generators/templates/spring_service_template.js +5 -1
- package/dist/get_file_stats.d.ts +1 -0
- package/dist/get_file_stats.js +10 -0
- package/dist/helpers/messages.d.ts +8 -0
- package/dist/helpers/messages.js +14 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +110 -29
- package/dist/install.d.ts +1 -0
- package/dist/install.js +149 -0
- package/dist/registers/register_component.d.ts +1 -0
- package/dist/registers/register_component.js +27 -21
- package/dist/registers/register_controllers_in_components.d.ts +1 -0
- package/dist/registers/register_controllers_in_components.js +22 -17
- package/dist/registers/register_routes.d.ts +1 -0
- package/dist/registers/register_routes.js +27 -32
- package/dist/registers/server_file_express.d.ts +1 -0
- package/dist/registers/server_file_express.js +20 -17
- package/dist/registers/server_file_spring.d.ts +1 -0
- package/dist/registers/server_file_spring.js +18 -13
- package/dist/types/config.d.ts +14 -0
- package/dist/types/config.js +2 -1
- package/dist/utils/get_root_dir_path.d.ts +1 -0
- package/dist/utils/get_root_dir_path.js +10 -3
- package/dist/utils/get_user_config_path.d.ts +1 -0
- package/dist/utils/get_user_config_path.js +14 -7
- package/dist/utils/init_helper_function.d.ts +1 -0
- package/dist/utils/init_helper_function.js +50 -44
- package/dist/utils/package_config.d.ts +1 -0
- package/dist/utils/package_config.js +2 -0
- package/dist/utils/package_description.d.ts +1 -0
- package/dist/utils/package_description.js +12 -5
- package/dist/utils/package_generator.d.ts +1 -0
- package/dist/utils/package_generator.js +69 -41
- package/dist/utils/package_init.d.ts +1 -0
- package/dist/utils/package_init.js +9 -5
- package/dist/utils/read_package_json.d.ts +4 -0
- package/dist/utils/read_package_json.js +17 -0
- package/dist/utils/read_user_config.d.ts +1 -0
- package/dist/utils/read_user_config.js +29 -22
- package/dist/utils/read_user_config_path.d.ts +1 -0
- package/dist/utils/read_user_config_path.js +16 -9
- package/dist/utils/write_dolph_config.d.ts +1 -0
- package/dist/utils/write_dolph_config.js +32 -5
- package/dist/utils/write_gitignore.d.ts +1 -0
- package/dist/utils/write_gitignore.js +32 -5
- package/dist/utils/write_package_json.d.ts +1 -0
- package/dist/utils/write_package_json.js +32 -5
- package/dist/utils/write_swrcc.d.ts +1 -0
- package/dist/utils/write_swrcc.js +32 -5
- package/dist/utils/write_tsconfig.d.ts +1 -0
- package/dist/utils/write_tsconfig.js +32 -5
- package/dist/utils/write_user_config.d.ts +1 -0
- package/dist/utils/write_user_config.js +17 -10
- package/package.json +22 -12
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSocketService = void 0;
|
|
4
|
+
const generateSocketService = (componentName) => {
|
|
2
5
|
let template;
|
|
3
6
|
const capitalizeFirstLetter = (str) => {
|
|
4
7
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -23,3 +26,4 @@ export class ${className} extends DolphSocketServiceHandler<Dolph> {
|
|
|
23
26
|
`;
|
|
24
27
|
return template;
|
|
25
28
|
};
|
|
29
|
+
exports.generateSocketService = generateSocketService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateSpringComponent: (componentName: string) => string;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSpringComponent = void 0;
|
|
4
|
+
const generateSpringComponent = (componentName) => {
|
|
2
5
|
const capitalizeFirstLetter = (str) => {
|
|
3
6
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
4
7
|
};
|
|
@@ -10,3 +13,4 @@ export class ${className} {}
|
|
|
10
13
|
`;
|
|
11
14
|
return template;
|
|
12
15
|
};
|
|
16
|
+
exports.generateSpringComponent = generateSpringComponent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateSpringController: (componentName: string) => string;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSpringController = void 0;
|
|
4
|
+
const generateSpringController = (componentName) => {
|
|
2
5
|
const capitalizeFirstLetter = (str) => {
|
|
3
6
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
4
7
|
};
|
|
@@ -26,3 +29,4 @@ export class ${className} extends DolphControllerHandler<Dolph> {
|
|
|
26
29
|
`;
|
|
27
30
|
return template;
|
|
28
31
|
};
|
|
32
|
+
exports.generateSpringController = generateSpringController;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateSpringModel: (componentName: string, isMongo: boolean, isMysql: boolean) => any;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSpringModel = void 0;
|
|
4
|
+
const generateSpringModel = (componentName, isMongo, isMysql) => {
|
|
2
5
|
let template;
|
|
3
6
|
const capitalizeFirstLetter = (str) => {
|
|
4
7
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -38,3 +41,4 @@ export const ${capitalizeFirstLetter(componentName)} = sequelizeInstance.define(
|
|
|
38
41
|
}
|
|
39
42
|
return template;
|
|
40
43
|
};
|
|
44
|
+
exports.generateSpringModel = generateSpringModel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateSpringService: (componentName: string, isMongo: boolean, isMySql: boolean) => any;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSpringService = void 0;
|
|
4
|
+
const generateSpringService = (componentName, isMongo, isMySql) => {
|
|
2
5
|
let template;
|
|
3
6
|
const capitalizeFirstLetter = (str) => {
|
|
4
7
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -80,3 +83,4 @@ export class ${className} extends DolphServiceHandler<Dolph> {
|
|
|
80
83
|
}
|
|
81
84
|
return template;
|
|
82
85
|
};
|
|
86
|
+
exports.generateSpringService = generateSpringService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getFileStats: (filePath: string) => number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFileStats = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const getFileStats = (filePath) => {
|
|
6
|
+
const stats = (0, fs_1.statSync)(filePath);
|
|
7
|
+
const sizeInBytes = stats.size;
|
|
8
|
+
return sizeInBytes;
|
|
9
|
+
};
|
|
10
|
+
exports.getFileStats = getFileStats;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const dolphMsg: {
|
|
2
|
+
infoGreen: (message: string) => void;
|
|
3
|
+
infoYellow: (message: string) => void;
|
|
4
|
+
infoBlue: (message: string) => void;
|
|
5
|
+
info: (message: string) => void;
|
|
6
|
+
errorRed: (message: string) => void;
|
|
7
|
+
errorGray: (message: string) => void;
|
|
8
|
+
};
|
package/dist/helpers/messages.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.dolphMsg = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
exports.dolphMsg = {
|
|
9
|
+
infoGreen: (message) => console.log(chalk_1.default.bold(chalk_1.default.green("[DOLPH INFO]: ")) + chalk_1.default.greenBright(message)),
|
|
10
|
+
infoYellow: (message) => console.log(chalk_1.default.bold(chalk_1.default.yellow("[DOLPH INFO]: ")) + chalk_1.default.yellowBright(message)),
|
|
11
|
+
infoBlue: (message) => console.log(chalk_1.default.bold(chalk_1.default.blue("[DOLPH INFO]: ")) + chalk_1.default.blueBright(message)),
|
|
12
|
+
info: (message) => console.log(chalk_1.default.bold(chalk_1.default.blue("[DOLPH INFO]: " + chalk_1.default.white(message)))),
|
|
13
|
+
errorRed: (message) => console.log(chalk_1.default.bold(chalk_1.default.red("[DOLPH ERROR]: ")) + chalk_1.default.redBright(message)),
|
|
14
|
+
errorGray: (message) => console.log(chalk_1.default.bold(chalk_1.default.bgGrey("[DOLPH ERROR]: ")) + chalk_1.default.grey(message)),
|
|
9
15
|
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,32 +1,113 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
// import chalk from "chalk";
|
|
4
|
+
// import { program } from "commander";
|
|
5
|
+
// import figlet from "figlet";
|
|
6
|
+
// import { packageDescription } from "./utils/package_description.js";
|
|
7
|
+
// import { configurePackage } from "./utils/read_user_config.js";
|
|
8
|
+
// import { InitDolphCli } from "./utils/package_init.js";
|
|
9
|
+
// import { packageGenerator } from "./utils/package_generator.js";
|
|
10
|
+
// import { watcherConfig } from "./daemon/watcherConfig.js";
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
// figlet.text(
|
|
49
|
+
// "dolph cli",
|
|
50
|
+
// {
|
|
51
|
+
// font: "Big",
|
|
52
|
+
// horizontalLayout: "default",
|
|
53
|
+
// verticalLayout: "default",
|
|
54
|
+
// width: 150,
|
|
55
|
+
// whitespaceBreak: true,
|
|
56
|
+
// },
|
|
57
|
+
// function (err: any, _data: any) {
|
|
58
|
+
// if (err) {
|
|
59
|
+
// console.log("[FIGLET ERROR]: ", chalk.red(err.toString()));
|
|
60
|
+
// return;
|
|
61
|
+
// }
|
|
62
|
+
// // console.log(chalk.bold(chalk.cyan(data)));
|
|
63
|
+
// InitDolphCli();
|
|
64
|
+
// packageDescription();
|
|
65
|
+
// configurePackage();
|
|
66
|
+
// packageGenerator();
|
|
67
|
+
// watcherConfig();
|
|
68
|
+
// program.command("*", { hidden: true }).action(() => {
|
|
69
|
+
// console.log(
|
|
70
|
+
// `${chalk.red("[DOLPH ERROR]: ")} ${chalk.redBright(
|
|
71
|
+
// "unknown command. See list of available commands: "
|
|
72
|
+
// )}`
|
|
73
|
+
// );
|
|
74
|
+
// program.help();
|
|
75
|
+
// });
|
|
76
|
+
// program.parse(process.argv);
|
|
77
|
+
// }
|
|
78
|
+
// );
|
|
79
|
+
const path = __importStar(require("path"));
|
|
80
|
+
const os = __importStar(require("os"));
|
|
81
|
+
const child_process_1 = require("child_process");
|
|
82
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
83
|
+
function getBinaryPath() {
|
|
84
|
+
const platform = os.platform();
|
|
85
|
+
const arch = os.arch();
|
|
86
|
+
let binaryName = "dolph";
|
|
87
|
+
if (platform === "win32") {
|
|
88
|
+
binaryName = "dolph.exe";
|
|
89
|
+
}
|
|
90
|
+
// const binaryPath = path.join(__dirname, "..", "bin", binaryName);
|
|
91
|
+
const binaryPath = path.join(__dirname, "../", "bin", binaryName);
|
|
92
|
+
if (!require("fs").existsSync(binaryPath)) {
|
|
93
|
+
console.log(`${chalk_1.default.red("[ERROR]: ")} ${chalk_1.default.blue(`DolphJS CLI binary not found. Please run "npm install" again.`)}`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
return binaryPath;
|
|
97
|
+
}
|
|
98
|
+
const binary = getBinaryPath();
|
|
99
|
+
// Pass all arguments to the Rust binary
|
|
100
|
+
const args = process.argv.slice(2);
|
|
101
|
+
const child = (0, child_process_1.spawn)(binary, args, {
|
|
102
|
+
// This pipes input/output to the current terminal
|
|
103
|
+
stdio: "inherit",
|
|
104
|
+
});
|
|
105
|
+
child.on("error", (err) => {
|
|
106
|
+
console.log(`${chalk_1.default.red("[ERROR]: ")} ${chalk_1.default.blue(`Failed to start DolphJS CLI: ${err.message}`)}`);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
});
|
|
109
|
+
child.on("close", (code) => {
|
|
110
|
+
if (code !== null) {
|
|
111
|
+
process.exit(code);
|
|
20
112
|
}
|
|
21
|
-
// console.log(chalk.bold(chalk.cyan(data)));
|
|
22
|
-
InitDolphCli();
|
|
23
|
-
packageDescription();
|
|
24
|
-
configurePackage();
|
|
25
|
-
packageGenerator();
|
|
26
|
-
watcherConfig();
|
|
27
|
-
program.command("*", { hidden: true }).action(() => {
|
|
28
|
-
console.log(`${chalk.red("[DOLPH ERROR]: ")} ${chalk.redBright("unknown command. See list of available commands: ")}`);
|
|
29
|
-
program.help();
|
|
30
|
-
});
|
|
31
|
-
program.parse(process.argv);
|
|
32
113
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/install.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const os = __importStar(require("os"));
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const https = __importStar(require("https"));
|
|
43
|
+
const http = __importStar(require("http"));
|
|
44
|
+
const child_process_1 = require("child_process");
|
|
45
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
46
|
+
async function downloadBinary() {
|
|
47
|
+
const platform = os.platform(); // 'darwin', 'linux', 'win32'
|
|
48
|
+
const arch = os.arch(); // 'x64', 'arm64'
|
|
49
|
+
let binaryName = "dolph";
|
|
50
|
+
let releaseAssetName = ""; // e.g., 'dolph-x86_64-apple-darwin.tar.gz' or 'dolph-x86_64-pc-windows-msvc.zip'
|
|
51
|
+
// Map Node.js platform/arch to the Rust target triples and asset names
|
|
52
|
+
if (platform === "darwin") {
|
|
53
|
+
if (arch === "arm64") {
|
|
54
|
+
releaseAssetName = "dolph-aarch64-apple-darwin";
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// x64
|
|
58
|
+
releaseAssetName = "dolph-x86_64-apple-darwin";
|
|
59
|
+
}
|
|
60
|
+
// macOS binaries are often just executable, not compressed, or .tar.gz
|
|
61
|
+
binaryName = "dolph"; // No .exe extension
|
|
62
|
+
}
|
|
63
|
+
else if (platform === "win32") {
|
|
64
|
+
releaseAssetName = "dolph-x86_64-pc-windows-msvc";
|
|
65
|
+
binaryName = "dolph.exe";
|
|
66
|
+
}
|
|
67
|
+
else if (platform === "linux") {
|
|
68
|
+
releaseAssetName = "dolph-x86_64-unknown-linux-gnu";
|
|
69
|
+
binaryName = "dolph";
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.error(`Unsupported platform: ${platform}-${arch}`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
const version = require("../package.json").version; // Get version from package.json
|
|
76
|
+
let releaseUrl = `https://github.com/dolphjs/cli_v2/releases/download/v${version}/${releaseAssetName}.tar.gz`;
|
|
77
|
+
if (platform === "win32") {
|
|
78
|
+
releaseUrl = `https://github.com/dolphjs/cli_v2/releases/download/v${version}/${releaseAssetName}.zip`;
|
|
79
|
+
}
|
|
80
|
+
// Where to put the binary
|
|
81
|
+
const installDir = path.join(__dirname, "..", "bin");
|
|
82
|
+
if (!fs.existsSync(installDir)) {
|
|
83
|
+
fs.mkdirSync(installDir, { recursive: true });
|
|
84
|
+
}
|
|
85
|
+
const binaryPath = path.join(__dirname, "..", "bin", binaryName);
|
|
86
|
+
const archiveName = platform === "win32" ? "dolph.zip" : "dolph.tar.gz";
|
|
87
|
+
const archivePath = path.join(__dirname, "..", "bin", archiveName);
|
|
88
|
+
console.log(`${chalk_1.default.blue("[INFO]: ")} ${chalk_1.default.blue(`Downloading DolphJS CLI for ${platform}-${arch} from ${releaseUrl}...`)}`);
|
|
89
|
+
try {
|
|
90
|
+
await downloadWithRedirects(releaseUrl, archivePath);
|
|
91
|
+
console.log(`${chalk_1.default.blue("[INFO]: ")} Extracting archive...`);
|
|
92
|
+
if (platform === "win32") {
|
|
93
|
+
const extCmd = (0, child_process_1.spawnSync)("powershell", ["-command", `Expand-Archive -Path '${archivePath}' -DestinationPath '${installDir}' -Force`], { stdio: "inherit" });
|
|
94
|
+
if (extCmd.status !== 0)
|
|
95
|
+
throw new Error("Failed to extract zip archive");
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const extCmd = (0, child_process_1.spawnSync)("tar", ["-xzf", archivePath, "-C", installDir], { stdio: "inherit" });
|
|
99
|
+
if (extCmd.status !== 0)
|
|
100
|
+
throw new Error("Failed to extract tar archive");
|
|
101
|
+
}
|
|
102
|
+
fs.unlinkSync(archivePath);
|
|
103
|
+
fs.chmodSync(binaryPath, "755");
|
|
104
|
+
console.log(`${chalk_1.default.blue("[INFO]: ")} ${chalk_1.default.blue(`DolphJS CLI downloaded and installed successfully!`)}`);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.log(`${chalk_1.default.red("[ERROR]: ")} ${chalk_1.default.redBright(`Error downloading DolphJS CLI: ${error?.message || error}`)}`);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function downloadWithRedirects(url, filePath, maxRedirects = 5) {
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
if (maxRedirects < 0) {
|
|
114
|
+
return reject(new Error("Too many redirects"));
|
|
115
|
+
}
|
|
116
|
+
const parsedUrl = new URL(url);
|
|
117
|
+
const httpModule = parsedUrl.protocol === "https:" ? https : http;
|
|
118
|
+
const request = httpModule.get(url, (response) => {
|
|
119
|
+
// Handle redirects
|
|
120
|
+
if (response.statusCode >= 300 &&
|
|
121
|
+
response.statusCode < 400 &&
|
|
122
|
+
response.headers.location) {
|
|
123
|
+
const redirectUrl = response.headers.location.startsWith("http")
|
|
124
|
+
? response.headers.location
|
|
125
|
+
: new URL(response.headers.location, url).href;
|
|
126
|
+
console.log(`Redirecting to: ${redirectUrl}`);
|
|
127
|
+
return downloadWithRedirects(redirectUrl, filePath, maxRedirects - 1)
|
|
128
|
+
.then(resolve)
|
|
129
|
+
.catch(reject);
|
|
130
|
+
}
|
|
131
|
+
// Handle error status codes
|
|
132
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
133
|
+
return reject(new Error(`Failed to download binary: HTTP status code ${response.statusCode}`));
|
|
134
|
+
}
|
|
135
|
+
// Create write stream and pipe response
|
|
136
|
+
const file = fs.createWriteStream(filePath);
|
|
137
|
+
response.pipe(file);
|
|
138
|
+
file.on("finish", () => {
|
|
139
|
+
file.close(() => resolve());
|
|
140
|
+
});
|
|
141
|
+
file.on("error", (err) => {
|
|
142
|
+
// Delete file on error
|
|
143
|
+
fs.unlink(filePath, () => reject(err));
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
request.on("error", (err) => reject(err));
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
downloadBinary();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const addComponentToServerFile: (componentName: string) => Promise<void>;
|
|
@@ -1,49 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.addComponentToServerFile = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const messages_js_1 = require("../helpers/messages.js");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
4
10
|
const createComponentDirectory = () => {
|
|
5
|
-
const projectRoot =
|
|
6
|
-
const userComponentPath =
|
|
7
|
-
if (!existsSync(userComponentPath)) {
|
|
8
|
-
mkdirSync(userComponentPath);
|
|
11
|
+
const projectRoot = path_1.default.join(process.cwd());
|
|
12
|
+
const userComponentPath = path_1.default.join(projectRoot, `/src/components`);
|
|
13
|
+
if (!(0, fs_1.existsSync)(userComponentPath)) {
|
|
14
|
+
(0, fs_1.mkdirSync)(userComponentPath);
|
|
9
15
|
}
|
|
10
16
|
};
|
|
11
17
|
const findSrcDirectory = () => {
|
|
12
18
|
const rootDir = process.cwd();
|
|
13
19
|
const possibleDirs = [`src`];
|
|
14
|
-
const srcDir = possibleDirs.find((dir) => existsSync(
|
|
15
|
-
return srcDir ?
|
|
20
|
+
const srcDir = possibleDirs.find((dir) => (0, fs_1.existsSync)(path_1.default.join(rootDir, dir)));
|
|
21
|
+
return srcDir ? path_1.default.join(rootDir, srcDir) : null;
|
|
16
22
|
};
|
|
17
|
-
|
|
23
|
+
const addComponentToServerFile = async (componentName) => {
|
|
18
24
|
if (!componentName) {
|
|
19
|
-
dolphMsg.errorRed("component extension or name is required! 🤨");
|
|
25
|
+
messages_js_1.dolphMsg.errorRed("component extension or name is required! 🤨");
|
|
20
26
|
}
|
|
21
27
|
const serverDir = findSrcDirectory();
|
|
22
28
|
if (!serverDir) {
|
|
23
|
-
dolphMsg.errorRed("something went wrong, please make sure to use the `new` command when creating a dolph project.");
|
|
29
|
+
messages_js_1.dolphMsg.errorRed("something went wrong, please make sure to use the `new` command when creating a dolph project.");
|
|
24
30
|
return;
|
|
25
31
|
}
|
|
26
|
-
const serverPath =
|
|
32
|
+
const serverPath = path_1.default.join(serverDir, "server.ts");
|
|
27
33
|
const capitalizedString = componentName.charAt(0).toUpperCase() + componentName.slice(1);
|
|
28
34
|
const importStatement = `import { ${capitalizedString}Component } from "./components/${componentName}/${componentName}.component";`;
|
|
29
35
|
try {
|
|
30
|
-
if (!existsSync(serverPath)) {
|
|
36
|
+
if (!(0, fs_1.existsSync)(serverPath)) {
|
|
31
37
|
const fileContent = `import { DolphFactory } from "@dolphjs/dolph";
|
|
32
38
|
${importStatement}
|
|
33
39
|
const dolph = new DolphFactory([${capitalizedString}Component]);
|
|
34
40
|
dolph.start();
|
|
35
41
|
`;
|
|
36
|
-
writeFileSync(serverPath, fileContent);
|
|
42
|
+
(0, fs_1.writeFileSync)(serverPath, fileContent);
|
|
37
43
|
}
|
|
38
44
|
else {
|
|
39
|
-
const fileContent = readFileSync(serverPath, "utf8");
|
|
45
|
+
const fileContent = (0, fs_1.readFileSync)(serverPath, "utf8");
|
|
40
46
|
const newComponentInstance = `${capitalizedString}Component`;
|
|
41
47
|
if (!fileContent.includes(importStatement)) {
|
|
42
48
|
const updatedContent = `${importStatement}\n${fileContent}`;
|
|
43
|
-
writeFileSync(serverPath, updatedContent);
|
|
49
|
+
(0, fs_1.writeFileSync)(serverPath, updatedContent);
|
|
44
50
|
}
|
|
45
51
|
if (fileContent.includes(`const dolph`)) {
|
|
46
|
-
// add new controller class to the existing array
|
|
47
52
|
const routesArrayMatch = fileContent.match(/const dolph = new DolphFactory\(([^)]+)\);/);
|
|
48
53
|
if (routesArrayMatch) {
|
|
49
54
|
const existingCode = routesArrayMatch[1].trim();
|
|
@@ -52,14 +57,15 @@ dolph.start();
|
|
|
52
57
|
? existingCode.slice(0, -1) + `, ${newComponentInstance}]`
|
|
53
58
|
: newComponentInstance}`);
|
|
54
59
|
const updatedContents = `${importStatement}\n${fileContents}`;
|
|
55
|
-
writeFileSync(serverPath, updatedContents);
|
|
60
|
+
(0, fs_1.writeFileSync)(serverPath, updatedContents);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
|
-
dolphMsg.info(`added ${capitalizedString}Component to components array in server.ts file.`);
|
|
64
|
+
messages_js_1.dolphMsg.info(`added ${capitalizedString}Component to components array in server.ts file.`);
|
|
60
65
|
process.exit(0);
|
|
61
66
|
}
|
|
62
67
|
catch (e) {
|
|
63
|
-
dolphMsg.errorRed(e.toString());
|
|
68
|
+
messages_js_1.dolphMsg.errorRed(e.toString());
|
|
64
69
|
}
|
|
65
70
|
};
|
|
71
|
+
exports.addComponentToServerFile = addComponentToServerFile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const addControllerInComponentFIle: (componentName: string) => Promise<void>;
|
|
@@ -1,44 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.addControllerInComponentFIle = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const messages_js_1 = require("../helpers/messages.js");
|
|
4
10
|
const findComponentsDirectory = (componentName) => {
|
|
5
11
|
const rootDir = process.cwd();
|
|
6
12
|
const possibleDirs = [`src/components/${componentName}`];
|
|
7
|
-
const srcDir = possibleDirs.find((dir) => existsSync(
|
|
8
|
-
return srcDir ?
|
|
13
|
+
const srcDir = possibleDirs.find((dir) => (0, fs_1.existsSync)(path_1.default.join(rootDir, dir)));
|
|
14
|
+
return srcDir ? path_1.default.join(rootDir, srcDir) : null;
|
|
9
15
|
};
|
|
10
|
-
|
|
16
|
+
const addControllerInComponentFIle = async (componentName) => {
|
|
11
17
|
if (!componentName) {
|
|
12
|
-
dolphMsg.errorRed("component extension or name is required! 🤨");
|
|
18
|
+
messages_js_1.dolphMsg.errorRed("component extension or name is required! 🤨");
|
|
13
19
|
}
|
|
14
20
|
const componentDir = findComponentsDirectory(componentName);
|
|
15
21
|
if (!componentDir) {
|
|
16
|
-
dolphMsg.errorRed("something went wrong, please make sure to use the `new` command when creating a dolph project.");
|
|
22
|
+
messages_js_1.dolphMsg.errorRed("something went wrong, please make sure to use the `new` command when creating a dolph project.");
|
|
17
23
|
return;
|
|
18
24
|
}
|
|
19
|
-
const componentPath =
|
|
25
|
+
const componentPath = path_1.default.join(componentDir, `${componentName}.component.ts`);
|
|
20
26
|
const capitalizedString = componentName.charAt(0).toUpperCase() + componentName.slice(1);
|
|
21
27
|
const importStatement = `import { ${capitalizedString}Controller } from "./${componentName}.controller";`;
|
|
22
28
|
try {
|
|
23
|
-
if (!existsSync(componentPath)) {
|
|
29
|
+
if (!(0, fs_1.existsSync)(componentPath)) {
|
|
24
30
|
const fileContent = `import { Component } from "@dolphjs/dolph/decorators";
|
|
25
31
|
import { ${capitalizedString}Controller } from "./${componentName}.controller";
|
|
26
32
|
|
|
27
33
|
@Component({ controllers: [${capitalizedString}Controller], services: [] })
|
|
28
34
|
export class ${capitalizedString}Component {}
|
|
29
35
|
`;
|
|
30
|
-
writeFileSync(componentPath, fileContent);
|
|
36
|
+
(0, fs_1.writeFileSync)(componentPath, fileContent);
|
|
31
37
|
}
|
|
32
38
|
else {
|
|
33
|
-
const fileContent = readFileSync(componentPath, "utf8");
|
|
39
|
+
const fileContent = (0, fs_1.readFileSync)(componentPath, "utf8");
|
|
34
40
|
const newComponentInstance = `${capitalizedString}Controller`;
|
|
35
41
|
if (!fileContent.includes(importStatement)) {
|
|
36
|
-
// If import statement is not present, add it along with the new controller
|
|
37
42
|
const updatedContents = `${importStatement}\n${fileContent.replace(/@Component\(\s*{\s*controllers:\s*\[([^\]]*)\]\s*}\s*\)/, `@Component({ controllers: [${newComponentInstance}] })`)}`;
|
|
38
|
-
writeFileSync(componentPath, updatedContents);
|
|
43
|
+
(0, fs_1.writeFileSync)(componentPath, updatedContents);
|
|
39
44
|
}
|
|
40
45
|
else if (fileContent.includes(`const dolph`)) {
|
|
41
|
-
// If import statement is present and contains `const dolph`
|
|
42
46
|
const controllersArrayMatch = fileContent.match(/@Component\(\s*{\s*controllers:\s*\[([^\]]*)\]\s*}\s*\)/);
|
|
43
47
|
if (controllersArrayMatch) {
|
|
44
48
|
const existingCode = controllersArrayMatch[1].trim();
|
|
@@ -47,11 +51,11 @@ export class ${capitalizedString}Component {}
|
|
|
47
51
|
? existingCode.slice(0, -1) + `, ${newComponentInstance}`
|
|
48
52
|
: newComponentInstance}`);
|
|
49
53
|
const updatedContents = `${importStatement}\n${fileContents}`;
|
|
50
|
-
writeFileSync(componentPath, updatedContents);
|
|
54
|
+
(0, fs_1.writeFileSync)(componentPath, updatedContents);
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
|
-
dolphMsg.info(`registered ${capitalizedString}Controller in ${capitalizedString}Component`);
|
|
58
|
+
messages_js_1.dolphMsg.info(`registered ${capitalizedString}Controller in ${capitalizedString}Component`);
|
|
55
59
|
process.exit(0);
|
|
56
60
|
}
|
|
57
61
|
catch (error) {
|
|
@@ -59,3 +63,4 @@ export class ${capitalizedString}Component {}
|
|
|
59
63
|
process.exit(1);
|
|
60
64
|
}
|
|
61
65
|
};
|
|
66
|
+
exports.addControllerInComponentFIle = addControllerInComponentFIle;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const addRoutesIndexFile: (routesName: string, readConfig: any) => void;
|