@apso/cli 0.3.0 → 0.3.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.
|
@@ -10,13 +10,13 @@ export default class New extends BaseCommand {
|
|
|
10
10
|
static args: {
|
|
11
11
|
name: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
|
|
12
12
|
};
|
|
13
|
-
installModules(
|
|
14
|
-
formatApp(
|
|
15
|
-
startApp(
|
|
13
|
+
installModules(projectPath: string): Promise<void>;
|
|
14
|
+
formatApp(projectPath: string): Promise<void>;
|
|
15
|
+
startApp(projectPath: string): Promise<void>;
|
|
16
16
|
cloneTemplate(projectPath: string): Promise<void>;
|
|
17
|
-
run(): Promise<void>;
|
|
18
17
|
validateFlags(): Promise<{
|
|
19
18
|
projectName: string;
|
|
20
19
|
apiType: string;
|
|
21
20
|
}>;
|
|
21
|
+
run(): Promise<void>;
|
|
22
22
|
}
|
|
@@ -12,28 +12,25 @@ class New extends base_command_1.default {
|
|
|
12
12
|
super(...arguments);
|
|
13
13
|
this.CURR_DIR = process.cwd();
|
|
14
14
|
}
|
|
15
|
-
async installModules(
|
|
16
|
-
this.log("
|
|
17
|
-
await this.runNpmCommand(["install", "--force", "--prefix",
|
|
15
|
+
async installModules(projectPath) {
|
|
16
|
+
this.log("Installing modules...");
|
|
17
|
+
await this.runNpmCommand(["install", "--force", "--prefix", projectPath]);
|
|
18
18
|
}
|
|
19
|
-
async formatApp(
|
|
20
|
-
this.log("
|
|
21
|
-
shelljs_1.default.cd(
|
|
22
|
-
await this.runNpmCommand(["run", "format", "--prefix",
|
|
19
|
+
async formatApp(projectPath) {
|
|
20
|
+
this.log("Formatting code...");
|
|
21
|
+
shelljs_1.default.cd(projectPath);
|
|
22
|
+
await this.runNpmCommand(["run", "format", "--prefix", projectPath]);
|
|
23
23
|
}
|
|
24
|
-
async startApp(
|
|
24
|
+
async startApp(projectPath) {
|
|
25
25
|
return new Promise((resolve, reject) => {
|
|
26
|
-
const
|
|
26
|
+
const isWindows = process.platform === "win32";
|
|
27
|
+
const command = isWindows ? "npm.cmd" : "npm";
|
|
27
28
|
const args = ["start"];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// args.push('--cwd')
|
|
34
|
-
// args.push(root)
|
|
35
|
-
// args.push('--verbose')
|
|
36
|
-
const child = (0, child_process_1.spawn)(command, args, { stdio: "inherit", cwd: root });
|
|
29
|
+
const child = (0, child_process_1.spawn)(command, args, {
|
|
30
|
+
cwd: projectPath,
|
|
31
|
+
stdio: "inherit",
|
|
32
|
+
shell: isWindows,
|
|
33
|
+
});
|
|
37
34
|
child.on("close", (code) => {
|
|
38
35
|
if (code !== 0) {
|
|
39
36
|
reject({
|
|
@@ -43,15 +40,18 @@ class New extends base_command_1.default {
|
|
|
43
40
|
}
|
|
44
41
|
resolve();
|
|
45
42
|
});
|
|
43
|
+
child.on("error", (err) => {
|
|
44
|
+
this.log(`Error starting app: ${err.message}`);
|
|
45
|
+
reject(err);
|
|
46
|
+
});
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
async cloneTemplate(projectPath) {
|
|
49
|
-
this.log("
|
|
50
|
+
this.log("Cloning service template...");
|
|
50
51
|
if (!fs.existsSync(projectPath) && this.CURR_DIR !== projectPath) {
|
|
51
52
|
fs.mkdirSync(projectPath);
|
|
52
53
|
}
|
|
53
54
|
shelljs_1.default.cd(projectPath);
|
|
54
|
-
// Execute git clone and capture the result using HTTPS
|
|
55
55
|
const cloneResult = shelljs_1.default.exec(`git clone --depth=1 --branch=main https://github.com/apsoai/service-template.git ${projectPath}`, { silent: true }); // Use silent: true to suppress default output
|
|
56
56
|
// Check if the command failed
|
|
57
57
|
if (cloneResult.code !== 0) {
|
|
@@ -66,34 +66,31 @@ class New extends base_command_1.default {
|
|
|
66
66
|
shelljs_1.default.exec(`rm -rf ${projectPath}/.git`);
|
|
67
67
|
shelljs_1.default.cd(this.CURR_DIR);
|
|
68
68
|
}
|
|
69
|
-
async run() {
|
|
70
|
-
this.log("Initializing New Apso Server...");
|
|
71
|
-
const { projectName,
|
|
72
|
-
// apiType,
|
|
73
|
-
} = await this.validateFlags();
|
|
74
|
-
const CURR_DIR = process.cwd();
|
|
75
|
-
const projectPath = path.join(CURR_DIR, projectName);
|
|
76
|
-
await this.cloneTemplate(projectPath);
|
|
77
|
-
await this.installModules(projectPath);
|
|
78
|
-
await this.formatApp(projectPath);
|
|
79
|
-
}
|
|
80
69
|
async validateFlags() {
|
|
81
70
|
var _a;
|
|
82
71
|
const { flags } = await this.parse(New);
|
|
83
72
|
let projectName = flags.name;
|
|
84
73
|
let apiType = (_a = flags.type) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
85
|
-
if (
|
|
86
|
-
// this.error("`name` must be set (e.g. WoofyApp)");
|
|
74
|
+
if (!projectName) {
|
|
87
75
|
projectName = '';
|
|
88
76
|
}
|
|
89
|
-
if (
|
|
77
|
+
if (!apiType) {
|
|
90
78
|
apiType = "rest";
|
|
91
79
|
}
|
|
92
|
-
if (
|
|
93
|
-
this.error("`apiType` must be
|
|
80
|
+
if (!["rest", "graphql"].includes(apiType)) {
|
|
81
|
+
this.error("`apiType` must be 'rest' or 'graphql'");
|
|
94
82
|
}
|
|
95
83
|
return { projectName, apiType };
|
|
96
84
|
}
|
|
85
|
+
async run() {
|
|
86
|
+
this.log("Initializing New Apso Server...");
|
|
87
|
+
const { projectName } = await this.validateFlags();
|
|
88
|
+
const CURR_DIR = process.cwd();
|
|
89
|
+
const projectPath = path.join(CURR_DIR, projectName);
|
|
90
|
+
await this.cloneTemplate(projectPath);
|
|
91
|
+
await this.installModules(projectPath);
|
|
92
|
+
await this.formatApp(projectPath);
|
|
93
|
+
}
|
|
97
94
|
}
|
|
98
95
|
New.description = "Initialize your server project";
|
|
99
96
|
New.examples = [`$ apso server new --name TestProject`];
|
package/dist/lib/base-command.js
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
3
4
|
const core_1 = require("@oclif/core");
|
|
4
5
|
const child_process_1 = require("child_process");
|
|
6
|
+
const os_1 = tslib_1.__importDefault(require("os"));
|
|
5
7
|
class BaseCommand extends core_1.Command {
|
|
6
8
|
async runNpmCommand(args, silent = false) {
|
|
7
9
|
return new Promise((resolve, reject) => {
|
|
8
|
-
const
|
|
10
|
+
const isWindows = os_1.default.platform() === "win32";
|
|
11
|
+
const command = isWindows ? "npm.cmd" : "npm";
|
|
9
12
|
const cmdStr = `${command} ${args.join(" ")}`;
|
|
10
|
-
this.log(cmdStr);
|
|
11
|
-
const child = (0, child_process_1.spawn)(command, args, {
|
|
13
|
+
this.log(`Running: ${cmdStr}`);
|
|
14
|
+
const child = (0, child_process_1.spawn)(command, args, {
|
|
15
|
+
stdio: "inherit",
|
|
16
|
+
shell: isWindows,
|
|
17
|
+
});
|
|
12
18
|
child.on("close", (code) => {
|
|
13
19
|
if (code !== 0) {
|
|
14
|
-
reject({
|
|
15
|
-
command: cmdStr,
|
|
16
|
-
});
|
|
20
|
+
reject({ command: cmdStr, exitCode: code });
|
|
17
21
|
return;
|
|
18
22
|
}
|
|
19
23
|
resolve();
|
|
20
24
|
});
|
|
25
|
+
child.on("error", () => {
|
|
26
|
+
this.error(`Failed to run: ${cmdStr}`);
|
|
27
|
+
});
|
|
21
28
|
});
|
|
22
29
|
}
|
|
23
30
|
}
|
package/oclif.manifest.json
CHANGED