@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Dolph
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFile } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { readConfig } from "../utils/read_user_config_path.js";
|
|
5
|
+
import { resolveControllerContent } from "./resolvers/resolve_controller_content.js";
|
|
6
|
+
const createControllerDirectory = () => {
|
|
7
|
+
const projectRoot = path.join(process.cwd());
|
|
8
|
+
const userControllerFilePath = path.join(projectRoot, "/src/controllers");
|
|
9
|
+
if (!existsSync(userControllerFilePath)) {
|
|
10
|
+
mkdirSync(userControllerFilePath);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
// removed other possible dirs to enforce dolphjs style guide
|
|
14
|
+
const findControllerDirectory = () => {
|
|
15
|
+
const rootDir = process.cwd();
|
|
16
|
+
const possibleDirs = [
|
|
17
|
+
"/src/controllers",
|
|
18
|
+
// "/src/Controllers",
|
|
19
|
+
// "/src/controller",
|
|
20
|
+
// "/src/Controller",
|
|
21
|
+
// "/Controller",
|
|
22
|
+
// "/Controllers",
|
|
23
|
+
// "/controllers",
|
|
24
|
+
// "/controller",
|
|
25
|
+
];
|
|
26
|
+
const controllerDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
|
|
27
|
+
return controllerDir ? path.join(rootDir, controllerDir) : null;
|
|
28
|
+
};
|
|
29
|
+
export const generateControllerFile = async (name, controllerDir, readConfig) => {
|
|
30
|
+
await writeFile(controllerDir, resolveControllerContent(readConfig, name), (error) => {
|
|
31
|
+
if (error) {
|
|
32
|
+
console.log(chalk.bold(chalk.red(error.toString())));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const generateController = async (name) => {
|
|
37
|
+
if (!name)
|
|
38
|
+
chalk.bold(chalk.red("Controller extension or name is required! 🤨"));
|
|
39
|
+
let controllerDir = findControllerDirectory();
|
|
40
|
+
if (!controllerDir) {
|
|
41
|
+
//TODO: create one if it doesn't exist
|
|
42
|
+
// console.log(
|
|
43
|
+
// chalk.bold(chalk.red("controller directory doesn't exist 🤨"))
|
|
44
|
+
// );
|
|
45
|
+
// return;
|
|
46
|
+
createControllerDirectory();
|
|
47
|
+
controllerDir = findControllerDirectory();
|
|
48
|
+
}
|
|
49
|
+
const controllerDirName = path.join(controllerDir, name);
|
|
50
|
+
const controllerFilePath = path.join(controllerDirName + `/${name}.controller.${readConfig().language}`);
|
|
51
|
+
try {
|
|
52
|
+
// Create the generate controller path
|
|
53
|
+
if (readConfig().generateFolder === "true" || true) {
|
|
54
|
+
mkdirSync(controllerDirName);
|
|
55
|
+
}
|
|
56
|
+
//TODO: if no index.ts file, create one too
|
|
57
|
+
generateControllerFile(name, path.join(controllerFilePath), readConfig
|
|
58
|
+
// controllerDirName,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
console.log(chalk.bold(chalk.red(e)));
|
|
63
|
+
}
|
|
64
|
+
console.log(`${chalk.bold(chalk.green(`${name}.controller.${readConfig().language} generated successfully! 🙃`))}`);
|
|
65
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFile } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { readConfig } from "../utils/read_user_config_path.js";
|
|
5
|
+
import { resolveModelContent } from "./resolvers/resolve_model_content.js";
|
|
6
|
+
const createModelDirectory = () => {
|
|
7
|
+
const projectRoot = path.join(process.cwd());
|
|
8
|
+
const userModelFilePath = path.join(projectRoot, "/src/models");
|
|
9
|
+
if (!existsSync(userModelFilePath)) {
|
|
10
|
+
mkdirSync(userModelFilePath);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
// removed other possible dirs to enforce dolphjs style guide
|
|
14
|
+
const findModelDirectory = () => {
|
|
15
|
+
const rootDir = process.cwd();
|
|
16
|
+
const possibleDirs = [
|
|
17
|
+
"/src/models",
|
|
18
|
+
// "/src/Models",
|
|
19
|
+
// "/src/model",
|
|
20
|
+
// "/src/Model",
|
|
21
|
+
// "/Models",
|
|
22
|
+
// "/Model",
|
|
23
|
+
// "/models",
|
|
24
|
+
// "/model",
|
|
25
|
+
];
|
|
26
|
+
const modelDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
|
|
27
|
+
return modelDir ? path.join(rootDir, modelDir) : null;
|
|
28
|
+
};
|
|
29
|
+
export const generateModelFile = async (name, modelDir, readConfig) => {
|
|
30
|
+
await writeFile(modelDir, resolveModelContent(readConfig, name), (error) => {
|
|
31
|
+
if (error) {
|
|
32
|
+
console.log(chalk.bold(chalk.red(error.toString())));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const generateModel = async (name) => {
|
|
37
|
+
if (!name)
|
|
38
|
+
chalk.bold(chalk.red("Model extension or name is required! 🤨"));
|
|
39
|
+
let modelDir = findModelDirectory();
|
|
40
|
+
if (!modelDir) {
|
|
41
|
+
//TODO: create one if it doesn't exist
|
|
42
|
+
// console.log(chalk.bold(chalk.red("Model directory doesn't exist 🤨")));
|
|
43
|
+
// return;
|
|
44
|
+
createModelDirectory();
|
|
45
|
+
modelDir = findModelDirectory();
|
|
46
|
+
}
|
|
47
|
+
const modelDirName = path.join(modelDir, name);
|
|
48
|
+
const modelFilePath = path.join(modelDirName + `/${name}.model.${readConfig().language}`);
|
|
49
|
+
try {
|
|
50
|
+
// Create the generate controller path
|
|
51
|
+
mkdirSync(modelDirName);
|
|
52
|
+
//TODO: if no index.ts file, create one too
|
|
53
|
+
generateModelFile(name, path.join(modelFilePath), readConfig
|
|
54
|
+
// modelDirName,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.log(chalk.bold(chalk.red(e)));
|
|
59
|
+
}
|
|
60
|
+
console.log(`${chalk.bold(chalk.green(`${name}.model.${readConfig().language} generated successfully! 🙃`))}`);
|
|
61
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFile } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { readConfig } from "../utils/read_user_config_path.js";
|
|
5
|
+
import { resolveMySqlContent } from "./resolvers/resolve_model_content.js";
|
|
6
|
+
const createConfigDirectory = () => {
|
|
7
|
+
const projectRoot = path.join(process.cwd());
|
|
8
|
+
const userConfigFilePath = path.join(projectRoot, "/src/configs");
|
|
9
|
+
if (!existsSync(userConfigFilePath)) {
|
|
10
|
+
mkdirSync(userConfigFilePath);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
// removed other possible dirs to enforce dolphjs style guide
|
|
14
|
+
const findConfigDirectory = () => {
|
|
15
|
+
const rootDir = process.cwd();
|
|
16
|
+
const possibleDirs = [
|
|
17
|
+
// "/src/Configs",
|
|
18
|
+
// "/src/Config",
|
|
19
|
+
"/src/configs",
|
|
20
|
+
// "/src/config",
|
|
21
|
+
// "/Configs",
|
|
22
|
+
// "/configs",
|
|
23
|
+
// "/config",
|
|
24
|
+
// "/Config",
|
|
25
|
+
];
|
|
26
|
+
const configDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
|
|
27
|
+
return configDir ? path.join(rootDir, configDir) : null;
|
|
28
|
+
};
|
|
29
|
+
export const generateConfigFile = async (name, configDir, readConfig) => {
|
|
30
|
+
await writeFile(configDir, resolveMySqlContent(readConfig), (error) => {
|
|
31
|
+
if (error) {
|
|
32
|
+
console.log(chalk.bold(chalk.red(error.toString())));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const generateConfig = async (name) => {
|
|
37
|
+
if (!name)
|
|
38
|
+
chalk.bold(chalk.red("Config extension or name is required! 🤨"));
|
|
39
|
+
let configDir = findConfigDirectory();
|
|
40
|
+
if (!configDir) {
|
|
41
|
+
//TODO: create one if it doesn't exist
|
|
42
|
+
// console.log(chalk.bold(chalk.red("Config directory doesn't exist 🤨")));
|
|
43
|
+
// return;
|
|
44
|
+
createConfigDirectory();
|
|
45
|
+
configDir = findConfigDirectory();
|
|
46
|
+
}
|
|
47
|
+
const configDirName = configDir;
|
|
48
|
+
const configFilePath = path.join(configDirName + `/db.configs.${readConfig().language}`);
|
|
49
|
+
try {
|
|
50
|
+
// Create the generate controller path
|
|
51
|
+
// if (readConfig().generateFolder === "true" || true) {
|
|
52
|
+
// mkdirSync(configDirName);
|
|
53
|
+
// }
|
|
54
|
+
//TODO: if no index.ts file, create one too
|
|
55
|
+
generateConfigFile(name, path.join(configFilePath), readConfig
|
|
56
|
+
// configDirName,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.log(chalk.bold(chalk.red(e)));
|
|
61
|
+
}
|
|
62
|
+
console.log(`${chalk.bold(chalk.green(`db.config.${readConfig().language} generated successfully! 🙃`))}`);
|
|
63
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFile } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { readConfig } from "../utils/read_user_config_path.js";
|
|
5
|
+
import { resolveRoutesContent } from "./resolvers/resolve_routes_content.js";
|
|
6
|
+
const createRoutesDirectory = () => {
|
|
7
|
+
const projectRoot = path.join(process.cwd());
|
|
8
|
+
const userRoutesFilePath = path.join(projectRoot, "/src/routes");
|
|
9
|
+
if (!existsSync(userRoutesFilePath)) {
|
|
10
|
+
mkdirSync(userRoutesFilePath);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
// removed other possible dirs to enforce dolphjs style guide
|
|
14
|
+
const findRoutesDirectory = () => {
|
|
15
|
+
const rootDir = process.cwd();
|
|
16
|
+
const possibleDirs = [
|
|
17
|
+
"/src/routes",
|
|
18
|
+
// "/src/Routes",
|
|
19
|
+
// "/Routes",
|
|
20
|
+
// "/routes"
|
|
21
|
+
];
|
|
22
|
+
const routesDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
|
|
23
|
+
return routesDir ? path.join(rootDir, routesDir) : null;
|
|
24
|
+
};
|
|
25
|
+
export const generateRoutesFile = async (name, routesDir, readConfig) => {
|
|
26
|
+
await writeFile(routesDir, resolveRoutesContent(readConfig, name), (error) => {
|
|
27
|
+
if (error) {
|
|
28
|
+
console.log(chalk.bold(chalk.red(error.toString())));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
export const generateRouter = async (name) => {
|
|
33
|
+
if (!name)
|
|
34
|
+
chalk.bold(chalk.red("Routes extension or name is required! 🤨"));
|
|
35
|
+
let routesDir = findRoutesDirectory();
|
|
36
|
+
if (!routesDir) {
|
|
37
|
+
//TODO: create one if it doesn't exist
|
|
38
|
+
// console.log(chalk.bold(chalk.red("routes directory doesn't exist 🤨")));
|
|
39
|
+
// return;
|
|
40
|
+
createRoutesDirectory();
|
|
41
|
+
routesDir = findRoutesDirectory();
|
|
42
|
+
}
|
|
43
|
+
const routesDirName = path.join(routesDir, name);
|
|
44
|
+
const routesFilePath = path.join(routesDirName + `/${name}.routes.${readConfig().language}`);
|
|
45
|
+
try {
|
|
46
|
+
// Create the generate controller path
|
|
47
|
+
if (readConfig().generateFolder === "true" || true) {
|
|
48
|
+
mkdirSync(routesDirName);
|
|
49
|
+
}
|
|
50
|
+
//TODO: if no index.ts file, create one too
|
|
51
|
+
generateRoutesFile(name, path.join(routesFilePath), readConfig
|
|
52
|
+
// routesDirName,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.log(chalk.bold(chalk.red(e)));
|
|
57
|
+
}
|
|
58
|
+
console.log(`${chalk.bold(chalk.green(`${name}.routes.${readConfig().language} generated successfully! 🙃`))}`);
|
|
59
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFile } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { readConfig } from "../utils/read_user_config_path.js";
|
|
5
|
+
import { resolveServiceContent } from "./resolvers/resolve_service_content.js";
|
|
6
|
+
const createServiceDirectory = () => {
|
|
7
|
+
const projectRoot = path.join(process.cwd());
|
|
8
|
+
const userServiceFilePath = path.join(projectRoot, "/src/services");
|
|
9
|
+
if (!existsSync(userServiceFilePath)) {
|
|
10
|
+
mkdirSync(userServiceFilePath);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
// removed other possible dirs to enforce dolphjs style guide
|
|
14
|
+
const findServiceDirectory = () => {
|
|
15
|
+
const rootDir = process.cwd();
|
|
16
|
+
const possibleDirs = [
|
|
17
|
+
"/src/services",
|
|
18
|
+
// "/src/Services",
|
|
19
|
+
// "/src/service",
|
|
20
|
+
// "/src/Services",
|
|
21
|
+
// "/Service",
|
|
22
|
+
// "/Services",
|
|
23
|
+
// "/services",
|
|
24
|
+
// "/service",
|
|
25
|
+
];
|
|
26
|
+
const serviceDir = possibleDirs.find((dir) => existsSync(path.join(rootDir, dir)));
|
|
27
|
+
return serviceDir ? path.join(rootDir, serviceDir) : null;
|
|
28
|
+
};
|
|
29
|
+
export const generateServiceFile = async (name, serviceDir, readConfig) => {
|
|
30
|
+
await writeFile(serviceDir, resolveServiceContent(readConfig, name), (error) => {
|
|
31
|
+
if (error) {
|
|
32
|
+
console.log(chalk.bold(chalk.red(error.toString())));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const generateService = async (name) => {
|
|
37
|
+
if (!name)
|
|
38
|
+
chalk.bold(chalk.red("Service extension or name is required! 🤨"));
|
|
39
|
+
let serviceDir = findServiceDirectory();
|
|
40
|
+
if (!serviceDir) {
|
|
41
|
+
//TODO: create one if it doesn't exist
|
|
42
|
+
// console.log(chalk.bold(chalk.red("Service directory doesn't exist 🤨")));
|
|
43
|
+
// return;
|
|
44
|
+
createServiceDirectory();
|
|
45
|
+
serviceDir = findServiceDirectory();
|
|
46
|
+
}
|
|
47
|
+
const serviceDirName = path.join(serviceDir, name);
|
|
48
|
+
const serviceFilePath = path.join(serviceDirName + `/${name}.service.${readConfig().language}`);
|
|
49
|
+
try {
|
|
50
|
+
// Create the generate controller path
|
|
51
|
+
if (readConfig().generateFolder === "true" || true) {
|
|
52
|
+
mkdirSync(serviceDirName);
|
|
53
|
+
}
|
|
54
|
+
//TODO: if no index.ts file, create one too
|
|
55
|
+
generateServiceFile(name, path.join(serviceFilePath), readConfig
|
|
56
|
+
// serviceDirName,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.log(chalk.bold(chalk.red(e)));
|
|
61
|
+
}
|
|
62
|
+
console.log(`${chalk.bold(chalk.green(`${name}.service.${readConfig().language} generated successfully! 🙃`))}`);
|
|
63
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// import { readConfig } from "utils/read_user_config_path.js";
|
|
2
|
+
import * as generateControllerTemplate from "../templates/controller_template.js";
|
|
3
|
+
export const resolveControllerContent = (readConfig, controllerName) => {
|
|
4
|
+
if (readConfig().language === "js" && readConfig().paradigm === "oop") {
|
|
5
|
+
return generateControllerTemplate.generateOopJsTemplate(controllerName);
|
|
6
|
+
}
|
|
7
|
+
else if (readConfig().language === "js" &&
|
|
8
|
+
readConfig().paradigm === "functional") {
|
|
9
|
+
return generateControllerTemplate.generateFnJsTemplate(controllerName);
|
|
10
|
+
}
|
|
11
|
+
else if (readConfig().language === "ts" &&
|
|
12
|
+
readConfig().paradigm === "oop") {
|
|
13
|
+
return generateControllerTemplate.generateOopTsTemplate(controllerName);
|
|
14
|
+
}
|
|
15
|
+
else if (readConfig().language === "ts" &&
|
|
16
|
+
readConfig().paradigm === "functional") {
|
|
17
|
+
return generateControllerTemplate.generateFnTsTemplate(controllerName);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// import { readConfig } from "utils/read_user_config_path.js";
|
|
2
|
+
import * as generateModelTemplate from "../templates/model_template.js";
|
|
3
|
+
import * as generateMySqlTemplate from "../templates/mysql_config_template.js";
|
|
4
|
+
export const resolveModelContent = (readConfig, modelName) => {
|
|
5
|
+
if (readConfig().language === "js" && readConfig().paradigm === "oop") {
|
|
6
|
+
return generateModelTemplate.generateOopJsTemplate(modelName, readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
7
|
+
}
|
|
8
|
+
else if (readConfig().language === "js" &&
|
|
9
|
+
readConfig().paradigm === "functional") {
|
|
10
|
+
return generateModelTemplate.generateFnJsTemplate(modelName, readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
11
|
+
}
|
|
12
|
+
else if (readConfig().language === "ts" &&
|
|
13
|
+
readConfig().paradigm === "oop") {
|
|
14
|
+
return generateModelTemplate.generateOopTsTemplate(modelName, readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
15
|
+
}
|
|
16
|
+
else if (readConfig().language === "ts" &&
|
|
17
|
+
readConfig().paradigm === "functional") {
|
|
18
|
+
return generateModelTemplate.generateFnTsTemplate(modelName, readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export const resolveMySqlContent = (readConfig) => {
|
|
22
|
+
if (readConfig().language === "js" && readConfig().paradigm === "oop") {
|
|
23
|
+
return generateMySqlTemplate.generateOopJsTemplate();
|
|
24
|
+
}
|
|
25
|
+
else if (readConfig().language === "js" &&
|
|
26
|
+
readConfig().paradigm === "functional") {
|
|
27
|
+
return generateMySqlTemplate.generateFnJsTemplate();
|
|
28
|
+
}
|
|
29
|
+
else if (readConfig().language === "ts" &&
|
|
30
|
+
readConfig().paradigm === "oop") {
|
|
31
|
+
return generateMySqlTemplate.generateOopTsTemplate();
|
|
32
|
+
}
|
|
33
|
+
else if (readConfig().language === "ts" &&
|
|
34
|
+
readConfig().paradigm === "functional") {
|
|
35
|
+
return generateMySqlTemplate.generateFnTsTemplate();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// import { readConfig } from "utils/read_user_config_path.js";
|
|
2
|
+
import * as generateRoutesTemplate from "../templates/routes_template.js";
|
|
3
|
+
export const resolveRoutesContent = (readConfig, routerName) => {
|
|
4
|
+
if (readConfig().language === "js" && readConfig().paradigm === "oop") {
|
|
5
|
+
return generateRoutesTemplate.generateOopJsTemplate(routerName);
|
|
6
|
+
}
|
|
7
|
+
else if (readConfig().language === "js" &&
|
|
8
|
+
readConfig().paradigm === "functional") {
|
|
9
|
+
return generateRoutesTemplate.generateFnJsTemplate(routerName);
|
|
10
|
+
}
|
|
11
|
+
else if (readConfig().language === "ts" &&
|
|
12
|
+
readConfig().paradigm === "oop") {
|
|
13
|
+
return generateRoutesTemplate.generateOopTsTemplate(routerName);
|
|
14
|
+
}
|
|
15
|
+
else if (readConfig().language === "ts" &&
|
|
16
|
+
readConfig().paradigm === "functional") {
|
|
17
|
+
return generateRoutesTemplate.generateFnTsTemplate(routerName);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// import { readConfig } from "utils/read_user_config_path.js";
|
|
2
|
+
import * as generateServiceTemplate from "../templates/service_template.js";
|
|
3
|
+
export const resolveServiceContent = (readConfig, serviceName) => {
|
|
4
|
+
if (readConfig().language === "js" && readConfig().paradigm === "oop") {
|
|
5
|
+
return generateServiceTemplate.generateOopJsTemplate(serviceName, readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
6
|
+
}
|
|
7
|
+
else if (readConfig().language === "js" &&
|
|
8
|
+
readConfig().paradigm === "functional") {
|
|
9
|
+
return generateServiceTemplate.generateFnJsTemplate(serviceName);
|
|
10
|
+
}
|
|
11
|
+
else if (readConfig().language === "ts" &&
|
|
12
|
+
readConfig().paradigm === "oop") {
|
|
13
|
+
return generateServiceTemplate.generateOopTsTemplate(serviceName, readConfig().database === "mongo" ? true : false, readConfig().database === "mysql" ? true : false);
|
|
14
|
+
}
|
|
15
|
+
else if (readConfig().language === "ts" &&
|
|
16
|
+
readConfig().paradigm === "functional") {
|
|
17
|
+
return generateServiceTemplate.generateFnTsTemplate(serviceName);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const generateOopTsTemplate = (controllerName) => {
|
|
2
|
+
let template;
|
|
3
|
+
const capitalizeFirstLetter = (str) => {
|
|
4
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
5
|
+
};
|
|
6
|
+
const className = capitalizeFirstLetter(controllerName) + "Controller";
|
|
7
|
+
template = `
|
|
8
|
+
import { DolphControllerHandler } from "@dolphjs/dolph/classes";
|
|
9
|
+
import {
|
|
10
|
+
Dolph,
|
|
11
|
+
SuccessResponse,
|
|
12
|
+
TryCatchAsyncDec,
|
|
13
|
+
DRequest,
|
|
14
|
+
DResponse
|
|
15
|
+
} from "@dolphjs/dolph/common";
|
|
16
|
+
|
|
17
|
+
export class ${className} extends DolphControllerHandler<Dolph> {
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@TryCatchAsyncDec
|
|
23
|
+
public async defaultMethod (req: DRequest, res: DResponse) {
|
|
24
|
+
SuccessResponse({ res, body: { message: "${controllerName} is working!" } });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
return template;
|
|
29
|
+
};
|
|
30
|
+
const generateOopJsTemplate = (controllerName) => {
|
|
31
|
+
let template;
|
|
32
|
+
const capitalizeFirstLetter = (str) => {
|
|
33
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
34
|
+
};
|
|
35
|
+
const className = capitalizeFirstLetter(controllerName) + "Controller";
|
|
36
|
+
template = `
|
|
37
|
+
const { DolphControllerHandler } = require("@dolphjs/dolph/classes");
|
|
38
|
+
const {
|
|
39
|
+
SuccessResponse,
|
|
40
|
+
TryCatchAsyncFn,
|
|
41
|
+
} = require("@dolphjs/dolph/common");
|
|
42
|
+
|
|
43
|
+
class ${className} extends DolphControllerHandler {
|
|
44
|
+
constructor() {
|
|
45
|
+
super();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
defaultMethod = TryCatchAsyncFn (async (req, res) => {
|
|
49
|
+
SuccessResponse({ res, body: { message: "${controllerName} is working!" } });
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { ${className} }
|
|
54
|
+
`;
|
|
55
|
+
return template;
|
|
56
|
+
};
|
|
57
|
+
const generateFnTsTemplate = (controllerName) => {
|
|
58
|
+
let template;
|
|
59
|
+
template = `
|
|
60
|
+
import { TryCatchAsyncFn, SuccessResponse, DRequest, DResponse } from "@dolphjs/dolph/common";
|
|
61
|
+
|
|
62
|
+
export const defaultFunc = TryCatchAsyncFn(async (req: DRequest, res: DResponse) => {
|
|
63
|
+
SuccessResponse({ res, body: { message: "${controllerName} working!" } });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
`;
|
|
67
|
+
return template;
|
|
68
|
+
};
|
|
69
|
+
const generateFnJsTemplate = (controllerName) => {
|
|
70
|
+
let template;
|
|
71
|
+
template = `
|
|
72
|
+
const { TryCatchAsyncFn, SuccessResponse } = require("@dolphjs/dolph/common");
|
|
73
|
+
|
|
74
|
+
const defaultFunc = TryCatchAsyncFn(async (req, res) => {
|
|
75
|
+
SuccessResponse({ res, body: { message: "${controllerName} working!" } });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
module.exports = { defaultFunc };
|
|
79
|
+
|
|
80
|
+
`;
|
|
81
|
+
return template;
|
|
82
|
+
};
|
|
83
|
+
export { generateFnJsTemplate, generateFnTsTemplate, generateOopJsTemplate, generateOopTsTemplate, };
|