@forgehive/forge-cli 0.1.7 → 0.2.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 +57 -2
- package/dist/tasks/auth/add.d.ts +16 -0
- package/dist/tasks/auth/add.js +50 -0
- package/dist/tasks/auth/list.d.ts +14 -0
- package/dist/tasks/auth/list.js +31 -0
- package/dist/tasks/auth/load.d.ts +6 -0
- package/dist/tasks/auth/load.js +44 -0
- package/dist/tasks/auth/loadCurrent.d.ts +6 -0
- package/dist/tasks/auth/loadCurrent.js +24 -0
- package/dist/tasks/auth/remove.d.ts +13 -0
- package/dist/tasks/auth/remove.js +56 -0
- package/dist/tasks/auth/switch.d.ts +12 -0
- package/dist/tasks/auth/switch.js +43 -0
- package/dist/tasks/conf/info.d.ts +7 -0
- package/dist/tasks/conf/info.js +13 -8
- 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/dist/tasks/task/createTask.js +4 -0
- package/dist/tasks/task/download.d.ts +58 -0
- package/dist/tasks/task/download.js +153 -0
- package/dist/tasks/task/publish.d.ts +41 -0
- package/dist/tasks/task/publish.js +106 -0
- package/dist/tasks/types.d.ts +10 -0
- package/dist/test/tasks/create.test.js +4 -0
- package/forge.json +44 -0
- package/logs/auth:list.log +4 -0
- package/logs/auth:load.log +2 -0
- package/logs/auth:loadCurrent.log +1 -0
- package/logs/conf:info.log +1 -2
- package/logs/runner:create.log +3 -0
- package/package.json +3 -2
- package/src/runner.ts +60 -2
- package/src/tasks/auth/add.ts +57 -0
- package/src/tasks/auth/list.ts +43 -0
- package/src/tasks/auth/load.ts +51 -0
- package/src/tasks/auth/loadCurrent.ts +35 -0
- package/src/tasks/auth/remove.ts +66 -0
- package/src/tasks/auth/switch.ts +53 -0
- package/src/tasks/conf/info.ts +16 -8
- 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/src/tasks/task/createTask.ts +4 -0
- package/src/tasks/task/download.ts +192 -0
- package/src/tasks/task/publish.ts +135 -0
- package/src/tasks/types.ts +12 -0
- package/src/test/tasks/create.test.ts +4 -0
package/dist/runner.js
CHANGED
|
@@ -6,6 +6,15 @@ 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");
|
|
12
|
+
const publish_1 = require("./tasks/task/publish");
|
|
13
|
+
const download_1 = require("./tasks/task/download");
|
|
14
|
+
const add_1 = require("./tasks/auth/add");
|
|
15
|
+
const switch_1 = require("./tasks/auth/switch");
|
|
16
|
+
const list_1 = require("./tasks/auth/list");
|
|
17
|
+
const remove_3 = require("./tasks/auth/remove");
|
|
9
18
|
const runner = new runner_1.Runner((data) => {
|
|
10
19
|
const { _, ...filteredObj } = data;
|
|
11
20
|
return {
|
|
@@ -21,6 +30,17 @@ runner.load('info', info_1.info);
|
|
|
21
30
|
runner.load('task:create', createTask_1.createTaskCommand);
|
|
22
31
|
runner.load('task:run', run_1.run);
|
|
23
32
|
runner.load('task:remove', remove_1.remove);
|
|
33
|
+
runner.load('task:publish', publish_1.publish);
|
|
34
|
+
runner.load('task:download', download_1.download);
|
|
35
|
+
// Runner commands
|
|
36
|
+
runner.load('runner:create', create_1.create);
|
|
37
|
+
runner.load('runner:remove', remove_2.remove);
|
|
38
|
+
runner.load('runner:bundle', bundle_1.bundle);
|
|
39
|
+
// Auth commands
|
|
40
|
+
runner.load('auth:add', add_1.add);
|
|
41
|
+
runner.load('auth:switch', switch_1.switchProfile);
|
|
42
|
+
runner.load('auth:list', list_1.list);
|
|
43
|
+
runner.load('auth:remove', remove_3.remove);
|
|
24
44
|
// Set handler
|
|
25
45
|
runner.setHandler(async (data) => {
|
|
26
46
|
const parsedArgs = runner.parseArguments(data);
|
|
@@ -34,16 +54,51 @@ runner.setHandler(async (data) => {
|
|
|
34
54
|
}
|
|
35
55
|
try {
|
|
36
56
|
let result;
|
|
37
|
-
const
|
|
38
|
-
|
|
57
|
+
const commandsWithDescriptor = ['task:create', 'task:remove', 'task:publish'];
|
|
58
|
+
const commandsWithRunner = ['runner:create', 'runner:remove'];
|
|
59
|
+
if (commandsWithDescriptor.includes(taskName)) {
|
|
60
|
+
console.log('Running:', taskName, action);
|
|
39
61
|
result = await task.run({ descriptorName: action });
|
|
40
62
|
}
|
|
63
|
+
else if (commandsWithRunner.includes(taskName)) {
|
|
64
|
+
result = await task.run({
|
|
65
|
+
runnerName: action
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else if (taskName === 'runner:bundle') {
|
|
69
|
+
const paths = args;
|
|
70
|
+
result = await task.run({
|
|
71
|
+
runnerName: action,
|
|
72
|
+
targetPath: paths.targetPath
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else if (taskName === 'task:download') {
|
|
76
|
+
const { uuid } = args;
|
|
77
|
+
result = await task.run({
|
|
78
|
+
descriptorName: action,
|
|
79
|
+
uuid
|
|
80
|
+
});
|
|
81
|
+
}
|
|
41
82
|
else if (taskName === 'task:run') {
|
|
42
83
|
result = await task.run({
|
|
43
84
|
descriptorName: action,
|
|
44
85
|
args
|
|
45
86
|
});
|
|
46
87
|
}
|
|
88
|
+
else if (taskName === 'auth:add') {
|
|
89
|
+
const { apiKey, apiSecret, url } = args;
|
|
90
|
+
result = await task.run({
|
|
91
|
+
name: action,
|
|
92
|
+
apiKey,
|
|
93
|
+
apiSecret,
|
|
94
|
+
url
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else if (taskName === 'auth:switch' || taskName === 'auth:remove') {
|
|
98
|
+
result = await task.run({
|
|
99
|
+
profileName: action
|
|
100
|
+
});
|
|
101
|
+
}
|
|
47
102
|
else {
|
|
48
103
|
result = await task.run(args);
|
|
49
104
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Profiles } from '../types';
|
|
2
|
+
export declare const add: import("@forgehive/task").TaskInstanceType<(argv: {
|
|
3
|
+
name: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
apiSecret: string;
|
|
6
|
+
url: string;
|
|
7
|
+
}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
8
|
+
loadProfiles: (args: {}) => Promise<Promise<Profiles>>;
|
|
9
|
+
persistProfiles: (profiles: Profiles) => Promise<void>;
|
|
10
|
+
}>) => Promise<{
|
|
11
|
+
status: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}>, {
|
|
14
|
+
loadProfiles: (args: {}) => Promise<Promise<Profiles>>;
|
|
15
|
+
persistProfiles: (profiles: Profiles) => Promise<void>;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TASK: add
|
|
3
|
+
// Run this task with:
|
|
4
|
+
// forge task:run auth:add
|
|
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.add = 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 os_1 = __importDefault(require("os"));
|
|
15
|
+
const load_1 = require("./load");
|
|
16
|
+
const schema = new schema_1.Schema({
|
|
17
|
+
name: schema_1.Schema.string(),
|
|
18
|
+
apiKey: schema_1.Schema.string(),
|
|
19
|
+
apiSecret: schema_1.Schema.string(),
|
|
20
|
+
url: schema_1.Schema.string()
|
|
21
|
+
});
|
|
22
|
+
const boundaries = {
|
|
23
|
+
loadProfiles: load_1.load.asBoundary(),
|
|
24
|
+
persistProfiles: async (profiles) => {
|
|
25
|
+
const buildsPath = path_1.default.join(os_1.default.homedir(), '.forge');
|
|
26
|
+
const profilesPath = path_1.default.join(buildsPath, 'profiles.json');
|
|
27
|
+
await promises_1.default.writeFile(profilesPath, JSON.stringify(profiles, null, 2));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.add = (0, task_1.createTask)(schema, boundaries, async function ({ name, apiKey, apiSecret, url }, { loadProfiles, persistProfiles }) {
|
|
31
|
+
const profiles = await loadProfiles({});
|
|
32
|
+
// Check if profile with same name already exists
|
|
33
|
+
const existingProfileIndex = profiles.profiles.findIndex(p => p.name === name);
|
|
34
|
+
if (existingProfileIndex >= 0) {
|
|
35
|
+
// Replace existing profile
|
|
36
|
+
profiles.profiles[existingProfileIndex] = { name, apiKey, apiSecret, url };
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Add new profile
|
|
40
|
+
profiles.profiles.push({ name, apiKey, apiSecret, url });
|
|
41
|
+
}
|
|
42
|
+
// Set as default profile
|
|
43
|
+
profiles.default = name;
|
|
44
|
+
// Persist profiles
|
|
45
|
+
await persistProfiles(profiles);
|
|
46
|
+
return {
|
|
47
|
+
status: 'Ok',
|
|
48
|
+
message: `Profile '${name}' added and set as default`
|
|
49
|
+
};
|
|
50
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Profiles } from '../types';
|
|
2
|
+
export declare const list: import("@forgehive/task").TaskInstanceType<(argv: {}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
3
|
+
loadProfiles: (args: {}) => Promise<Promise<Profiles>>;
|
|
4
|
+
}>) => Promise<{
|
|
5
|
+
status: string;
|
|
6
|
+
profiles: never[];
|
|
7
|
+
default?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
default: string;
|
|
10
|
+
status?: undefined;
|
|
11
|
+
profiles?: undefined;
|
|
12
|
+
}>, {
|
|
13
|
+
loadProfiles: (args: {}) => Promise<Promise<Profiles>>;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TASK: list
|
|
3
|
+
// Run this task with:
|
|
4
|
+
// forge task:run auth:list
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.list = void 0;
|
|
7
|
+
const task_1 = require("@forgehive/task");
|
|
8
|
+
const schema_1 = require("@forgehive/schema");
|
|
9
|
+
const load_1 = require("./load");
|
|
10
|
+
const schema = new schema_1.Schema({});
|
|
11
|
+
const boundaries = {
|
|
12
|
+
loadProfiles: load_1.load.asBoundary()
|
|
13
|
+
};
|
|
14
|
+
exports.list = (0, task_1.createTask)(schema, boundaries, async function (_argv, { loadProfiles }) {
|
|
15
|
+
const profiles = await loadProfiles({});
|
|
16
|
+
if (profiles.profiles.length === 0) {
|
|
17
|
+
console.log('No profiles found. Use auth:add to create one.');
|
|
18
|
+
return { status: 'Ok', profiles: [] };
|
|
19
|
+
}
|
|
20
|
+
console.log('Available profiles:');
|
|
21
|
+
profiles.profiles.forEach(profile => {
|
|
22
|
+
const isDefault = profile.name === profiles.default;
|
|
23
|
+
const prefix = isDefault ? '* ' : ' ';
|
|
24
|
+
console.log(`${prefix}${profile.name} - API Key: ${profile.apiKey}`);
|
|
25
|
+
});
|
|
26
|
+
console.log('\nUse auth:add to create or update a profile');
|
|
27
|
+
console.log('\nUse auth:switch to switch to a profile');
|
|
28
|
+
return {
|
|
29
|
+
default: profiles.default
|
|
30
|
+
};
|
|
31
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Profiles } from '../types';
|
|
2
|
+
export declare const load: import("@forgehive/task").TaskInstanceType<(argv: {}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
3
|
+
ensureBuildsFolder: () => Promise<string>;
|
|
4
|
+
}>) => Promise<Profiles>, {
|
|
5
|
+
ensureBuildsFolder: () => Promise<string>;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TASK: load
|
|
3
|
+
// Run this task with:
|
|
4
|
+
// forge task:run auth:load
|
|
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.load = void 0;
|
|
10
|
+
const os_1 = __importDefault(require("os"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
13
|
+
const task_1 = require("@forgehive/task");
|
|
14
|
+
const schema_1 = require("@forgehive/schema");
|
|
15
|
+
const schema = new schema_1.Schema({});
|
|
16
|
+
const boundaries = {
|
|
17
|
+
ensureBuildsFolder: async () => {
|
|
18
|
+
const buildsPath = path_1.default.join(os_1.default.homedir(), '.forge');
|
|
19
|
+
try {
|
|
20
|
+
await promises_1.default.access(buildsPath);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
await promises_1.default.mkdir(buildsPath, { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
return buildsPath;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.load = (0, task_1.createTask)(schema, boundaries, async function (argv, { ensureBuildsFolder }) {
|
|
29
|
+
const buildsPath = await ensureBuildsFolder();
|
|
30
|
+
let profiles = {
|
|
31
|
+
default: '',
|
|
32
|
+
profiles: []
|
|
33
|
+
};
|
|
34
|
+
const profilesPath = path_1.default.join(buildsPath, 'profiles.json');
|
|
35
|
+
try {
|
|
36
|
+
const content = await promises_1.default.readFile(profilesPath, 'utf-8');
|
|
37
|
+
profiles = JSON.parse(content);
|
|
38
|
+
}
|
|
39
|
+
catch (_error) {
|
|
40
|
+
console.log('Creating profiles.json');
|
|
41
|
+
await promises_1.default.writeFile(profilesPath, '{"profiles": [], "default": ""}');
|
|
42
|
+
}
|
|
43
|
+
return profiles;
|
|
44
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Profile } from '../types';
|
|
2
|
+
export declare const loadCurrent: import("@forgehive/task").TaskInstanceType<(argv: {}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
3
|
+
loadProfiles: (args: {}) => Promise<Promise<import("../types").Profiles>>;
|
|
4
|
+
}>) => Promise<Profile>, {
|
|
5
|
+
loadProfiles: (args: {}) => Promise<Promise<import("../types").Profiles>>;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TASK: loadCurrent
|
|
3
|
+
// Run this task with:
|
|
4
|
+
// forge task:run auth:loadCurrent
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadCurrent = void 0;
|
|
7
|
+
const task_1 = require("@forgehive/task");
|
|
8
|
+
const schema_1 = require("@forgehive/schema");
|
|
9
|
+
const load_1 = require("./load");
|
|
10
|
+
const schema = new schema_1.Schema({});
|
|
11
|
+
const boundaries = {
|
|
12
|
+
loadProfiles: load_1.load.asBoundary()
|
|
13
|
+
};
|
|
14
|
+
exports.loadCurrent = (0, task_1.createTask)(schema, boundaries, async function (_argv, { loadProfiles }) {
|
|
15
|
+
const profiles = await loadProfiles({});
|
|
16
|
+
if (!profiles.default || profiles.default === '') {
|
|
17
|
+
throw new Error('No default profile set. Please run forge task:run auth:add to create a profile.');
|
|
18
|
+
}
|
|
19
|
+
const defaultProfile = profiles.profiles.find(profile => profile.name === profiles.default);
|
|
20
|
+
if (!defaultProfile) {
|
|
21
|
+
throw new Error(`Default profile "${profiles.default}" not found in profiles.`);
|
|
22
|
+
}
|
|
23
|
+
return { ...defaultProfile, name: profiles.default };
|
|
24
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Profiles } from '../types';
|
|
2
|
+
export declare const remove: import("@forgehive/task").TaskInstanceType<(argv: {
|
|
3
|
+
profileName: string;
|
|
4
|
+
}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
5
|
+
loadProfiles: (args: {}) => Promise<Promise<Profiles>>;
|
|
6
|
+
persistProfiles: (profiles: Profiles) => Promise<void>;
|
|
7
|
+
}>) => Promise<{
|
|
8
|
+
status: string;
|
|
9
|
+
message: string;
|
|
10
|
+
}>, {
|
|
11
|
+
loadProfiles: (args: {}) => Promise<Promise<Profiles>>;
|
|
12
|
+
persistProfiles: (profiles: Profiles) => Promise<void>;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TASK: remove
|
|
3
|
+
// Run this task with:
|
|
4
|
+
// forge task:run auth:remove --profileName [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 os_1 = __importDefault(require("os"));
|
|
15
|
+
const load_1 = require("./load");
|
|
16
|
+
const schema = new schema_1.Schema({
|
|
17
|
+
profileName: schema_1.Schema.string()
|
|
18
|
+
});
|
|
19
|
+
const boundaries = {
|
|
20
|
+
loadProfiles: load_1.load.asBoundary(),
|
|
21
|
+
persistProfiles: async (profiles) => {
|
|
22
|
+
const buildsPath = path_1.default.join(os_1.default.homedir(), '.forge');
|
|
23
|
+
const profilesPath = path_1.default.join(buildsPath, 'profiles.json');
|
|
24
|
+
await promises_1.default.writeFile(profilesPath, JSON.stringify(profiles, null, 2));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.remove = (0, task_1.createTask)(schema, boundaries, async function ({ profileName }, { loadProfiles, persistProfiles }) {
|
|
28
|
+
const profiles = await loadProfiles({});
|
|
29
|
+
// Check if profile exists
|
|
30
|
+
const profileExists = profiles.profiles.some(profile => profile.name === profileName);
|
|
31
|
+
if (!profileExists) {
|
|
32
|
+
throw new Error(`Profile "${profileName}" not found. Use auth:list to see available profiles.`);
|
|
33
|
+
}
|
|
34
|
+
// Remove the profile using filter
|
|
35
|
+
profiles.profiles = profiles.profiles.filter(profile => profile.name !== profileName);
|
|
36
|
+
// If the removed profile was the default, update the default
|
|
37
|
+
if (profiles.default === profileName) {
|
|
38
|
+
if (profiles.profiles.length > 0) {
|
|
39
|
+
// Set the first available profile as default
|
|
40
|
+
profiles.default = profiles.profiles[0].name;
|
|
41
|
+
console.log(`Default profile set to: ${profiles.default}`);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// No profiles left, set default to empty
|
|
45
|
+
profiles.default = '';
|
|
46
|
+
console.log('No profiles left. Default set to empty.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Persist updated profiles
|
|
50
|
+
await persistProfiles(profiles);
|
|
51
|
+
console.log(`Profile "${profileName}" has been removed.`);
|
|
52
|
+
return {
|
|
53
|
+
status: 'Ok',
|
|
54
|
+
message: `Profile "${profileName}" has been removed.`
|
|
55
|
+
};
|
|
56
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Profiles } from '../types';
|
|
2
|
+
export declare const switchProfile: import("@forgehive/task").TaskInstanceType<(argv: {
|
|
3
|
+
profileName: string;
|
|
4
|
+
}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
5
|
+
loadProfiles: (args: {}) => Promise<Promise<Profiles>>;
|
|
6
|
+
persistProfiles: (profiles: Profiles) => Promise<void>;
|
|
7
|
+
}>) => Promise<{
|
|
8
|
+
default: string;
|
|
9
|
+
}>, {
|
|
10
|
+
loadProfiles: (args: {}) => Promise<Promise<Profiles>>;
|
|
11
|
+
persistProfiles: (profiles: Profiles) => Promise<void>;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TASK: switch
|
|
3
|
+
// Run this task with:
|
|
4
|
+
// forge task:run auth:switch --profileName [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.switchProfile = 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 os_1 = __importDefault(require("os"));
|
|
15
|
+
const load_1 = require("./load");
|
|
16
|
+
const schema = new schema_1.Schema({
|
|
17
|
+
profileName: schema_1.Schema.string()
|
|
18
|
+
});
|
|
19
|
+
const boundaries = {
|
|
20
|
+
loadProfiles: load_1.load.asBoundary(),
|
|
21
|
+
persistProfiles: async (profiles) => {
|
|
22
|
+
const buildsPath = path_1.default.join(os_1.default.homedir(), '.forge');
|
|
23
|
+
const profilesPath = path_1.default.join(buildsPath, 'profiles.json');
|
|
24
|
+
await promises_1.default.writeFile(profilesPath, JSON.stringify(profiles, null, 2));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.switchProfile = (0, task_1.createTask)(schema, boundaries, async function ({ profileName }, { loadProfiles, persistProfiles }) {
|
|
28
|
+
// Load profiles
|
|
29
|
+
const profiles = await loadProfiles({});
|
|
30
|
+
// Check if profile exists
|
|
31
|
+
const profileExists = profiles.profiles.some(profile => profile.name === profileName);
|
|
32
|
+
if (!profileExists) {
|
|
33
|
+
throw new Error(`Profile "${profileName}" not found. Use auth:list to see available profiles.`);
|
|
34
|
+
}
|
|
35
|
+
// Update default profile
|
|
36
|
+
profiles.default = profileName;
|
|
37
|
+
// Save updated profiles
|
|
38
|
+
await persistProfiles(profiles);
|
|
39
|
+
console.log(`Switched to profile: ${profileName}`);
|
|
40
|
+
return {
|
|
41
|
+
default: profileName
|
|
42
|
+
};
|
|
43
|
+
});
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
export declare const info: import("@forgehive/task").TaskInstanceType<(argv: {}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
2
2
|
readFile: (filePath: string) => Promise<string>;
|
|
3
|
+
loadCurrentProfile: (args: {}) => Promise<Promise<import("../types").Profile>>;
|
|
3
4
|
}>) => Promise<{
|
|
4
5
|
version: any;
|
|
6
|
+
profile: {
|
|
7
|
+
name: string;
|
|
8
|
+
url: string;
|
|
9
|
+
apiKey: string;
|
|
10
|
+
};
|
|
5
11
|
}>, {
|
|
6
12
|
readFile: (filePath: string) => Promise<string>;
|
|
13
|
+
loadCurrentProfile: (args: {}) => Promise<Promise<import("../types").Profile>>;
|
|
7
14
|
}>;
|
package/dist/tasks/conf/info.js
CHANGED
|
@@ -41,18 +41,23 @@ const task_1 = require("@forgehive/task");
|
|
|
41
41
|
const schema_1 = require("@forgehive/schema");
|
|
42
42
|
const fs = __importStar(require("fs"));
|
|
43
43
|
const path = __importStar(require("path"));
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
});
|
|
44
|
+
const loadCurrent_1 = require("../auth/loadCurrent");
|
|
45
|
+
const schema = new schema_1.Schema({});
|
|
47
46
|
const boundaries = {
|
|
48
|
-
readFile: async (filePath) => fs.promises.readFile(filePath, 'utf-8')
|
|
47
|
+
readFile: async (filePath) => fs.promises.readFile(filePath, 'utf-8'),
|
|
48
|
+
loadCurrentProfile: loadCurrent_1.loadCurrent.asBoundary()
|
|
49
49
|
};
|
|
50
|
-
exports.info = (0, task_1.createTask)(schema, boundaries, async function (_argv,
|
|
50
|
+
exports.info = (0, task_1.createTask)(schema, boundaries, async function (_argv, { loadCurrentProfile, readFile }) {
|
|
51
51
|
const packageJsonPath = path.join(__dirname, '../../../package.json');
|
|
52
|
-
|
|
53
|
-
const packageJsonContent = await boundaries.readFile(packageJsonPath);
|
|
52
|
+
const packageJsonContent = await readFile(packageJsonPath);
|
|
54
53
|
const packageJson = JSON.parse(packageJsonContent);
|
|
54
|
+
const profile = await loadCurrentProfile({});
|
|
55
55
|
return {
|
|
56
|
-
version: packageJson.version
|
|
56
|
+
version: packageJson.version,
|
|
57
|
+
profile: {
|
|
58
|
+
name: profile.name,
|
|
59
|
+
url: profile.url,
|
|
60
|
+
apiKey: profile.apiKey
|
|
61
|
+
}
|
|
57
62
|
};
|
|
58
63
|
});
|
|
@@ -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
|
+
}>;
|