@keshavsoft/kschema-cli 1.3.1 → 1.3.3
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/bin/v3/commands/init.js +12 -24
- package/bin/v3/commands/steps/announce.js +3 -0
- package/bin/v3/commands/steps/createProject.js +6 -0
- package/bin/v3/commands/steps/decideFolderName.js +4 -0
- package/bin/v3/commands/steps/decideTemplate.js +3 -0
- package/bin/v3/commands/steps/locateDestination.js +5 -0
- package/bin/v3/commands/steps/locateSource.js +14 -0
- package/package.json +1 -1
- package/commands/init.js +0 -20
- package/commands/test.js +0 -36
package/bin/v3/commands/init.js
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const defaultFolderName = "KehavSoft";
|
|
1
|
+
import { decideTemplate } from "./steps/decideTemplate.js";
|
|
2
|
+
import { decideFolderName } from "./steps/decideFolderName.js";
|
|
3
|
+
import { locateSource } from "./steps/locateSource.js";
|
|
4
|
+
import { locateDestination } from "./steps/locateDestination.js";
|
|
5
|
+
import { createProject } from "./steps/createProject.js";
|
|
6
|
+
import { announce } from "./steps/announce.js";
|
|
9
7
|
|
|
10
8
|
export default ({ inTemplate, inFolderName }) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
switch (inTemplate) {
|
|
15
|
-
case "express":
|
|
16
|
-
source = path.join(__dirname, "template", "express");
|
|
17
|
-
break;
|
|
18
|
-
|
|
19
|
-
default:
|
|
20
|
-
source = path.join(__dirname, "template", "basic");
|
|
21
|
-
break;
|
|
22
|
-
};
|
|
9
|
+
const template = decideTemplate({ inTemplate });
|
|
10
|
+
const folderName = decideFolderName({ inFolderName, template });
|
|
23
11
|
|
|
24
|
-
const
|
|
12
|
+
const source = locateSource({ template });
|
|
13
|
+
const destination = locateDestination({ folderName });
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
fs.cpSync(source, destination, { recursive: true });
|
|
15
|
+
createProject({ source, destination });
|
|
28
16
|
|
|
29
|
-
|
|
17
|
+
announce({ folderName });
|
|
30
18
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = path.dirname(__filename);
|
|
6
|
+
|
|
7
|
+
export const locateSource = ({ template }) => {
|
|
8
|
+
return path.join(
|
|
9
|
+
__dirname,
|
|
10
|
+
"..",
|
|
11
|
+
"template",
|
|
12
|
+
template === "express" ? "express" : "basic"
|
|
13
|
+
);
|
|
14
|
+
};
|
package/package.json
CHANGED
package/commands/init.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// commands/init.js
|
|
2
|
-
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const __dirname = path.dirname(__filename);
|
|
9
|
-
|
|
10
|
-
export default (arg) => {
|
|
11
|
-
const folderName = arg || "KehavSoft1";
|
|
12
|
-
|
|
13
|
-
const source = path.join(__dirname, "../template");
|
|
14
|
-
const destination = path.join(process.cwd(), folderName);
|
|
15
|
-
|
|
16
|
-
fs.mkdirSync(destination, { recursive: true });
|
|
17
|
-
fs.cpSync(source, destination, { recursive: true });
|
|
18
|
-
|
|
19
|
-
console.log(`Project created in ${folderName}`);
|
|
20
|
-
};
|
package/commands/test.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// commands/test.js
|
|
2
|
-
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
|
|
6
|
-
export default (arg) => {
|
|
7
|
-
const projectPath = arg
|
|
8
|
-
? path.resolve(process.cwd(), arg)
|
|
9
|
-
: process.cwd();
|
|
10
|
-
|
|
11
|
-
// 1. Check folder exists
|
|
12
|
-
if (!fs.existsSync(projectPath)) {
|
|
13
|
-
console.log("Invalid path");
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// 2. Check required structure
|
|
18
|
-
const hasConfigJson = fs.existsSync(
|
|
19
|
-
path.join(projectPath, "config.json")
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
const hasConfigFolder = fs.existsSync(
|
|
23
|
-
path.join(projectPath, "Config")
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const hasSchemasFolder = fs.existsSync(
|
|
27
|
-
path.join(projectPath, "Config", "Schemas")
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
// 3. Final decision
|
|
31
|
-
if (hasConfigJson && hasConfigFolder && hasSchemasFolder) {
|
|
32
|
-
console.log("Already initialized");
|
|
33
|
-
} else {
|
|
34
|
-
console.log("Not initialized");
|
|
35
|
-
}
|
|
36
|
-
};
|