@forgehive/forge-cli 0.2.14 → 0.3.0
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 +3 -1
- package/dist/tasks/auth/add.js +23 -19
- package/dist/tasks/auth/list.js +20 -16
- package/dist/tasks/auth/load.js +19 -15
- package/dist/tasks/auth/loadCurrent.js +13 -9
- package/dist/tasks/auth/remove.js +30 -26
- package/dist/tasks/auth/switch.js +19 -15
- package/dist/tasks/bundle/create.js +16 -12
- package/dist/tasks/bundle/fingerprint.d.ts +36 -0
- package/dist/tasks/bundle/fingerprint.js +164 -0
- package/dist/tasks/bundle/load.js +9 -5
- package/dist/tasks/bundle/zip.js +49 -45
- package/dist/tasks/conf/info.js +23 -19
- package/dist/tasks/conf/load.js +8 -4
- package/dist/tasks/fixture/download.js +40 -36
- package/dist/tasks/init.js +35 -31
- package/dist/tasks/runner/bundle.js +34 -30
- package/dist/tasks/runner/create.js +28 -24
- package/dist/tasks/runner/remove.js +22 -18
- package/dist/tasks/task/createTask.js +35 -28
- package/dist/tasks/task/describe.js +85 -81
- package/dist/tasks/task/download.js +63 -59
- package/dist/tasks/task/fingerprint.d.ts +26 -0
- package/dist/tasks/task/fingerprint.js +87 -0
- package/dist/tasks/task/list.js +27 -23
- package/dist/tasks/task/publish.js +72 -68
- package/dist/tasks/task/remove.js +24 -20
- package/dist/tasks/task/replay.js +94 -90
- package/dist/tasks/task/run.js +84 -79
- package/dist/test/tasks/create.test.js +6 -5
- package/dist/utils/taskAnalysis.d.ts +21 -0
- package/dist/utils/taskAnalysis.js +380 -0
- package/forge.json +12 -0
- package/logs/task:fingerprint.log +10 -0
- package/package.json +7 -7
- package/specs/fingerprint.md +380 -0
- package/src/runner.ts +3 -1
- package/src/tasks/README.md +13 -13
- package/src/tasks/auth/add.ts +3 -3
- package/src/tasks/auth/list.ts +3 -3
- package/src/tasks/auth/load.ts +3 -3
- package/src/tasks/auth/loadCurrent.ts +3 -3
- package/src/tasks/auth/remove.ts +3 -3
- package/src/tasks/auth/switch.ts +3 -3
- package/src/tasks/bundle/README.md +7 -7
- package/src/tasks/bundle/create.ts +4 -4
- package/src/tasks/bundle/fingerprint.ts +218 -0
- package/src/tasks/bundle/load.ts +4 -4
- package/src/tasks/bundle/zip.ts +3 -3
- package/src/tasks/conf/info.ts +3 -3
- package/src/tasks/conf/load.ts +3 -3
- package/src/tasks/fixture/download.ts +3 -3
- package/src/tasks/init.ts +3 -3
- package/src/tasks/runner/bundle.ts +3 -3
- package/src/tasks/runner/create.ts +3 -3
- package/src/tasks/runner/remove.ts +3 -3
- package/src/tasks/task/createTask.ts +10 -7
- package/src/tasks/task/describe.ts +3 -3
- package/src/tasks/task/download.ts +3 -3
- package/src/tasks/task/fingerprint.ts +107 -0
- package/src/tasks/task/list.ts +3 -3
- package/src/tasks/task/publish.ts +3 -3
- package/src/tasks/task/remove.ts +3 -3
- package/src/tasks/task/replay.ts +3 -3
- package/src/tasks/task/run.ts +5 -4
- package/src/test/tasks/create.test.ts +9 -9
- package/src/utils/taskAnalysis.ts +419 -0
package/dist/tasks/bundle/zip.js
CHANGED
|
@@ -43,54 +43,58 @@ const bytesToMB = (bytes) => {
|
|
|
43
43
|
return `${MB.toFixed(2)} MB`;
|
|
44
44
|
};
|
|
45
45
|
exports.bytesToMB = bytesToMB;
|
|
46
|
-
exports.zip = (0, task_1.createTask)(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
reject(err);
|
|
65
|
-
});
|
|
66
|
-
outStream.on('end', function () {
|
|
67
|
-
console.log('Data has been drained');
|
|
68
|
-
});
|
|
69
|
-
outStream.on('close', function () {
|
|
70
|
-
setTimeout(() => {
|
|
71
|
-
resolve({
|
|
72
|
-
output,
|
|
73
|
-
outputPath,
|
|
74
|
-
size: archive.pointer()
|
|
75
|
-
});
|
|
76
|
-
}, 100);
|
|
46
|
+
exports.zip = (0, task_1.createTask)({
|
|
47
|
+
schema,
|
|
48
|
+
boundaries,
|
|
49
|
+
fn: async function ({ dir, input, output }, { createWriteStream, createArchiver, resolvePathDir, fileExists }) {
|
|
50
|
+
const outputPath = await resolvePathDir(dir, output);
|
|
51
|
+
const inputPath = await resolvePathDir(dir, input);
|
|
52
|
+
const inputMapPath = inputPath + '.map';
|
|
53
|
+
// Check if input file exists
|
|
54
|
+
const inputExists = await fileExists(inputPath);
|
|
55
|
+
if (!inputExists) {
|
|
56
|
+
throw new Error(`Input file does not exist: ${inputPath}`);
|
|
57
|
+
}
|
|
58
|
+
// Check if source map exists before creating Promise
|
|
59
|
+
const mapExists = await fileExists(inputMapPath);
|
|
60
|
+
// Handle async operations outside of Promise constructor
|
|
61
|
+
const outStream = await createWriteStream(outputPath);
|
|
62
|
+
const archive = await createArchiver('zip', {
|
|
63
|
+
zlib: { level: 9 } // Sets the compression level
|
|
77
64
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
console.warn('ENOENT', err);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
archive.on('error', function (err) {
|
|
83
67
|
reject(err);
|
|
68
|
+
});
|
|
69
|
+
outStream.on('end', function () {
|
|
70
|
+
console.log('Data has been drained');
|
|
71
|
+
});
|
|
72
|
+
outStream.on('close', function () {
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
resolve({
|
|
75
|
+
output,
|
|
76
|
+
outputPath,
|
|
77
|
+
size: archive.pointer()
|
|
78
|
+
});
|
|
79
|
+
}, 100);
|
|
80
|
+
});
|
|
81
|
+
archive.on('warning', function (err) {
|
|
82
|
+
if (err.code === 'ENOENT') {
|
|
83
|
+
console.warn('ENOENT', err);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
reject(err);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
archive.pipe(outStream);
|
|
90
|
+
// Add the main bundle file
|
|
91
|
+
archive.file(inputPath, { name: 'index.js' });
|
|
92
|
+
// Add source map if it exists
|
|
93
|
+
if (mapExists) {
|
|
94
|
+
archive.file(inputMapPath, { name: 'index.js.map' });
|
|
84
95
|
}
|
|
96
|
+
archive.finalize();
|
|
85
97
|
});
|
|
86
|
-
|
|
87
|
-
// Add the main bundle file
|
|
88
|
-
archive.file(inputPath, { name: 'index.js' });
|
|
89
|
-
// Add source map if it exists
|
|
90
|
-
if (mapExists) {
|
|
91
|
-
archive.file(inputMapPath, { name: 'index.js.map' });
|
|
92
|
-
}
|
|
93
|
-
archive.finalize();
|
|
94
|
-
});
|
|
98
|
+
}
|
|
95
99
|
});
|
|
96
100
|
exports.zip.setDescription(description);
|
package/dist/tasks/conf/info.js
CHANGED
|
@@ -47,25 +47,29 @@ const boundaries = {
|
|
|
47
47
|
readFile: async (filePath) => fs.promises.readFile(filePath, 'utf-8'),
|
|
48
48
|
loadCurrentProfile: loadCurrent_1.loadCurrent.asBoundary()
|
|
49
49
|
};
|
|
50
|
-
exports.info = (0, task_1.createTask)(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
profile = await loadCurrentProfile({});
|
|
61
|
-
info.profile = {
|
|
62
|
-
name: profile.name,
|
|
63
|
-
url: profile.url,
|
|
64
|
-
apiKey: profile.apiKey
|
|
50
|
+
exports.info = (0, task_1.createTask)({
|
|
51
|
+
schema,
|
|
52
|
+
boundaries,
|
|
53
|
+
fn: async function (_argv, { loadCurrentProfile, readFile }) {
|
|
54
|
+
const packageJsonPath = path.join(__dirname, '../../../package.json');
|
|
55
|
+
const packageJsonContent = await readFile(packageJsonPath);
|
|
56
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
57
|
+
const info = {
|
|
58
|
+
version: packageJson.version,
|
|
59
|
+
profile: {}
|
|
65
60
|
};
|
|
61
|
+
let profile;
|
|
62
|
+
try {
|
|
63
|
+
profile = await loadCurrentProfile({});
|
|
64
|
+
info.profile = {
|
|
65
|
+
name: profile.name,
|
|
66
|
+
url: profile.url,
|
|
67
|
+
apiKey: profile.apiKey
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.log('No default profile set. Please run forge task:run auth:add to create a profile.');
|
|
72
|
+
}
|
|
73
|
+
return info;
|
|
66
74
|
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
console.log('No default profile set. Please run forge task:run auth:add to create a profile.');
|
|
69
|
-
}
|
|
70
|
-
return info;
|
|
71
75
|
});
|
package/dist/tasks/conf/load.js
CHANGED
|
@@ -14,8 +14,12 @@ const boundaries = {
|
|
|
14
14
|
return await promises_1.default.readFile(filePath, 'utf-8');
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
exports.load = (0, task_1.createTask)(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
exports.load = (0, task_1.createTask)({
|
|
18
|
+
schema,
|
|
19
|
+
boundaries,
|
|
20
|
+
fn: async function (_, { readFile }) {
|
|
21
|
+
const forgePath = path_1.default.join(process.cwd(), 'forge.json');
|
|
22
|
+
const content = await readFile(forgePath);
|
|
23
|
+
return JSON.parse(content);
|
|
24
|
+
}
|
|
21
25
|
});
|
|
@@ -45,38 +45,41 @@ const boundaries = {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
-
exports.download = (0, task_1.createTask)(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
console.error('Error downloading fixture:', error.message, error.status);
|
|
63
|
-
if (error.status === 404) {
|
|
64
|
-
throw new Error('Fixture not found');
|
|
48
|
+
exports.download = (0, task_1.createTask)({
|
|
49
|
+
schema,
|
|
50
|
+
boundaries,
|
|
51
|
+
fn: async function ({ uuid }, { downloadFixture, getCwd, persistFixture, loadCurrentProfile, loadConf }) {
|
|
52
|
+
console.log('==================================================');
|
|
53
|
+
console.log(`Attempting to download fixture with uuid: ${uuid}`);
|
|
54
|
+
console.log('==================================================');
|
|
55
|
+
const profile = await loadCurrentProfile({});
|
|
56
|
+
const cwd = await getCwd();
|
|
57
|
+
const forge = await loadConf({});
|
|
58
|
+
// Download from hive api server first to get the task descriptor
|
|
59
|
+
let response;
|
|
60
|
+
try {
|
|
61
|
+
response = await downloadFixture(uuid, profile);
|
|
65
62
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
63
|
+
catch (e) {
|
|
64
|
+
const error = e;
|
|
65
|
+
console.error('Error downloading fixture:', error.message, error.status);
|
|
66
|
+
if (error.status === 404) {
|
|
67
|
+
throw new Error('Fixture not found');
|
|
68
|
+
}
|
|
69
|
+
throw new Error('Failed to download fixture');
|
|
70
|
+
}
|
|
71
|
+
const fixture = response.fixture;
|
|
72
|
+
const taskName = fixture.taskName;
|
|
73
|
+
// Determine the output path using forge fixtures path and task descriptor
|
|
74
|
+
const fixturesBasePath = forge.paths.fixtures || 'fixtures';
|
|
75
|
+
const fixtureDir = path_1.default.join(fixturesBasePath, taskName);
|
|
76
|
+
const fixturePath = path_1.default.join(fixtureDir, `${uuid}.json`);
|
|
77
|
+
const filePath = path_1.default.resolve(cwd, fixturePath);
|
|
78
|
+
// Persist fixture to file
|
|
79
|
+
await persistFixture(filePath, response.fixture);
|
|
80
|
+
// Get the relative path for display in the replay command
|
|
81
|
+
const shortPath = path_1.default.join(taskName, `${uuid}.json`);
|
|
82
|
+
console.log(`
|
|
80
83
|
==================================================
|
|
81
84
|
Fixture download completed!
|
|
82
85
|
==================================================
|
|
@@ -90,10 +93,11 @@ Replay with:
|
|
|
90
93
|
forge task:replay ${taskName} --path ${shortPath}
|
|
91
94
|
==================================================
|
|
92
95
|
`);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
return {
|
|
97
|
+
status: 'Downloaded',
|
|
98
|
+
path: filePath,
|
|
99
|
+
shortPath: shortPath
|
|
100
|
+
};
|
|
101
|
+
}
|
|
98
102
|
});
|
|
99
103
|
exports.download.setDescription(description);
|
package/dist/tasks/init.js
CHANGED
|
@@ -20,36 +20,40 @@ const boundaries = {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
// Create a task with type inference from schema and boundaries
|
|
23
|
-
exports.init = (0, task_1.createTask)(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
23
|
+
exports.init = (0, task_1.createTask)({
|
|
24
|
+
schema,
|
|
25
|
+
boundaries,
|
|
26
|
+
fn: async function (argv, { saveFile, getCwd }) {
|
|
27
|
+
// Handle the dryRun flag
|
|
28
|
+
const isDryRun = Boolean(argv.dryRun);
|
|
29
|
+
const cwd = await getCwd();
|
|
30
|
+
const forgePath = path_1.default.join(cwd, 'forge.json');
|
|
31
|
+
const config = {
|
|
32
|
+
project: {
|
|
33
|
+
name: 'BaseProject'
|
|
34
|
+
},
|
|
35
|
+
paths: {
|
|
36
|
+
logs: 'logs/',
|
|
37
|
+
fixtures: 'fixtures/',
|
|
38
|
+
tasks: 'src/tasks/',
|
|
39
|
+
runners: 'src/runners/',
|
|
40
|
+
tests: 'src/tests/'
|
|
41
|
+
},
|
|
42
|
+
infra: {
|
|
43
|
+
region: 'us-west-2',
|
|
44
|
+
bucket: ''
|
|
45
|
+
},
|
|
46
|
+
tasks: {},
|
|
47
|
+
runners: {}
|
|
48
|
+
};
|
|
49
|
+
const content = JSON.stringify(config, null, 2);
|
|
50
|
+
if (!isDryRun) {
|
|
51
|
+
await saveFile(forgePath, content);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.log('Dry run, not creating forge.json');
|
|
55
|
+
console.log(content);
|
|
56
|
+
}
|
|
57
|
+
return config;
|
|
49
58
|
}
|
|
50
|
-
else {
|
|
51
|
-
console.log('Dry run, not creating forge.json');
|
|
52
|
-
console.log(content);
|
|
53
|
-
}
|
|
54
|
-
return config;
|
|
55
59
|
});
|
|
@@ -31,19 +31,22 @@ const boundaries = {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
exports.bundle = (0, task_1.createTask)(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
exports.bundle = (0, task_1.createTask)({
|
|
35
|
+
schema,
|
|
36
|
+
boundaries,
|
|
37
|
+
fn: async function ({ runnerName, targetPath }, { loadConf, getCwd, ensureDir }) {
|
|
38
|
+
// Load forge configuration
|
|
39
|
+
const forge = await loadConf({});
|
|
40
|
+
const cwd = await getCwd();
|
|
41
|
+
// Verify runner exists in forge.json
|
|
42
|
+
if (!forge.runners || !forge.runners[runnerName]) {
|
|
43
|
+
throw new Error(`Runner '${runnerName}' not found in forge.json configuration`);
|
|
44
|
+
}
|
|
45
|
+
// Get runner entry point from forge.json
|
|
46
|
+
const runnerConfig = forge.runners[runnerName];
|
|
47
|
+
const entryPoint = path_1.default.join(cwd, runnerConfig.path);
|
|
48
|
+
const outputFile = path_1.default.join(targetPath, `${runnerName}.js`);
|
|
49
|
+
console.log(`
|
|
47
50
|
==================================================
|
|
48
51
|
Starting runner creation!
|
|
49
52
|
Creating runner: ${runnerName}
|
|
@@ -51,21 +54,22 @@ exports.bundle = (0, task_1.createTask)(schema, boundaries, async function ({ ru
|
|
|
51
54
|
Output file: ${outputFile}
|
|
52
55
|
==================================================
|
|
53
56
|
`);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
// Ensure target directory exists
|
|
58
|
+
await ensureDir(path_1.default.dirname(targetPath));
|
|
59
|
+
// Build using esbuild
|
|
60
|
+
await esbuild_1.default.build({
|
|
61
|
+
entryPoints: [entryPoint],
|
|
62
|
+
outfile: outputFile,
|
|
63
|
+
bundle: true,
|
|
64
|
+
minify: true,
|
|
65
|
+
platform: 'node',
|
|
66
|
+
sourcemap: true
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
status: 'Success',
|
|
70
|
+
runnerName,
|
|
71
|
+
entryPoint,
|
|
72
|
+
outputFile: path_1.default.join(targetPath, `${runnerName}.js`)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
71
75
|
});
|
|
@@ -63,35 +63,39 @@ const boundaries = {
|
|
|
63
63
|
await promises_1.default.writeFile(forgePath, JSON.stringify(forge, null, 2));
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
|
-
exports.create = (0, task_1.createTask)(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
exports.create = (0, task_1.createTask)({
|
|
67
|
+
schema,
|
|
68
|
+
boundaries,
|
|
69
|
+
fn: async function ({ runnerName }, { persistRunner, loadConf, persistConf, getCwd }) {
|
|
70
|
+
const formattedName = (0, camelCase_1.camelCase)(runnerName);
|
|
71
|
+
const cwd = await getCwd();
|
|
72
|
+
const forge = await loadConf({});
|
|
73
|
+
const runnerPath = forge.paths.runners;
|
|
74
|
+
console.log(`
|
|
72
75
|
==================================================
|
|
73
76
|
Starting runner creation!
|
|
74
77
|
Creating runner: ${formattedName}
|
|
75
78
|
Into: ${runnerPath}${formattedName}/index.ts
|
|
76
79
|
==================================================
|
|
77
80
|
`);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
const comp = handlebars_1.default.compile(RUNNER_TEMPLATE);
|
|
82
|
+
const content = comp({
|
|
83
|
+
runnerName: formattedName
|
|
84
|
+
});
|
|
85
|
+
await persistRunner(runnerPath, formattedName, content);
|
|
86
|
+
if (forge.runners === undefined) {
|
|
87
|
+
forge.runners = {};
|
|
88
|
+
}
|
|
89
|
+
// Create runner descriptor
|
|
90
|
+
const runnerDescriptor = {
|
|
91
|
+
path: `${runnerPath}${formattedName}/index.ts`,
|
|
92
|
+
version: '0.0.1'
|
|
93
|
+
};
|
|
94
|
+
forge.runners[formattedName] = runnerDescriptor;
|
|
95
|
+
await persistConf(forge, cwd);
|
|
96
|
+
return {
|
|
97
|
+
runnerPath: `${runnerPath}/${formattedName}`,
|
|
98
|
+
runnerName: formattedName
|
|
99
|
+
};
|
|
85
100
|
}
|
|
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
101
|
});
|
|
@@ -32,27 +32,31 @@ const boundaries = {
|
|
|
32
32
|
await promises_1.default.writeFile(forgePath, JSON.stringify(forge, null, 2));
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
exports.remove = (0, task_1.createTask)(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
exports.remove = (0, task_1.createTask)({
|
|
36
|
+
schema,
|
|
37
|
+
boundaries,
|
|
38
|
+
fn: async function ({ runnerName }, { loadConf, getCwd, removeRunner, persistConf }) {
|
|
39
|
+
const formattedName = (0, camelCase_1.camelCase)(runnerName);
|
|
40
|
+
const cwd = await getCwd();
|
|
41
|
+
const forge = await loadConf({});
|
|
42
|
+
if (!forge.runners || !forge.runners[formattedName]) {
|
|
43
|
+
throw new Error(`Runner '${formattedName}' not found in forge.json configuration`);
|
|
44
|
+
}
|
|
45
|
+
const runnerConfig = forge.runners[formattedName];
|
|
46
|
+
const runnerFolder = path_1.default.join(cwd, path_1.default.dirname(runnerConfig.path));
|
|
47
|
+
console.log(`
|
|
45
48
|
==================================================
|
|
46
49
|
Removing runner: ${formattedName}
|
|
47
50
|
Path: ${runnerFolder}
|
|
48
51
|
==================================================
|
|
49
52
|
`);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
await removeRunner(runnerFolder);
|
|
54
|
+
delete forge.runners[formattedName];
|
|
55
|
+
await persistConf(forge, cwd);
|
|
56
|
+
return {
|
|
57
|
+
status: 'success',
|
|
58
|
+
message: `Runner '${formattedName}' successfully removed`,
|
|
59
|
+
runnerName: formattedName
|
|
60
|
+
};
|
|
61
|
+
}
|
|
58
62
|
});
|
|
@@ -20,6 +20,7 @@ const TASK_TEMPLATE = `// TASK: {{ taskName }}
|
|
|
20
20
|
import { createTask } from '@forgehive/task'
|
|
21
21
|
import { Schema } from '@forgehive/schema'
|
|
22
22
|
|
|
23
|
+
const name = '{{ taskDescriptor }}'
|
|
23
24
|
const description = 'Add task description here'
|
|
24
25
|
|
|
25
26
|
const schema = new Schema({
|
|
@@ -32,10 +33,12 @@ const boundaries = {
|
|
|
32
33
|
// example: readFile: async (path: string) => fs.readFile(path, 'utf-8')
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
export const {{ taskName }} = createTask(
|
|
36
|
+
export const {{ taskName }} = createTask({
|
|
37
|
+
name,
|
|
38
|
+
description,
|
|
36
39
|
schema,
|
|
37
40
|
boundaries,
|
|
38
|
-
async function (argv, boundaries) {
|
|
41
|
+
fn: async function (argv, boundaries) {
|
|
39
42
|
console.log('input:', argv)
|
|
40
43
|
console.log('boundaries:', boundaries)
|
|
41
44
|
// Your task implementation goes here
|
|
@@ -43,9 +46,8 @@ export const {{ taskName }} = createTask(
|
|
|
43
46
|
|
|
44
47
|
return status
|
|
45
48
|
}
|
|
46
|
-
)
|
|
49
|
+
})
|
|
47
50
|
|
|
48
|
-
{{ taskName }}.setDescription(description)
|
|
49
51
|
`;
|
|
50
52
|
const schema = new schema_1.Schema({
|
|
51
53
|
descriptorName: schema_1.Schema.string()
|
|
@@ -100,36 +102,41 @@ const boundaries = {
|
|
|
100
102
|
await promises_1.default.writeFile(forgePath, JSON.stringify(forge, null, 2));
|
|
101
103
|
}
|
|
102
104
|
};
|
|
103
|
-
exports.createTaskCommand = (0, task_1.createTask)(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
exports.createTaskCommand = (0, task_1.createTask)({
|
|
106
|
+
schema,
|
|
107
|
+
boundaries,
|
|
108
|
+
fn: async function ({ descriptorName }, { loadTemplate, persistTask, loadConf, persistConf, parseTaskName, getCwd }) {
|
|
109
|
+
const { taskName, fileName, descriptor, dir } = await parseTaskName(descriptorName);
|
|
110
|
+
const cwd = await getCwd();
|
|
111
|
+
const forge = await loadConf({});
|
|
112
|
+
let taskPath = forge.paths.tasks;
|
|
113
|
+
if (dir !== undefined) {
|
|
114
|
+
taskPath = path_1.default.join(taskPath, dir);
|
|
115
|
+
}
|
|
116
|
+
console.log(`
|
|
112
117
|
==================================================
|
|
113
118
|
Starting task creation!
|
|
114
119
|
Creating: ${taskName}
|
|
120
|
+
Descriptor: ${descriptor}
|
|
115
121
|
Dir: ${dir ?? ''}
|
|
116
122
|
Into: ${taskPath}
|
|
117
123
|
==================================================
|
|
118
124
|
`);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
const template = await loadTemplate();
|
|
126
|
+
const comp = handlebars_1.default.compile(template);
|
|
127
|
+
const content = comp({
|
|
128
|
+
taskName,
|
|
129
|
+
taskDescriptor: descriptor
|
|
130
|
+
});
|
|
131
|
+
await persistTask(taskPath, fileName, content, cwd);
|
|
132
|
+
if (forge.tasks === undefined) {
|
|
133
|
+
forge.tasks = {};
|
|
134
|
+
}
|
|
135
|
+
forge.tasks[descriptor] = {
|
|
136
|
+
path: `${taskPath}/${fileName}`,
|
|
137
|
+
handler: taskName
|
|
138
|
+
};
|
|
139
|
+
await persistConf(forge, cwd);
|
|
140
|
+
return { taskPath, fileName };
|
|
128
141
|
}
|
|
129
|
-
forge.tasks[descriptor] = {
|
|
130
|
-
path: `${taskPath}/${fileName}`,
|
|
131
|
-
handler: taskName
|
|
132
|
-
};
|
|
133
|
-
await persistConf(forge, cwd);
|
|
134
|
-
return { taskPath, fileName };
|
|
135
142
|
});
|