@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.
@@ -1,30 +1,18 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { fileURLToPath } from "url";
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = path.dirname(__filename);
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 folderName = inFolderName || `kschema-${inTemplate}-${Date.now()}`;
12
- let source;
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 destination = path.join(process.cwd(), folderName);
12
+ const source = locateSource({ template });
13
+ const destination = locateDestination({ folderName });
25
14
 
26
- fs.mkdirSync(destination, { recursive: true });
27
- fs.cpSync(source, destination, { recursive: true });
15
+ createProject({ source, destination });
28
16
 
29
- console.log(`Project created in ${folderName}`);
17
+ announce({ folderName });
30
18
  };
@@ -0,0 +1,3 @@
1
+ export const announce = ({ folderName }) => {
2
+ console.log(`[keshavsoft] Project created: ${folderName}`);
3
+ };
@@ -0,0 +1,6 @@
1
+ import fs from "fs";
2
+
3
+ export const createProject = ({ source, destination }) => {
4
+ fs.mkdirSync(destination, { recursive: true });
5
+ fs.cpSync(source, destination, { recursive: true });
6
+ };
@@ -0,0 +1,4 @@
1
+ export const decideFolderName = ({ inFolderName, template }) => {
2
+ const brand = "keshavsoft";
3
+ return inFolderName || `${brand}-${template}-${Date.now()}`;
4
+ };
@@ -0,0 +1,3 @@
1
+ export const decideTemplate = ({ inTemplate }) => {
2
+ return inTemplate || "basic";
3
+ };
@@ -0,0 +1,5 @@
1
+ import path from "path";
2
+
3
+ export const locateDestination = ({ folderName }) => {
4
+ return path.join(process.cwd(), folderName);
5
+ };
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keshavsoft/kschema-cli",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "cliVersion": "3",
5
5
  "type": "module",
6
6
  "bin": {
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
- };