@dolphjs/cli 0.1.1 → 1.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/LICENSE +21 -0
- package/dist/generators/generate_controller.js +65 -0
- package/dist/generators/generate_model.js +61 -0
- package/dist/generators/generate_mysql.js +63 -0
- package/dist/generators/generate_routes.js +59 -0
- package/dist/generators/generate_service.js +63 -0
- package/dist/generators/resolvers/resolve_controller_content.js +19 -0
- package/dist/generators/resolvers/resolve_model_content.js +37 -0
- package/dist/generators/resolvers/resolve_routes_content.js +19 -0
- package/dist/generators/resolvers/resolve_service_content.js +19 -0
- package/dist/generators/templates/controller_template.js +83 -0
- package/dist/generators/templates/model_template.js +168 -0
- package/dist/generators/templates/mysql_config_template.js +59 -0
- package/dist/generators/templates/routes_template.js +86 -0
- package/dist/generators/templates/service_template.js +172 -0
- package/dist/index.js +30 -0
- package/dist/registers/register_routes.js +145 -0
- package/dist/registers/server_file_routes.js +74 -0
- package/dist/types/config.js +1 -0
- package/dist/utils/get_root_dir_path.js +11 -0
- package/dist/utils/get_user_config_path.js +10 -0
- package/dist/utils/init_helper_function.js +90 -0
- package/dist/utils/package_description.js +6 -0
- package/dist/utils/package_generator.js +73 -0
- package/dist/utils/package_init.js +11 -0
- package/dist/utils/read_package_json.js +9 -0
- package/dist/utils/read_user_config.js +67 -0
- package/dist/utils/read_user_config_path.js +19 -0
- package/dist/utils/write_dolph_config.js +9 -0
- package/dist/utils/write_gitignore.js +12 -0
- package/dist/utils/write_package_json.js +68 -0
- package/dist/utils/write_swrcc.js +48 -0
- package/dist/utils/write_tsconfig.js +45 -0
- package/dist/utils/write_user_config.js +16 -0
- package/package.json +47 -40
- package/CODE_OF_CONDUCT.md +0 -76
- package/CONTRIBUTING.md +0 -91
- package/new-app.mjs +0 -209
- package/readme.md +0 -25
- package/utils/constants/packageManagers.mjs +0 -3
- package/utils/constants/types.mjs +0 -4
- package/utils/dependencies.mjs +0 -24
- package/utils/js-func/packageData.mjs +0 -20
- package/utils/js-func/writeSubFile.mjs +0 -96
- package/utils/js-oop/packageData.mjs +0 -19
- package/utils/js-oop/writeSubFileJsOop.mjs +0 -94
- package/utils/ts-func/copySubFolder.mjs +0 -58
- package/utils/ts-func/gitignoreData.mjs +0 -11
- package/utils/ts-func/nodemonData.mjs +0 -12
- package/utils/ts-func/packageData.mjs +0 -23
- package/utils/ts-func/readmeData.mjs +0 -293
- package/utils/ts-func/swcrcData.mjs +0 -49
- package/utils/ts-func/tsconfigFile.mjs +0 -55
- package/utils/ts-oop/copySubFolder.mjs +0 -71
- package/utils/ts-oop/gitignoreData.mjs +0 -11
- package/utils/ts-oop/nodemonData.mjs +0 -12
- package/utils/ts-oop/packageData.mjs +0 -23
- package/utils/ts-oop/readmeData.mjs +0 -292
- package/utils/ts-oop/swcrcData.mjs +0 -49
- package/utils/ts-oop/tsconfigFile.mjs +0 -55
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { existsSync, writeFileSync } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
// removed other possible dirs to enforce dolphjs style guide
|
|
5
|
+
const findBaseDirectory = () => {
|
|
6
|
+
const rootDir = process.cwd();
|
|
7
|
+
const possibleDirs = [
|
|
8
|
+
"/src",
|
|
9
|
+
// "/"
|
|
10
|
+
];
|
|
11
|
+
const routesDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
|
|
12
|
+
return routesDir ? path.join(rootDir, routesDir) : null;
|
|
13
|
+
};
|
|
14
|
+
export const addServerFile = (readConfig) => {
|
|
15
|
+
let extension;
|
|
16
|
+
let database;
|
|
17
|
+
extension = readConfig().language;
|
|
18
|
+
database = readConfig().database;
|
|
19
|
+
const baseDirectory = findBaseDirectory();
|
|
20
|
+
const indexPath = path.join(baseDirectory, `server.${extension}`);
|
|
21
|
+
let importStatement = ``;
|
|
22
|
+
let otherFileContent = "";
|
|
23
|
+
if (extension === "ts" && database === "mysql") {
|
|
24
|
+
importStatement = `import { DolphFactory } from "@dolphjs/dolph";
|
|
25
|
+
import { routes } from "./routes";
|
|
26
|
+
import { sequelizeInstance } from "@/configs/db.configs";
|
|
27
|
+
import { autoInitMySql } from "@dolphjs/dolph/packages";
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
else if (extension === "ts") {
|
|
31
|
+
importStatement = `import { DolphFactory } from "@dolphjs/dolph";
|
|
32
|
+
import { routes } from "./routes";`;
|
|
33
|
+
}
|
|
34
|
+
else if (extension === "js" && database === "mysql") {
|
|
35
|
+
importStatement = `const { DolphFactory } = require("@dolphjs/dolph");
|
|
36
|
+
const { routes } = require("./routes");
|
|
37
|
+
const { sequelizeInstance } = require("@/configs/db.configs");
|
|
38
|
+
const { autoInitMySql } = require("@dolphjs/dolph/packages");
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
else if (extension === "js") {
|
|
42
|
+
importStatement = `const { DolphFactory } = require("@dolphjs/dolph");
|
|
43
|
+
const { routes } = require("./routes");`;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.log(chalk.bold(chalk.red("dolphjs only supports '.js' & '.ts' file extensions ")));
|
|
47
|
+
}
|
|
48
|
+
if (database === "mysql") {
|
|
49
|
+
otherFileContent = `const dolph = new DolphFactory(routes, []);
|
|
50
|
+
autoInitMySql(sequelizeInstance);
|
|
51
|
+
|
|
52
|
+
dolph.start();`;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
otherFileContent = `const dolph = new DolphFactory(routes, []);
|
|
56
|
+
dolph.start();`;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
// check if file exists
|
|
60
|
+
if (!existsSync(indexPath)) {
|
|
61
|
+
// if it doesn't exist, create file and add import statement
|
|
62
|
+
const fileContent = `${importStatement}\n\n${otherFileContent}\n`;
|
|
63
|
+
writeFileSync(indexPath, fileContent);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const fileContent = `${importStatement}\n\n${otherFileContent}\n`;
|
|
67
|
+
writeFileSync(indexPath, fileContent);
|
|
68
|
+
}
|
|
69
|
+
console.log(chalk.bold(chalk.green(`added server.${extension} file to base directory`)));
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.log(chalk.bold(chalk.red(e)));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { config } from "dotenv";
|
|
3
|
+
config();
|
|
4
|
+
export const getRootDirectory = () => {
|
|
5
|
+
let projectRoot;
|
|
6
|
+
projectRoot =
|
|
7
|
+
process.env?.mode === "dev"
|
|
8
|
+
? path.join(process.cwd(), "src")
|
|
9
|
+
: path.join(process.cwd());
|
|
10
|
+
return projectRoot;
|
|
11
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
export const getUserConfigFilePath = () => {
|
|
4
|
+
const userConfigFolderPath = path.join(process.cwd());
|
|
5
|
+
const userConfigFilePath = path.join(userConfigFolderPath, "dolph-cli.yaml");
|
|
6
|
+
if (existsSync(userConfigFilePath)) {
|
|
7
|
+
return userConfigFilePath;
|
|
8
|
+
}
|
|
9
|
+
return path.join(userConfigFilePath, "../../", "dolph-cli.yaml");
|
|
10
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import yaml from "js-yaml";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import { writeSwcrc } from "./write_swrcc.js";
|
|
7
|
+
import { writeTsConfigFile } from "./write_tsconfig.js";
|
|
8
|
+
import { writeDolphConfig } from "./write_dolph_config.js";
|
|
9
|
+
import { writePackageJsonFile } from "./write_package_json.js";
|
|
10
|
+
import { writeGitignore } from "./write_gitignore.js";
|
|
11
|
+
export const initDolphCli = (appname) => {
|
|
12
|
+
let projectName = appname;
|
|
13
|
+
if (appname.length === 0) {
|
|
14
|
+
console.log(chalk.red(chalk.bold("Provide a name for you project or indicate with a '.' to use current directory ")));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (appname !== ".") {
|
|
18
|
+
mkdirSync(appname);
|
|
19
|
+
process.chdir(appname);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
projectName = process.cwd().split("/").pop();
|
|
23
|
+
}
|
|
24
|
+
const configFolderPath = path.join(process.cwd());
|
|
25
|
+
const srcPath = path.join(configFolderPath, "src");
|
|
26
|
+
const userConfigFilePath = path.join(configFolderPath, "dolph-cli.yaml");
|
|
27
|
+
if (!existsSync(configFolderPath)) {
|
|
28
|
+
mkdirSync(configFolderPath);
|
|
29
|
+
}
|
|
30
|
+
if (!existsSync(srcPath)) {
|
|
31
|
+
mkdirSync(srcPath);
|
|
32
|
+
}
|
|
33
|
+
const defaultConfig = {
|
|
34
|
+
language: "ts",
|
|
35
|
+
paradigm: "oop",
|
|
36
|
+
database: "mongo",
|
|
37
|
+
generateFolder: true,
|
|
38
|
+
};
|
|
39
|
+
if (!existsSync(userConfigFilePath)) {
|
|
40
|
+
inquirer
|
|
41
|
+
.prompt([
|
|
42
|
+
{
|
|
43
|
+
type: "list",
|
|
44
|
+
name: "language",
|
|
45
|
+
message: "Select your preferred language",
|
|
46
|
+
choices: ["ts", "js"],
|
|
47
|
+
default: "ts",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "list",
|
|
51
|
+
name: "paradigm",
|
|
52
|
+
message: "Choose the programming paradigm for your app (recommended is 'oop' )",
|
|
53
|
+
choices: ["oop", "functional"],
|
|
54
|
+
default: "oop",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "list",
|
|
58
|
+
name: "database",
|
|
59
|
+
message: "Which database will you be using?",
|
|
60
|
+
choices: ["mongo", "mysql", "postgresql", "other"],
|
|
61
|
+
default: "mongo",
|
|
62
|
+
},
|
|
63
|
+
// {
|
|
64
|
+
// type: "list",
|
|
65
|
+
// name: "generateFolder",
|
|
66
|
+
// message:
|
|
67
|
+
// "Generate folder and files for the Services, Models, Controllers and Routes",
|
|
68
|
+
// choices: ["true", "false"],
|
|
69
|
+
// default: "true",
|
|
70
|
+
// },
|
|
71
|
+
])
|
|
72
|
+
.then((replies) => {
|
|
73
|
+
const userConfig = { ...defaultConfig, ...replies };
|
|
74
|
+
const yamlString = yaml.dump(userConfig);
|
|
75
|
+
writeFileSync(userConfigFilePath, yamlString, "utf8");
|
|
76
|
+
if (userConfig.language === "ts") {
|
|
77
|
+
writeSwcrc();
|
|
78
|
+
writeTsConfigFile();
|
|
79
|
+
}
|
|
80
|
+
writeDolphConfig();
|
|
81
|
+
writePackageJsonFile(projectName, userConfig.language);
|
|
82
|
+
writeGitignore();
|
|
83
|
+
console.log(chalk.green(chalk.bold("dolph cli configurations have been initialized successfully 😎.")));
|
|
84
|
+
console.log(chalk.green(chalk.bold("run yarn install to install dependencies in project directory and start coding 😉.")));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
console.log(chalk.bold(chalk.cyan("I see you already have your dolph cli configurations present 😉.")));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { program } from "commander";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import * as controllerGen from "../generators/generate_controller.js";
|
|
4
|
+
import * as serviceGen from "../generators/generate_service.js";
|
|
5
|
+
import * as routesGen from "../generators/generate_routes.js";
|
|
6
|
+
import * as modelGen from "../generators/generate_model.js";
|
|
7
|
+
import * as mysqlGen from "../generators/generate_mysql.js";
|
|
8
|
+
import { readConfig } from "./read_user_config_path.js";
|
|
9
|
+
import { addRoutesIndexFile } from "../registers/register_routes.js";
|
|
10
|
+
import { addServerFile } from "../registers/server_file_routes.js";
|
|
11
|
+
export const packageGenerator = () => {
|
|
12
|
+
program
|
|
13
|
+
.command("generate")
|
|
14
|
+
.alias("g")
|
|
15
|
+
.option("-s, --service" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs service file.")
|
|
16
|
+
.option("-c, --controller" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs controller file.")
|
|
17
|
+
.option("-r, --routes" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs routes file.")
|
|
18
|
+
.option("-m, --models" + chalk.bold(chalk.blue("<name>")), "Generates a dolphjs models file.")
|
|
19
|
+
.option("-a, --all" + chalk.bold(chalk.blue("<name>")), "Generates dolphjs ocntrollers, routes, models and services files for the name paramter.")
|
|
20
|
+
// .option(
|
|
21
|
+
// "-in, --interfaces" + chalk.bold(chalk.blue("<name>")),
|
|
22
|
+
// "Generates a dolphjs interfaces file."
|
|
23
|
+
// )
|
|
24
|
+
// .option(
|
|
25
|
+
// "-hp, --helper" + chalk.bold(chalk.blue("<name>")),
|
|
26
|
+
// "Generates a dolphjs helper file."
|
|
27
|
+
// )
|
|
28
|
+
.action(async (name, _options) => {
|
|
29
|
+
Object.entries(name).forEach(([key, value]) => {
|
|
30
|
+
// generates controller files for the paramter name
|
|
31
|
+
if (key && key.toLowerCase().includes("controller") && value) {
|
|
32
|
+
controllerGen.generateController(value.toString());
|
|
33
|
+
}
|
|
34
|
+
// generates service files for the paramter name
|
|
35
|
+
if (key && key.toLowerCase().includes("service") && value) {
|
|
36
|
+
serviceGen.generateService(value.toString());
|
|
37
|
+
}
|
|
38
|
+
// generatess routes files for the paramter name
|
|
39
|
+
if (key && key.toLowerCase().includes("routes") && value) {
|
|
40
|
+
routesGen.generateRouter(value.toString());
|
|
41
|
+
addRoutesIndexFile(value.toString(), readConfig);
|
|
42
|
+
}
|
|
43
|
+
// generatess model fles for the paramter name
|
|
44
|
+
if (key && key.toLowerCase().includes("models") && value) {
|
|
45
|
+
modelGen.generateModel(value.toString());
|
|
46
|
+
if (readConfig().database === "mysql") {
|
|
47
|
+
mysqlGen.generateConfig(value.toString());
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// generates files for all the above options
|
|
51
|
+
if (key && key.toLowerCase().includes("all") && value) {
|
|
52
|
+
modelGen.generateModel(value.toString());
|
|
53
|
+
if (readConfig().database === "mysql") {
|
|
54
|
+
mysqlGen.generateConfig(value.toString());
|
|
55
|
+
}
|
|
56
|
+
serviceGen.generateService(value.toString());
|
|
57
|
+
controllerGen.generateController(value.toString());
|
|
58
|
+
routesGen.generateRouter(value.toString());
|
|
59
|
+
addRoutesIndexFile(value.toString(), readConfig);
|
|
60
|
+
addServerFile(readConfig);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
// const controllerName = controller ? `${controller}` : undefined;
|
|
64
|
+
// const serviceName = service ? `${service}` : undefined;
|
|
65
|
+
// const modelName = model ? `${model}` : undefined;
|
|
66
|
+
// const routesName = routes ? `${routes}` : undefined;
|
|
67
|
+
// const interfacesName = interfaces ? `${interfaces}` : undefined;
|
|
68
|
+
// const helperName = helper ? `${helper}` : undefined;
|
|
69
|
+
// if (controllerName) {
|
|
70
|
+
// controllerGen.generateController(controllerName);
|
|
71
|
+
// }
|
|
72
|
+
});
|
|
73
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { program } from "commander";
|
|
2
|
+
import { initDolphCli } from "./init_helper_function.js";
|
|
3
|
+
export const InitDolphCli = () => {
|
|
4
|
+
program
|
|
5
|
+
.command("new <project-name>")
|
|
6
|
+
.alias("nw")
|
|
7
|
+
.description("Creates a new dolphjs app")
|
|
8
|
+
.action((appname) => {
|
|
9
|
+
initDolphCli(appname);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
4
|
+
const packageJsonContent = readFileSync(packageJsonPath, "utf8");
|
|
5
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
6
|
+
const version = packageJson.version;
|
|
7
|
+
const name = packageJson.name;
|
|
8
|
+
const description = packageJson.description;
|
|
9
|
+
export { version, name, description };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { program } from "commander";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { readConfig } from "./read_user_config_path.js";
|
|
4
|
+
import { writeConfig } from "./write_user_config.js";
|
|
5
|
+
const dbOptions = ["mongo", "postgresql", "mysql", "other"];
|
|
6
|
+
export const configurePackage = () => {
|
|
7
|
+
program
|
|
8
|
+
.command("config")
|
|
9
|
+
.alias("cf")
|
|
10
|
+
.description("Set default configurations")
|
|
11
|
+
.option("-l, --language" + chalk.bold(chalk.blue("<language>")), "Set the default coding language (ts or js)")
|
|
12
|
+
.option("-p, --paradigm" + chalk.bold(chalk.blue("<paradigm>")), "Set the default programming paradigm (oop or functional)")
|
|
13
|
+
.option("-d, --database" + chalk.bold(chalk.blue("<database>")), "Set the default project database (mongo, mysql, postresql or other)")
|
|
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
|
+
const config = readConfig();
|
|
17
|
+
// validate language choosen
|
|
18
|
+
if (options.language) {
|
|
19
|
+
if (options.language !== "js" && options.language !== "ts") {
|
|
20
|
+
console.log(options.language);
|
|
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 = options.language;
|
|
25
|
+
writeConfig(config);
|
|
26
|
+
console.log(chalk.cyan(`Default project language is now ${chalk.bold(config.language)}`));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// validate paradigm choosen
|
|
30
|
+
if (options.paradigm) {
|
|
31
|
+
if (options.paradigm !== "oop" && options.paradigm !== "functional") {
|
|
32
|
+
console.log(chalk.red(`Invalid programming paradigm, must be either ${chalk.bold("oop")} or ${chalk.bold("functional")}`));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
config.paradigm = options.paradigm;
|
|
36
|
+
writeConfig(config);
|
|
37
|
+
console.log(chalk.cyan(`Default programming paradigm is now ${chalk.bold(config.paradigm)}`));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// validate database choosen
|
|
41
|
+
if (options.database) {
|
|
42
|
+
if (!dbOptions.includes(options.database)) {
|
|
43
|
+
console.log(chalk.red(`Invalid database value, must be either of these: ${dbOptions.join(", ")} `));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
config.database = options.database;
|
|
47
|
+
writeConfig(config);
|
|
48
|
+
console.log(chalk.cyan(`Default project database is now ${chalk.bold(config.database)}`));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// validate generateFolder
|
|
52
|
+
if (options.generateFolder) {
|
|
53
|
+
if (options.generateFolder !== "true" &&
|
|
54
|
+
options.generateFolder !== "false") {
|
|
55
|
+
console.log(chalk.red(`Invalid folder generation value, value must be ${chalk.bold("true")} or ${chalk.bold("false")}`));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
config.generateFolder = options.generateFolder;
|
|
59
|
+
writeConfig(config);
|
|
60
|
+
console.log(chalk.cyan(`Generation of folder files for the Services, Models, Controllers and Routes set to ${chalk.bold(config.generateFolder)}`));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
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`)));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { getUserConfigFilePath } from "./get_user_config_path.js";
|
|
3
|
+
import { readFileSync } from "fs";
|
|
4
|
+
import yaml from "js-yaml";
|
|
5
|
+
const filePath = getUserConfigFilePath();
|
|
6
|
+
export const readConfig = () => {
|
|
7
|
+
try {
|
|
8
|
+
const data = readFileSync(filePath, "utf8");
|
|
9
|
+
const yamlData = yaml.load(data);
|
|
10
|
+
const jsonData = JSON.stringify(yamlData);
|
|
11
|
+
return JSON.parse(jsonData.toString());
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
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 🥹")));
|
|
16
|
+
process.exit(1);
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { getRootDirectory } from "./get_root_dir_path.js";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
export function writeDolphConfig() {
|
|
5
|
+
const dolphConfigContent = `port: 3300
|
|
6
|
+
`;
|
|
7
|
+
const filePath = join(getRootDirectory(), "dolph_config.yaml");
|
|
8
|
+
fs.writeFileSync(filePath, dolphConfigContent, { encoding: "utf-8" });
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { getRootDirectory } from "./get_root_dir_path.js";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
export function writeGitignore() {
|
|
5
|
+
const gitignoreContent = `node_modules
|
|
6
|
+
.env
|
|
7
|
+
logs
|
|
8
|
+
yarn-error.log
|
|
9
|
+
`;
|
|
10
|
+
const filePath = join(getRootDirectory(), ".gitignore");
|
|
11
|
+
fs.writeFileSync(filePath, gitignoreContent, { encoding: "utf-8" });
|
|
12
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { getRootDirectory } from "./get_root_dir_path.js";
|
|
4
|
+
export function writePackageJsonFile(name, extension) {
|
|
5
|
+
const packageJsonContent = extension === "ts"
|
|
6
|
+
? `{
|
|
7
|
+
"name": "${name}",
|
|
8
|
+
"version": "1.0.0",
|
|
9
|
+
"main": "app/server.js",
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=18.0.0"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev:start": "cross-env NODE_ENV=development nodemon",
|
|
17
|
+
"dev:docker:start": "docker-compose -f docker-compose-dev.yml up",
|
|
18
|
+
"dev:docker:stop": "docker-compose -f docker-compose-dev.yml down",
|
|
19
|
+
"build": "swc src -d app --source-maps --copy-files",
|
|
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"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@dolphjs/dolph": "^1.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@swc/cli": "^0.1.62",
|
|
30
|
+
"@swc/core": "^1.3.91",
|
|
31
|
+
"@types/express": "^4.17.18",
|
|
32
|
+
"@types/node": "^20.8.2",
|
|
33
|
+
"cross-env": "^7.0.3",
|
|
34
|
+
"ts-node": "^10.9.1",
|
|
35
|
+
"tsc-alias": "^1.8.8",
|
|
36
|
+
"tsconfig-paths": "^4.2.0",
|
|
37
|
+
"typescript": "^5.2.2"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`
|
|
41
|
+
: `{
|
|
42
|
+
"name": "${name}",
|
|
43
|
+
"version": "1.0.0",
|
|
44
|
+
"main": "src/server.js",
|
|
45
|
+
"author": "",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"dev:start": "cross-env NODE_ENV=development nodemon",
|
|
52
|
+
"dev:docker:start": "docker-compose -f docker-compose-dev.yml up",
|
|
53
|
+
"dev:docker:stop": "docker-compose -f docker-compose-dev.yml down",
|
|
54
|
+
"prod:start": "node src/server.js",
|
|
55
|
+
"clean": "rm -r logs",
|
|
56
|
+
"start": "npm run prod:start"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@dolphjs/dolph": "^1.1.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"cross-env": "^7.0.3"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
const filePath = join(getRootDirectory(), "package.json");
|
|
67
|
+
fs.writeFileSync(filePath, packageJsonContent, { encoding: "utf-8" });
|
|
68
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { getRootDirectory } from "./get_root_dir_path.js";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
export function writeSwcrc() {
|
|
5
|
+
const swcrcContent = `{
|
|
6
|
+
"jsc": {
|
|
7
|
+
"parser": {
|
|
8
|
+
"syntax": "typescript",
|
|
9
|
+
"tsx": false,
|
|
10
|
+
"dynamicImport": true,
|
|
11
|
+
"decorators": true
|
|
12
|
+
},
|
|
13
|
+
"transform": {
|
|
14
|
+
"legacyDecorator": true,
|
|
15
|
+
"decoratorMetadata": true
|
|
16
|
+
},
|
|
17
|
+
"target": "es2022",
|
|
18
|
+
"externalHelpers": false,
|
|
19
|
+
"keepClassNames": true,
|
|
20
|
+
"loose": false,
|
|
21
|
+
"minify": {
|
|
22
|
+
"compress": false,
|
|
23
|
+
"mangle": false
|
|
24
|
+
},
|
|
25
|
+
"baseUrl": "src",
|
|
26
|
+
"paths": {
|
|
27
|
+
"@/*": ["*"],
|
|
28
|
+
"@/configs/*": ["configs/*"],
|
|
29
|
+
"@/controllers/*": ["controllers/*"],
|
|
30
|
+
"@/dtos/*": ["dtos/*"],
|
|
31
|
+
"@/interfaces/*": ["interfaces/*"],
|
|
32
|
+
"@/middlewares/*": ["middlewares/*"],
|
|
33
|
+
"@/models/*": ["models/*"],
|
|
34
|
+
"@/routes/*": ["routes/*"],
|
|
35
|
+
"@/services/*": ["services/*"],
|
|
36
|
+
"@/utils/*": ["utils/*"],
|
|
37
|
+
"@/constants/*": ["constants/*"],
|
|
38
|
+
"@/validations/*": ["validations/*"]
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"module": {
|
|
42
|
+
"type": "commonjs"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
const filePath = join(getRootDirectory(), ".swcrc");
|
|
47
|
+
fs.writeFileSync(filePath, swcrcContent, { encoding: "utf-8" });
|
|
48
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { getRootDirectory } from "./get_root_dir_path.js";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
export function writeTsConfigFile() {
|
|
5
|
+
const tsConfigContent = `{
|
|
6
|
+
"exclude": ["node_modules"],
|
|
7
|
+
"compilerOptions": {
|
|
8
|
+
"allowJs": false,
|
|
9
|
+
"declaration": false,
|
|
10
|
+
"experimentalDecorators": true,
|
|
11
|
+
"sourceMap": false,
|
|
12
|
+
"useUnknownInCatchVariables": false,
|
|
13
|
+
"strictFunctionTypes": false,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"esModuleInterop": true,
|
|
17
|
+
"target": "ES2022",
|
|
18
|
+
"baseUrl": "src",
|
|
19
|
+
"outDir": "app",
|
|
20
|
+
"pretty": true,
|
|
21
|
+
"module": "commonjs",
|
|
22
|
+
"paths": {
|
|
23
|
+
"@/*": ["*"],
|
|
24
|
+
"@/configs/*": ["configs/*"],
|
|
25
|
+
"@/controllers/*": ["controllers/*"],
|
|
26
|
+
"@/dtos/*": ["dtos/*"],
|
|
27
|
+
"@/interfaces/*": ["interfaces/*"],
|
|
28
|
+
"@/middlewares/*": ["middlewares/*"],
|
|
29
|
+
"@/models/*": ["models/*"],
|
|
30
|
+
"@/routes/*": ["routes/*"],
|
|
31
|
+
"@/services/*": ["services/*"],
|
|
32
|
+
"@/utils/*": ["utils/*"],
|
|
33
|
+
"@/constants/*": ["constants/*"],
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"include": ["src/", ".env"],
|
|
37
|
+
"ts-node": {
|
|
38
|
+
"compilerOptions": {
|
|
39
|
+
"module": "CommonJS"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}`;
|
|
43
|
+
const filePath = join(getRootDirectory(), "tsconfig.json");
|
|
44
|
+
fs.writeFileSync(filePath, tsConfigContent, { encoding: "utf-8" });
|
|
45
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import yaml from "js-yaml";
|
|
3
|
+
import { getUserConfigFilePath } from "./get_user_config_path.js";
|
|
4
|
+
import { writeFileSync } from "fs";
|
|
5
|
+
const filePath = getUserConfigFilePath();
|
|
6
|
+
export const writeConfig = (config) => {
|
|
7
|
+
try {
|
|
8
|
+
const yamlString = yaml.dump(config);
|
|
9
|
+
writeFileSync(filePath, yamlString, "utf8");
|
|
10
|
+
console.log(chalk.green("Configurations saved successfully! 😎."));
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
console.log(chalk.bold(chalk.red("Error encountered reading config file, please run 'dolph-cli tr' to initialize config file 🥹")));
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
};
|