@forgehive/forge-cli 0.1.7 → 0.1.8
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/dist/runner.js +22 -2
- package/dist/tasks/runner/bundle.d.ts +18 -0
- package/dist/tasks/runner/bundle.js +71 -0
- package/dist/tasks/runner/create.d.ts +21 -0
- package/dist/tasks/runner/create.js +97 -0
- package/dist/tasks/runner/remove.d.ts +18 -0
- package/dist/tasks/runner/remove.js +58 -0
- package/forge.json +12 -0
- package/logs/runner:create.log +3 -0
- package/package.json +4 -4
- package/src/runner.ts +24 -2
- package/src/tasks/runner/bundle.ts +79 -0
- package/src/tasks/runner/create.ts +121 -0
- package/src/tasks/runner/remove.ts +74 -0
- package/logs/conf:info.log +0 -2
package/dist/runner.js
CHANGED
|
@@ -6,6 +6,9 @@ const info_1 = require("./tasks/conf/info");
|
|
|
6
6
|
const createTask_1 = require("./tasks/task/createTask");
|
|
7
7
|
const run_1 = require("./tasks/task/run");
|
|
8
8
|
const remove_1 = require("./tasks/task/remove");
|
|
9
|
+
const create_1 = require("./tasks/runner/create");
|
|
10
|
+
const remove_2 = require("./tasks/runner/remove");
|
|
11
|
+
const bundle_1 = require("./tasks/runner/bundle");
|
|
9
12
|
const runner = new runner_1.Runner((data) => {
|
|
10
13
|
const { _, ...filteredObj } = data;
|
|
11
14
|
return {
|
|
@@ -21,6 +24,10 @@ runner.load('info', info_1.info);
|
|
|
21
24
|
runner.load('task:create', createTask_1.createTaskCommand);
|
|
22
25
|
runner.load('task:run', run_1.run);
|
|
23
26
|
runner.load('task:remove', remove_1.remove);
|
|
27
|
+
// Runner commands
|
|
28
|
+
runner.load('runner:create', create_1.create);
|
|
29
|
+
runner.load('runner:remove', remove_2.remove);
|
|
30
|
+
runner.load('runner:bundle', bundle_1.bundle);
|
|
24
31
|
// Set handler
|
|
25
32
|
runner.setHandler(async (data) => {
|
|
26
33
|
const parsedArgs = runner.parseArguments(data);
|
|
@@ -34,10 +41,23 @@ runner.setHandler(async (data) => {
|
|
|
34
41
|
}
|
|
35
42
|
try {
|
|
36
43
|
let result;
|
|
37
|
-
const
|
|
38
|
-
|
|
44
|
+
const commandsWithDescriptor = ['task:create', 'task:remove'];
|
|
45
|
+
const commandsWithRunner = ['runner:create', 'runner:remove'];
|
|
46
|
+
if (commandsWithDescriptor.includes(taskName)) {
|
|
39
47
|
result = await task.run({ descriptorName: action });
|
|
40
48
|
}
|
|
49
|
+
else if (commandsWithRunner.includes(taskName)) {
|
|
50
|
+
result = await task.run({
|
|
51
|
+
runnerName: action
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else if (taskName === 'runner:bundle') {
|
|
55
|
+
const paths = args;
|
|
56
|
+
result = await task.run({
|
|
57
|
+
runnerName: action,
|
|
58
|
+
targetPath: paths.targetPath
|
|
59
|
+
});
|
|
60
|
+
}
|
|
41
61
|
else if (taskName === 'task:run') {
|
|
42
62
|
result = await task.run({
|
|
43
63
|
descriptorName: action,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ForgeConf } from '../types';
|
|
2
|
+
export declare const bundle: import("@forgehive/task").TaskInstanceType<(argv: {
|
|
3
|
+
runnerName: string;
|
|
4
|
+
targetPath: string;
|
|
5
|
+
}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
6
|
+
loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
|
|
7
|
+
getCwd: () => Promise<string>;
|
|
8
|
+
ensureDir: (dirPath: string) => Promise<void>;
|
|
9
|
+
}>) => Promise<{
|
|
10
|
+
status: string;
|
|
11
|
+
runnerName: string;
|
|
12
|
+
entryPoint: string;
|
|
13
|
+
outputFile: string;
|
|
14
|
+
}>, {
|
|
15
|
+
loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
|
|
16
|
+
getCwd: () => Promise<string>;
|
|
17
|
+
ensureDir: (dirPath: string) => Promise<void>;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TASK: bundle
|
|
3
|
+
// Run this task with:
|
|
4
|
+
// forge task:run runner:bundle --runnerName=<runner-name> --targetPath=<target-path>
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.bundle = void 0;
|
|
10
|
+
const task_1 = require("@forgehive/task");
|
|
11
|
+
const schema_1 = require("@forgehive/schema");
|
|
12
|
+
const esbuild_1 = __importDefault(require("esbuild"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
15
|
+
const load_1 = require("../conf/load");
|
|
16
|
+
const schema = new schema_1.Schema({
|
|
17
|
+
runnerName: schema_1.Schema.string(),
|
|
18
|
+
targetPath: schema_1.Schema.string()
|
|
19
|
+
});
|
|
20
|
+
const boundaries = {
|
|
21
|
+
loadConf: load_1.load.asBoundary(),
|
|
22
|
+
getCwd: async () => {
|
|
23
|
+
return process.cwd();
|
|
24
|
+
},
|
|
25
|
+
ensureDir: async (dirPath) => {
|
|
26
|
+
try {
|
|
27
|
+
await promises_1.default.access(dirPath);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw new Error(`Directory ${dirPath} does not exist`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.bundle = (0, task_1.createTask)(schema, boundaries, async function ({ runnerName, targetPath }, { loadConf, getCwd, ensureDir }) {
|
|
35
|
+
// Load forge configuration
|
|
36
|
+
const forge = await loadConf({});
|
|
37
|
+
const cwd = await getCwd();
|
|
38
|
+
// Verify runner exists in forge.json
|
|
39
|
+
if (!forge.runners || !forge.runners[runnerName]) {
|
|
40
|
+
throw new Error(`Runner '${runnerName}' not found in forge.json configuration`);
|
|
41
|
+
}
|
|
42
|
+
// Get runner entry point from forge.json
|
|
43
|
+
const runnerConfig = forge.runners[runnerName];
|
|
44
|
+
const entryPoint = path_1.default.join(cwd, runnerConfig.path);
|
|
45
|
+
const outputFile = path_1.default.join(targetPath, `${runnerName}.js`);
|
|
46
|
+
console.log(`
|
|
47
|
+
==================================================
|
|
48
|
+
Starting runner creation!
|
|
49
|
+
Creating runner: ${runnerName}
|
|
50
|
+
Entrypoint: ${entryPoint}
|
|
51
|
+
Output file: ${outputFile}
|
|
52
|
+
==================================================
|
|
53
|
+
`);
|
|
54
|
+
// Ensure target directory exists
|
|
55
|
+
await ensureDir(path_1.default.dirname(targetPath));
|
|
56
|
+
// Build using esbuild
|
|
57
|
+
await esbuild_1.default.build({
|
|
58
|
+
entryPoints: [entryPoint],
|
|
59
|
+
outfile: outputFile,
|
|
60
|
+
bundle: true,
|
|
61
|
+
minify: true,
|
|
62
|
+
platform: 'node',
|
|
63
|
+
sourcemap: true
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
status: 'Success',
|
|
67
|
+
runnerName,
|
|
68
|
+
entryPoint,
|
|
69
|
+
outputFile: path_1.default.join(targetPath, `${runnerName}.js`)
|
|
70
|
+
};
|
|
71
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ForgeConf } from '../types';
|
|
2
|
+
export declare const create: import("@forgehive/task").TaskInstanceType<(argv: {
|
|
3
|
+
runnerName: string;
|
|
4
|
+
}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
5
|
+
loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
|
|
6
|
+
getCwd: () => Promise<string>;
|
|
7
|
+
persistRunner: (runnerPath: string, runnerName: string, content: string) => Promise<{
|
|
8
|
+
path: string;
|
|
9
|
+
}>;
|
|
10
|
+
persistConf: (forge: ForgeConf, cwd: string) => Promise<void>;
|
|
11
|
+
}>) => Promise<{
|
|
12
|
+
runnerPath: string;
|
|
13
|
+
runnerName: string;
|
|
14
|
+
}>, {
|
|
15
|
+
loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
|
|
16
|
+
getCwd: () => Promise<string>;
|
|
17
|
+
persistRunner: (runnerPath: string, runnerName: string, content: string) => Promise<{
|
|
18
|
+
path: string;
|
|
19
|
+
}>;
|
|
20
|
+
persistConf: (forge: ForgeConf, cwd: string) => Promise<void>;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TASK: create
|
|
3
|
+
// Run this task with:
|
|
4
|
+
// forge task:run runner:create --runnerName <runner-name>
|
|
5
|
+
// forge task:run runner:create --runnerName inventory
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.create = void 0;
|
|
11
|
+
const task_1 = require("@forgehive/task");
|
|
12
|
+
const schema_1 = require("@forgehive/schema");
|
|
13
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
16
|
+
const camelCase_1 = require("../../utils/camelCase");
|
|
17
|
+
const load_1 = require("../conf/load");
|
|
18
|
+
// Define the template content directly in the code
|
|
19
|
+
const RUNNER_TEMPLATE = `// RUNNER: {{ runnerName }}
|
|
20
|
+
import { Runner } from '@forgehive/runner'
|
|
21
|
+
|
|
22
|
+
// Import your tasks here
|
|
23
|
+
// import { EXAMPLE_TASK } from '../../tasks/MODULE/TASK'
|
|
24
|
+
|
|
25
|
+
const {{ runnerName }}Runner = new Runner()
|
|
26
|
+
|
|
27
|
+
// Load your tasks here
|
|
28
|
+
// runner.load('MODULE:TASK', EXAMPLE_TASK)
|
|
29
|
+
|
|
30
|
+
export { {{ runnerName }}Runner }
|
|
31
|
+
`;
|
|
32
|
+
const schema = new schema_1.Schema({
|
|
33
|
+
runnerName: schema_1.Schema.string()
|
|
34
|
+
});
|
|
35
|
+
const boundaries = {
|
|
36
|
+
// Load boundaries
|
|
37
|
+
loadConf: load_1.load.asBoundary(),
|
|
38
|
+
getCwd: async () => {
|
|
39
|
+
return process.cwd();
|
|
40
|
+
},
|
|
41
|
+
// Persist boundaries
|
|
42
|
+
persistRunner: async (runnerPath, runnerName, content) => {
|
|
43
|
+
const folderPath = path_1.default.join(runnerPath, runnerName);
|
|
44
|
+
const filePath = path_1.default.join(folderPath, 'index.ts');
|
|
45
|
+
let err;
|
|
46
|
+
try {
|
|
47
|
+
await promises_1.default.stat(folderPath);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
err = e;
|
|
51
|
+
}
|
|
52
|
+
if (err === undefined) {
|
|
53
|
+
throw new Error(`Runner folder '${folderPath}' already exists.`);
|
|
54
|
+
}
|
|
55
|
+
await promises_1.default.mkdir(folderPath, { recursive: true });
|
|
56
|
+
await promises_1.default.writeFile(filePath, content, 'utf-8');
|
|
57
|
+
return {
|
|
58
|
+
path: filePath.toString()
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
persistConf: async (forge, cwd) => {
|
|
62
|
+
const forgePath = path_1.default.join(cwd, 'forge.json');
|
|
63
|
+
await promises_1.default.writeFile(forgePath, JSON.stringify(forge, null, 2));
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.create = (0, task_1.createTask)(schema, boundaries, async function ({ runnerName }, { persistRunner, loadConf, persistConf, getCwd }) {
|
|
67
|
+
const formattedName = (0, camelCase_1.camelCase)(runnerName);
|
|
68
|
+
const cwd = await getCwd();
|
|
69
|
+
const forge = await loadConf({});
|
|
70
|
+
const runnerPath = forge.paths.runners;
|
|
71
|
+
console.log(`
|
|
72
|
+
==================================================
|
|
73
|
+
Starting runner creation!
|
|
74
|
+
Creating runner: ${formattedName}
|
|
75
|
+
Into: ${runnerPath}${formattedName}/index.ts
|
|
76
|
+
==================================================
|
|
77
|
+
`);
|
|
78
|
+
const comp = handlebars_1.default.compile(RUNNER_TEMPLATE);
|
|
79
|
+
const content = comp({
|
|
80
|
+
runnerName: formattedName
|
|
81
|
+
});
|
|
82
|
+
await persistRunner(runnerPath, formattedName, content);
|
|
83
|
+
if (forge.runners === undefined) {
|
|
84
|
+
forge.runners = {};
|
|
85
|
+
}
|
|
86
|
+
// Create runner descriptor
|
|
87
|
+
const runnerDescriptor = {
|
|
88
|
+
path: `${runnerPath}${formattedName}/index.ts`,
|
|
89
|
+
version: '0.0.1'
|
|
90
|
+
};
|
|
91
|
+
forge.runners[formattedName] = runnerDescriptor;
|
|
92
|
+
await persistConf(forge, cwd);
|
|
93
|
+
return {
|
|
94
|
+
runnerPath: `${runnerPath}/${formattedName}`,
|
|
95
|
+
runnerName: formattedName
|
|
96
|
+
};
|
|
97
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ForgeConf } from '../types';
|
|
2
|
+
export declare const remove: import("@forgehive/task").TaskInstanceType<(argv: {
|
|
3
|
+
runnerName: string;
|
|
4
|
+
}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
5
|
+
loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
|
|
6
|
+
getCwd: () => Promise<string>;
|
|
7
|
+
removeRunner: (runnerPath: string) => Promise<void>;
|
|
8
|
+
persistConf: (forge: ForgeConf, cwd: string) => Promise<void>;
|
|
9
|
+
}>) => Promise<{
|
|
10
|
+
status: string;
|
|
11
|
+
message: string;
|
|
12
|
+
runnerName: string;
|
|
13
|
+
}>, {
|
|
14
|
+
loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
|
|
15
|
+
getCwd: () => Promise<string>;
|
|
16
|
+
removeRunner: (runnerPath: string) => Promise<void>;
|
|
17
|
+
persistConf: (forge: ForgeConf, cwd: string) => Promise<void>;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TASK: remove
|
|
3
|
+
// Run this task with:
|
|
4
|
+
// forge task:run runner:remove --runnerName <runner-name>
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.remove = void 0;
|
|
10
|
+
const task_1 = require("@forgehive/task");
|
|
11
|
+
const schema_1 = require("@forgehive/schema");
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
14
|
+
const camelCase_1 = require("../../utils/camelCase");
|
|
15
|
+
const load_1 = require("../conf/load");
|
|
16
|
+
const schema = new schema_1.Schema({
|
|
17
|
+
runnerName: schema_1.Schema.string()
|
|
18
|
+
});
|
|
19
|
+
const boundaries = {
|
|
20
|
+
// Load boundaries
|
|
21
|
+
loadConf: load_1.load.asBoundary(),
|
|
22
|
+
getCwd: async () => {
|
|
23
|
+
return process.cwd();
|
|
24
|
+
},
|
|
25
|
+
// File system operations
|
|
26
|
+
removeRunner: async (runnerPath) => {
|
|
27
|
+
await promises_1.default.rm(runnerPath, { recursive: true, force: true });
|
|
28
|
+
},
|
|
29
|
+
// Configuration operations
|
|
30
|
+
persistConf: async (forge, cwd) => {
|
|
31
|
+
const forgePath = path_1.default.join(cwd, 'forge.json');
|
|
32
|
+
await promises_1.default.writeFile(forgePath, JSON.stringify(forge, null, 2));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.remove = (0, task_1.createTask)(schema, boundaries, async function ({ runnerName }, { loadConf, getCwd, removeRunner, persistConf }) {
|
|
36
|
+
const formattedName = (0, camelCase_1.camelCase)(runnerName);
|
|
37
|
+
const cwd = await getCwd();
|
|
38
|
+
const forge = await loadConf({});
|
|
39
|
+
if (!forge.runners || !forge.runners[formattedName]) {
|
|
40
|
+
throw new Error(`Runner '${formattedName}' not found in forge.json configuration`);
|
|
41
|
+
}
|
|
42
|
+
const runnerConfig = forge.runners[formattedName];
|
|
43
|
+
const runnerFolder = path_1.default.join(cwd, path_1.default.dirname(runnerConfig.path));
|
|
44
|
+
console.log(`
|
|
45
|
+
==================================================
|
|
46
|
+
Removing runner: ${formattedName}
|
|
47
|
+
Path: ${runnerFolder}
|
|
48
|
+
==================================================
|
|
49
|
+
`);
|
|
50
|
+
await removeRunner(runnerFolder);
|
|
51
|
+
delete forge.runners[formattedName];
|
|
52
|
+
await persistConf(forge, cwd);
|
|
53
|
+
return {
|
|
54
|
+
status: 'success',
|
|
55
|
+
message: `Runner '${formattedName}' successfully removed`,
|
|
56
|
+
runnerName: formattedName
|
|
57
|
+
};
|
|
58
|
+
});
|
package/forge.json
CHANGED
|
@@ -33,6 +33,18 @@
|
|
|
33
33
|
"conf:info": {
|
|
34
34
|
"path": "src/tasks/conf/info.ts",
|
|
35
35
|
"handler": "info"
|
|
36
|
+
},
|
|
37
|
+
"runner:create": {
|
|
38
|
+
"path": "src/tasks/runner/create.ts",
|
|
39
|
+
"handler": "create"
|
|
40
|
+
},
|
|
41
|
+
"runner:remove": {
|
|
42
|
+
"path": "src/tasks/runner/remove.ts",
|
|
43
|
+
"handler": "remove"
|
|
44
|
+
},
|
|
45
|
+
"runner:bundle": {
|
|
46
|
+
"path": "src/tasks/runner/bundle.ts",
|
|
47
|
+
"handler": "bundle"
|
|
36
48
|
}
|
|
37
49
|
},
|
|
38
50
|
"runners": {}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
{"name":"runner:create","type":"success","input":{},"output":{"status":"Ok"},"boundaries":{}}
|
|
2
|
+
{"name":"runner:create","type":"success","input":{"runnerName":"inventory"},"output":{},"boundaries":{"loadConf":[{"input":[{}],"output":{"project":{"name":"forge-cli"},"paths":{"logs":"logs/","tasks":"src/tasks/","runners":"src/runners/","fixtures":"src/tests/fixtures","tests":"src/tests/"},"infra":{"region":"us-west-2","bucket":""},"tasks":{"bundle:create":{"path":"src/tasks/bundle/create.ts","handler":"create"},"bundle:load":{"path":"src/tasks/bundle/load.ts","handler":"load"},"task:run":{"path":"src/tasks/task/run.ts","handler":"run"},"task:remove":{"path":"src/tasks/task/remove.ts","handler":"remove"},"conf:info":{"path":"src/tasks/conf/info.ts","handler":"info"},"runner:create":{"path":"src/tasks/runner/create.ts","handler":"create"}},"runners":{}}},{"input":[{}],"output":{"project":{"name":"forge-cli"},"paths":{"logs":"logs/","tasks":"src/tasks/","runners":"src/runners/","fixtures":"src/tests/fixtures","tests":"src/tests/"},"infra":{"region":"us-west-2","bucket":""},"tasks":{"bundle:create":{"path":"src/tasks/bundle/create.ts","handler":"create"},"bundle:load":{"path":"src/tasks/bundle/load.ts","handler":"load"},"task:run":{"path":"src/tasks/task/run.ts","handler":"run"},"task:remove":{"path":"src/tasks/task/remove.ts","handler":"remove"},"conf:info":{"path":"src/tasks/conf/info.ts","handler":"info"},"runner:create":{"path":"src/tasks/runner/create.ts","handler":"create"}},"runners":{}}}],"getCwd":[{"input":[],"output":"/Users/danielzavaladlvega/forgehive/mono/apps/cli"},{"input":[],"output":"/Users/danielzavaladlvega/forgehive/mono/apps/cli"}],"persistRunner":[],"persistConf":[]}}
|
|
3
|
+
{"name":"runner:create","type":"success","input":{"runnerName":"inventory"},"output":{},"boundaries":{"loadConf":[{"input":[{}],"output":{"project":{"name":"forge-cli"},"paths":{"logs":"logs/","tasks":"src/tasks/","runners":"src/runners/","fixtures":"src/tests/fixtures","tests":"src/tests/"},"infra":{"region":"us-west-2","bucket":""},"tasks":{"bundle:create":{"path":"src/tasks/bundle/create.ts","handler":"create"},"bundle:load":{"path":"src/tasks/bundle/load.ts","handler":"load"},"task:run":{"path":"src/tasks/task/run.ts","handler":"run"},"task:remove":{"path":"src/tasks/task/remove.ts","handler":"remove"},"conf:info":{"path":"src/tasks/conf/info.ts","handler":"info"},"runner:create":{"path":"src/tasks/runner/create.ts","handler":"create"}},"runners":{}}}],"getCwd":[{"input":[],"output":"/Users/danielzavaladlvega/forgehive/mono/apps/cli"}],"persistRunner":[],"persistConf":[]}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forgehive/forge-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "TypeScript CLI application",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"esbuild": "^0.25.0",
|
|
24
24
|
"handlebars": "^4.7.8",
|
|
25
25
|
"minimist": "^1.2.8",
|
|
26
|
-
"@forgehive/record-tape": "0.0.1",
|
|
27
|
-
"@forgehive/schema": "0.1.4",
|
|
28
26
|
"@forgehive/task": "0.1.4",
|
|
29
|
-
"@forgehive/
|
|
27
|
+
"@forgehive/schema": "0.1.4",
|
|
28
|
+
"@forgehive/runner": "0.1.4",
|
|
29
|
+
"@forgehive/record-tape": "0.0.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/jest": "^29.5.3",
|
package/src/runner.ts
CHANGED
|
@@ -8,6 +8,10 @@ import { createTaskCommand } from './tasks/task/createTask'
|
|
|
8
8
|
import { run as taskRunCommand } from './tasks/task/run'
|
|
9
9
|
import { remove as taskRemoveCommand } from './tasks/task/remove'
|
|
10
10
|
|
|
11
|
+
import { create as createRunner } from './tasks/runner/create'
|
|
12
|
+
import { remove as removeRunner } from './tasks/runner/remove'
|
|
13
|
+
import { bundle as bundleRunner } from './tasks/runner/bundle'
|
|
14
|
+
|
|
11
15
|
interface CliParsedArguments extends RunnerParsedArguments {
|
|
12
16
|
action: string;
|
|
13
17
|
}
|
|
@@ -31,6 +35,11 @@ runner.load('task:create', createTaskCommand)
|
|
|
31
35
|
runner.load('task:run', taskRunCommand)
|
|
32
36
|
runner.load('task:remove', taskRemoveCommand)
|
|
33
37
|
|
|
38
|
+
// Runner commands
|
|
39
|
+
runner.load('runner:create', createRunner)
|
|
40
|
+
runner.load('runner:remove', removeRunner)
|
|
41
|
+
runner.load('runner:bundle', bundleRunner)
|
|
42
|
+
|
|
34
43
|
// Set handler
|
|
35
44
|
runner.setHandler(async (data: ParsedArgs): Promise<unknown> => {
|
|
36
45
|
const parsedArgs = runner.parseArguments(data)
|
|
@@ -48,9 +57,22 @@ runner.setHandler(async (data: ParsedArgs): Promise<unknown> => {
|
|
|
48
57
|
try {
|
|
49
58
|
let result
|
|
50
59
|
|
|
51
|
-
const
|
|
52
|
-
|
|
60
|
+
const commandsWithDescriptor = ['task:create', 'task:remove']
|
|
61
|
+
const commandsWithRunner = ['runner:create', 'runner:remove']
|
|
62
|
+
|
|
63
|
+
if (commandsWithDescriptor.includes(taskName)) {
|
|
53
64
|
result = await task.run({ descriptorName: action })
|
|
65
|
+
} else if (commandsWithRunner.includes(taskName)) {
|
|
66
|
+
result = await task.run({
|
|
67
|
+
runnerName: action
|
|
68
|
+
})
|
|
69
|
+
} else if (taskName === 'runner:bundle') {
|
|
70
|
+
const paths = args as { targetPath: string }
|
|
71
|
+
|
|
72
|
+
result = await task.run({
|
|
73
|
+
runnerName: action,
|
|
74
|
+
targetPath: paths.targetPath
|
|
75
|
+
})
|
|
54
76
|
} else if (taskName === 'task:run') {
|
|
55
77
|
result = await task.run({
|
|
56
78
|
descriptorName: action,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// TASK: bundle
|
|
2
|
+
// Run this task with:
|
|
3
|
+
// forge task:run runner:bundle --runnerName=<runner-name> --targetPath=<target-path>
|
|
4
|
+
|
|
5
|
+
import { createTask } from '@forgehive/task'
|
|
6
|
+
import { Schema } from '@forgehive/schema'
|
|
7
|
+
import esbuild from 'esbuild'
|
|
8
|
+
import path from 'path'
|
|
9
|
+
import fs from 'fs/promises'
|
|
10
|
+
import { load as loadConf } from '../conf/load'
|
|
11
|
+
import { type ForgeConf } from '../types'
|
|
12
|
+
|
|
13
|
+
const schema = new Schema({
|
|
14
|
+
runnerName: Schema.string(),
|
|
15
|
+
targetPath: Schema.string()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const boundaries = {
|
|
19
|
+
loadConf: loadConf.asBoundary(),
|
|
20
|
+
getCwd: async (): Promise<string> => {
|
|
21
|
+
return process.cwd()
|
|
22
|
+
},
|
|
23
|
+
ensureDir: async (dirPath: string): Promise<void> => {
|
|
24
|
+
try {
|
|
25
|
+
await fs.access(dirPath)
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw new Error(`Directory ${dirPath} does not exist`)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const bundle = createTask(
|
|
33
|
+
schema,
|
|
34
|
+
boundaries,
|
|
35
|
+
async function ({ runnerName, targetPath }, { loadConf, getCwd, ensureDir }) {
|
|
36
|
+
// Load forge configuration
|
|
37
|
+
const forge: ForgeConf = await loadConf({})
|
|
38
|
+
const cwd = await getCwd()
|
|
39
|
+
|
|
40
|
+
// Verify runner exists in forge.json
|
|
41
|
+
if (!forge.runners || !forge.runners[runnerName]) {
|
|
42
|
+
throw new Error(`Runner '${runnerName}' not found in forge.json configuration`)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Get runner entry point from forge.json
|
|
46
|
+
const runnerConfig = forge.runners[runnerName]
|
|
47
|
+
const entryPoint = path.join(cwd, runnerConfig.path)
|
|
48
|
+
const outputFile = path.join(targetPath, `${runnerName}.js`)
|
|
49
|
+
|
|
50
|
+
console.log(`
|
|
51
|
+
==================================================
|
|
52
|
+
Starting runner creation!
|
|
53
|
+
Creating runner: ${runnerName}
|
|
54
|
+
Entrypoint: ${entryPoint}
|
|
55
|
+
Output file: ${outputFile}
|
|
56
|
+
==================================================
|
|
57
|
+
`)
|
|
58
|
+
|
|
59
|
+
// Ensure target directory exists
|
|
60
|
+
await ensureDir(path.dirname(targetPath))
|
|
61
|
+
|
|
62
|
+
// Build using esbuild
|
|
63
|
+
await esbuild.build({
|
|
64
|
+
entryPoints: [entryPoint],
|
|
65
|
+
outfile: outputFile,
|
|
66
|
+
bundle: true,
|
|
67
|
+
minify: true,
|
|
68
|
+
platform: 'node',
|
|
69
|
+
sourcemap: true
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
status: 'Success',
|
|
74
|
+
runnerName,
|
|
75
|
+
entryPoint,
|
|
76
|
+
outputFile: path.join(targetPath, `${runnerName}.js`)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
)
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// TASK: create
|
|
2
|
+
// Run this task with:
|
|
3
|
+
// forge task:run runner:create --runnerName <runner-name>
|
|
4
|
+
// forge task:run runner:create --runnerName inventory
|
|
5
|
+
|
|
6
|
+
import { createTask } from '@forgehive/task'
|
|
7
|
+
import { Schema } from '@forgehive/schema'
|
|
8
|
+
|
|
9
|
+
import Handlebars from 'handlebars'
|
|
10
|
+
import path from 'path'
|
|
11
|
+
import fs from 'fs/promises'
|
|
12
|
+
import { camelCase } from '../../utils/camelCase'
|
|
13
|
+
|
|
14
|
+
import { load } from '../conf/load'
|
|
15
|
+
import { type RunnerDescriptor, type ForgeConf } from '../types'
|
|
16
|
+
|
|
17
|
+
// Define the template content directly in the code
|
|
18
|
+
const RUNNER_TEMPLATE = `// RUNNER: {{ runnerName }}
|
|
19
|
+
import { Runner } from '@forgehive/runner'
|
|
20
|
+
|
|
21
|
+
// Import your tasks here
|
|
22
|
+
// import { EXAMPLE_TASK } from '../../tasks/MODULE/TASK'
|
|
23
|
+
|
|
24
|
+
const {{ runnerName }}Runner = new Runner()
|
|
25
|
+
|
|
26
|
+
// Load your tasks here
|
|
27
|
+
// runner.load('MODULE:TASK', EXAMPLE_TASK)
|
|
28
|
+
|
|
29
|
+
export { {{ runnerName }}Runner }
|
|
30
|
+
`
|
|
31
|
+
|
|
32
|
+
const schema = new Schema({
|
|
33
|
+
runnerName: Schema.string()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const boundaries = {
|
|
37
|
+
// Load boundaries
|
|
38
|
+
loadConf: load.asBoundary(),
|
|
39
|
+
getCwd: async (): Promise<string> => {
|
|
40
|
+
return process.cwd()
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
// Persist boundaries
|
|
44
|
+
persistRunner: async (runnerPath: string, runnerName: string, content: string): Promise<{ path: string }> => {
|
|
45
|
+
const folderPath = path.join(runnerPath, runnerName)
|
|
46
|
+
const filePath = path.join(folderPath, 'index.ts')
|
|
47
|
+
|
|
48
|
+
let err
|
|
49
|
+
try {
|
|
50
|
+
await fs.stat(folderPath)
|
|
51
|
+
} catch (e) {
|
|
52
|
+
err = e
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (err === undefined) {
|
|
56
|
+
throw new Error(`Runner folder '${folderPath}' already exists.`)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await fs.mkdir(folderPath, { recursive: true })
|
|
60
|
+
await fs.writeFile(filePath, content, 'utf-8')
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
path: filePath.toString()
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
persistConf: async (forge: ForgeConf, cwd: string): Promise<void> => {
|
|
67
|
+
const forgePath = path.join(cwd, 'forge.json')
|
|
68
|
+
await fs.writeFile(forgePath, JSON.stringify(forge, null, 2))
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const create = createTask(
|
|
73
|
+
schema,
|
|
74
|
+
boundaries,
|
|
75
|
+
async function ({ runnerName }, {
|
|
76
|
+
persistRunner,
|
|
77
|
+
loadConf,
|
|
78
|
+
persistConf,
|
|
79
|
+
getCwd
|
|
80
|
+
}) {
|
|
81
|
+
const formattedName = camelCase(runnerName)
|
|
82
|
+
const cwd = await getCwd()
|
|
83
|
+
|
|
84
|
+
const forge = await loadConf({})
|
|
85
|
+
const runnerPath = forge.paths.runners
|
|
86
|
+
|
|
87
|
+
console.log(`
|
|
88
|
+
==================================================
|
|
89
|
+
Starting runner creation!
|
|
90
|
+
Creating runner: ${formattedName}
|
|
91
|
+
Into: ${runnerPath}${formattedName}/index.ts
|
|
92
|
+
==================================================
|
|
93
|
+
`)
|
|
94
|
+
|
|
95
|
+
const comp = Handlebars.compile(RUNNER_TEMPLATE)
|
|
96
|
+
const content = comp({
|
|
97
|
+
runnerName: formattedName
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
await persistRunner(runnerPath, formattedName, content)
|
|
101
|
+
|
|
102
|
+
if (forge.runners === undefined) {
|
|
103
|
+
forge.runners = {}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Create runner descriptor
|
|
107
|
+
const runnerDescriptor: RunnerDescriptor = {
|
|
108
|
+
path: `${runnerPath}${formattedName}/index.ts`,
|
|
109
|
+
version: '0.0.1'
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
forge.runners[formattedName] = runnerDescriptor
|
|
113
|
+
|
|
114
|
+
await persistConf(forge, cwd)
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
runnerPath: `${runnerPath}/${formattedName}`,
|
|
118
|
+
runnerName: formattedName
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// TASK: remove
|
|
2
|
+
// Run this task with:
|
|
3
|
+
// forge task:run runner:remove --runnerName <runner-name>
|
|
4
|
+
|
|
5
|
+
import { createTask } from '@forgehive/task'
|
|
6
|
+
import { Schema } from '@forgehive/schema'
|
|
7
|
+
import path from 'path'
|
|
8
|
+
import fs from 'fs/promises'
|
|
9
|
+
import { camelCase } from '../../utils/camelCase'
|
|
10
|
+
import { load } from '../conf/load'
|
|
11
|
+
import { type ForgeConf } from '../types'
|
|
12
|
+
|
|
13
|
+
const schema = new Schema({
|
|
14
|
+
runnerName: Schema.string()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const boundaries = {
|
|
18
|
+
// Load boundaries
|
|
19
|
+
loadConf: load.asBoundary(),
|
|
20
|
+
getCwd: async (): Promise<string> => {
|
|
21
|
+
return process.cwd()
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
// File system operations
|
|
25
|
+
removeRunner: async (runnerPath: string): Promise<void> => {
|
|
26
|
+
await fs.rm(runnerPath, { recursive: true, force: true })
|
|
27
|
+
},
|
|
28
|
+
// Configuration operations
|
|
29
|
+
persistConf: async (forge: ForgeConf, cwd: string): Promise<void> => {
|
|
30
|
+
const forgePath = path.join(cwd, 'forge.json')
|
|
31
|
+
await fs.writeFile(forgePath, JSON.stringify(forge, null, 2))
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const remove = createTask(
|
|
36
|
+
schema,
|
|
37
|
+
boundaries,
|
|
38
|
+
async function ({ runnerName }, {
|
|
39
|
+
loadConf,
|
|
40
|
+
getCwd,
|
|
41
|
+
removeRunner,
|
|
42
|
+
persistConf
|
|
43
|
+
}) {
|
|
44
|
+
const formattedName = camelCase(runnerName)
|
|
45
|
+
const cwd = await getCwd()
|
|
46
|
+
const forge = await loadConf({})
|
|
47
|
+
|
|
48
|
+
if (!forge.runners || !forge.runners[formattedName]) {
|
|
49
|
+
throw new Error(`Runner '${formattedName}' not found in forge.json configuration`)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const runnerConfig = forge.runners[formattedName]
|
|
53
|
+
const runnerFolder = path.join(cwd, path.dirname(runnerConfig.path))
|
|
54
|
+
|
|
55
|
+
console.log(`
|
|
56
|
+
==================================================
|
|
57
|
+
Removing runner: ${formattedName}
|
|
58
|
+
Path: ${runnerFolder}
|
|
59
|
+
==================================================
|
|
60
|
+
`)
|
|
61
|
+
|
|
62
|
+
await removeRunner(runnerFolder)
|
|
63
|
+
|
|
64
|
+
delete forge.runners[formattedName]
|
|
65
|
+
|
|
66
|
+
await persistConf(forge, cwd)
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
status: 'success',
|
|
70
|
+
message: `Runner '${formattedName}' successfully removed`,
|
|
71
|
+
runnerName: formattedName
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
)
|
package/logs/conf:info.log
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
{"name":"conf:info","type":"success","input":{},"output":{"version":"0.1.5"},"boundaries":{"readFile":[{"input":["/Users/danielzavaladlvega/shadow/mono/apps/cli/package.json"],"output":"{\n \"name\": \"@forgehive/forge-cli\",\n \"version\": \"0.1.5\",\n \"description\": \"TypeScript CLI application\",\n \"license\": \"MIT\",\n \"main\": \"dist/index.js\",\n \"bin\": {\n \"forge\": \"./dist/index.js\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"dependencies\": {\n \"@forgehive/record-tape\": \"^0.0.1\",\n \"@forgehive/runner\": \"^0.1.1\",\n \"@forgehive/schema\": \"^0.1.0\",\n \"@forgehive/task\": \"^0.1.1\",\n \"esbuild\": \"^0.25.0\",\n \"handlebars\": \"^4.7.8\",\n \"minimist\": \"^1.2.8\"\n }\n },\n \"scripts\": {\n \"build\": \"tsc\",\n \"start\": \"node dist/index.js\",\n \"dev\": \"ts-node src/index.ts\",\n \"test\": \"jest\",\n \"lint\": \"eslint . --ext .ts\"\n },\n \"dependencies\": {\n \"@forgehive/record-tape\": \"workspace:*\",\n \"@forgehive/runner\": \"workspace:*\",\n \"@forgehive/schema\": \"workspace:*\",\n \"@forgehive/task\": \"workspace:*\",\n \"esbuild\": \"^0.25.0\",\n \"handlebars\": \"^4.7.8\",\n \"minimist\": \"^1.2.8\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.3\",\n \"@types/minimist\": \"^1.2.5\",\n \"@types/node\": \"^20.4.5\",\n \"jest\": \"^29.6.1\",\n \"ts-jest\": \"^29.1.1\",\n \"ts-node\": \"^10.9.1\",\n \"typescript\": \"^5.3.3\"\n }\n}\n"},{"input":["/Users/danielzavaladlvega/shadow/mono/apps/cli/package.json"],"output":"{\n \"name\": \"@forgehive/forge-cli\",\n \"version\": \"0.1.5\",\n \"description\": \"TypeScript CLI application\",\n \"license\": \"MIT\",\n \"main\": \"dist/index.js\",\n \"bin\": {\n \"forge\": \"./dist/index.js\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"dependencies\": {\n \"@forgehive/record-tape\": \"^0.0.1\",\n \"@forgehive/runner\": \"^0.1.1\",\n \"@forgehive/schema\": \"^0.1.0\",\n \"@forgehive/task\": \"^0.1.1\",\n \"esbuild\": \"^0.25.0\",\n \"handlebars\": \"^4.7.8\",\n \"minimist\": \"^1.2.8\"\n }\n },\n \"scripts\": {\n \"build\": \"tsc\",\n \"start\": \"node dist/index.js\",\n \"dev\": \"ts-node src/index.ts\",\n \"test\": \"jest\",\n \"lint\": \"eslint . --ext .ts\"\n },\n \"dependencies\": {\n \"@forgehive/record-tape\": \"workspace:*\",\n \"@forgehive/runner\": \"workspace:*\",\n \"@forgehive/schema\": \"workspace:*\",\n \"@forgehive/task\": \"workspace:*\",\n \"esbuild\": \"^0.25.0\",\n \"handlebars\": \"^4.7.8\",\n \"minimist\": \"^1.2.8\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.3\",\n \"@types/minimist\": \"^1.2.5\",\n \"@types/node\": \"^20.4.5\",\n \"jest\": \"^29.6.1\",\n \"ts-jest\": \"^29.1.1\",\n \"ts-node\": \"^10.9.1\",\n \"typescript\": \"^5.3.3\"\n }\n}\n"}]}}
|
|
2
|
-
{"name":"conf:info","type":"success","input":{},"output":{"version":"0.1.5"},"boundaries":{"readFile":[{"input":["/Users/danielzavaladlvega/shadow/mono/apps/cli/package.json"],"output":"{\n \"name\": \"@forgehive/forge-cli\",\n \"version\": \"0.1.5\",\n \"description\": \"TypeScript CLI application\",\n \"license\": \"MIT\",\n \"main\": \"dist/index.js\",\n \"bin\": {\n \"forge\": \"./dist/index.js\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"dependencies\": {\n \"@forgehive/record-tape\": \"^0.0.1\",\n \"@forgehive/runner\": \"^0.1.1\",\n \"@forgehive/schema\": \"^0.1.0\",\n \"@forgehive/task\": \"^0.1.1\",\n \"esbuild\": \"^0.25.0\",\n \"handlebars\": \"^4.7.8\",\n \"minimist\": \"^1.2.8\"\n }\n },\n \"scripts\": {\n \"build\": \"tsc\",\n \"start\": \"node dist/index.js\",\n \"dev\": \"ts-node src/index.ts\",\n \"test\": \"jest\",\n \"lint\": \"eslint . --ext .ts\"\n },\n \"dependencies\": {\n \"@forgehive/record-tape\": \"workspace:*\",\n \"@forgehive/runner\": \"workspace:*\",\n \"@forgehive/schema\": \"workspace:*\",\n \"@forgehive/task\": \"workspace:*\",\n \"esbuild\": \"^0.25.0\",\n \"handlebars\": \"^4.7.8\",\n \"minimist\": \"^1.2.8\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.3\",\n \"@types/minimist\": \"^1.2.5\",\n \"@types/node\": \"^20.4.5\",\n \"jest\": \"^29.6.1\",\n \"ts-jest\": \"^29.1.1\",\n \"ts-node\": \"^10.9.1\",\n \"typescript\": \"^5.3.3\"\n }\n}\n"}]}}
|