@forgehive/forge-cli 0.1.8 → 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 +36 -1
- 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/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 +32 -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 -0
- package/package.json +5 -4
- package/src/runner.ts +37 -1
- 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/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
|
@@ -9,6 +9,12 @@ const remove_1 = require("./tasks/task/remove");
|
|
|
9
9
|
const create_1 = require("./tasks/runner/create");
|
|
10
10
|
const remove_2 = require("./tasks/runner/remove");
|
|
11
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");
|
|
12
18
|
const runner = new runner_1.Runner((data) => {
|
|
13
19
|
const { _, ...filteredObj } = data;
|
|
14
20
|
return {
|
|
@@ -24,10 +30,17 @@ runner.load('info', info_1.info);
|
|
|
24
30
|
runner.load('task:create', createTask_1.createTaskCommand);
|
|
25
31
|
runner.load('task:run', run_1.run);
|
|
26
32
|
runner.load('task:remove', remove_1.remove);
|
|
33
|
+
runner.load('task:publish', publish_1.publish);
|
|
34
|
+
runner.load('task:download', download_1.download);
|
|
27
35
|
// Runner commands
|
|
28
36
|
runner.load('runner:create', create_1.create);
|
|
29
37
|
runner.load('runner:remove', remove_2.remove);
|
|
30
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);
|
|
31
44
|
// Set handler
|
|
32
45
|
runner.setHandler(async (data) => {
|
|
33
46
|
const parsedArgs = runner.parseArguments(data);
|
|
@@ -41,9 +54,10 @@ runner.setHandler(async (data) => {
|
|
|
41
54
|
}
|
|
42
55
|
try {
|
|
43
56
|
let result;
|
|
44
|
-
const commandsWithDescriptor = ['task:create', 'task:remove'];
|
|
57
|
+
const commandsWithDescriptor = ['task:create', 'task:remove', 'task:publish'];
|
|
45
58
|
const commandsWithRunner = ['runner:create', 'runner:remove'];
|
|
46
59
|
if (commandsWithDescriptor.includes(taskName)) {
|
|
60
|
+
console.log('Running:', taskName, action);
|
|
47
61
|
result = await task.run({ descriptorName: action });
|
|
48
62
|
}
|
|
49
63
|
else if (commandsWithRunner.includes(taskName)) {
|
|
@@ -58,12 +72,33 @@ runner.setHandler(async (data) => {
|
|
|
58
72
|
targetPath: paths.targetPath
|
|
59
73
|
});
|
|
60
74
|
}
|
|
75
|
+
else if (taskName === 'task:download') {
|
|
76
|
+
const { uuid } = args;
|
|
77
|
+
result = await task.run({
|
|
78
|
+
descriptorName: action,
|
|
79
|
+
uuid
|
|
80
|
+
});
|
|
81
|
+
}
|
|
61
82
|
else if (taskName === 'task:run') {
|
|
62
83
|
result = await task.run({
|
|
63
84
|
descriptorName: action,
|
|
64
85
|
args
|
|
65
86
|
});
|
|
66
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
|
+
}
|
|
67
102
|
else {
|
|
68
103
|
result = await task.run(args);
|
|
69
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
|
});
|
|
@@ -20,6 +20,8 @@ const TASK_TEMPLATE = `// TASK: {{ taskName }}
|
|
|
20
20
|
import { createTask } from '@forgehive/task'
|
|
21
21
|
import { Schema } from '@forgehive/schema'
|
|
22
22
|
|
|
23
|
+
const description = 'Add task description here'
|
|
24
|
+
|
|
23
25
|
const schema = new Schema({
|
|
24
26
|
// Add your schema definitions here
|
|
25
27
|
// example: myParam: Schema.string()
|
|
@@ -42,6 +44,8 @@ export const {{ taskName }} = createTask(
|
|
|
42
44
|
return status
|
|
43
45
|
}
|
|
44
46
|
)
|
|
47
|
+
|
|
48
|
+
{{ taskName }}.setDescription(description)
|
|
45
49
|
`;
|
|
46
50
|
const schema = new schema_1.Schema({
|
|
47
51
|
descriptorName: schema_1.Schema.string()
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Profile, type ForgeConf } from '../types';
|
|
2
|
+
export declare const download: import("@forgehive/task").TaskInstanceType<(argv: {
|
|
3
|
+
descriptorName: string;
|
|
4
|
+
uuid: string;
|
|
5
|
+
}, boundaries: import("@forgehive/task").WrappedBoundaries<{
|
|
6
|
+
loadCurrentProfile: (args: {}) => Promise<Promise<Profile>>;
|
|
7
|
+
downloadTask: (uuid: string, profile: Profile) => Promise<any>;
|
|
8
|
+
loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
|
|
9
|
+
getCwd: () => Promise<string>;
|
|
10
|
+
parseTaskName: (taskDescriptor: string) => Promise<{
|
|
11
|
+
descriptor: string;
|
|
12
|
+
taskName: string;
|
|
13
|
+
fileName: string;
|
|
14
|
+
dir?: string;
|
|
15
|
+
}>;
|
|
16
|
+
persistTask: (dir: string, fileName: string, content: string, cwd: string) => Promise<{
|
|
17
|
+
path: string;
|
|
18
|
+
}>;
|
|
19
|
+
persistConf: (forge: ForgeConf, cwd: string) => Promise<void>;
|
|
20
|
+
checkTaskExists: (dir: string, fileName: string) => Promise<boolean>;
|
|
21
|
+
}>) => Promise<{
|
|
22
|
+
error: string;
|
|
23
|
+
taskPath: string;
|
|
24
|
+
descriptor: string;
|
|
25
|
+
message?: undefined;
|
|
26
|
+
fileName?: undefined;
|
|
27
|
+
handler?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
error: string;
|
|
30
|
+
message: string;
|
|
31
|
+
taskPath: string;
|
|
32
|
+
descriptor: string;
|
|
33
|
+
fileName?: undefined;
|
|
34
|
+
handler?: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
taskPath: string;
|
|
37
|
+
fileName: string;
|
|
38
|
+
descriptor: string;
|
|
39
|
+
handler: any;
|
|
40
|
+
error?: undefined;
|
|
41
|
+
message?: undefined;
|
|
42
|
+
}>, {
|
|
43
|
+
loadCurrentProfile: (args: {}) => Promise<Promise<Profile>>;
|
|
44
|
+
downloadTask: (uuid: string, profile: Profile) => Promise<any>;
|
|
45
|
+
loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
|
|
46
|
+
getCwd: () => Promise<string>;
|
|
47
|
+
parseTaskName: (taskDescriptor: string) => Promise<{
|
|
48
|
+
descriptor: string;
|
|
49
|
+
taskName: string;
|
|
50
|
+
fileName: string;
|
|
51
|
+
dir?: string;
|
|
52
|
+
}>;
|
|
53
|
+
persistTask: (dir: string, fileName: string, content: string, cwd: string) => Promise<{
|
|
54
|
+
path: string;
|
|
55
|
+
}>;
|
|
56
|
+
persistConf: (forge: ForgeConf, cwd: string) => Promise<void>;
|
|
57
|
+
checkTaskExists: (dir: string, fileName: string) => Promise<boolean>;
|
|
58
|
+
}>;
|