@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/logs/conf:info.log
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
{"name":"conf:info","type":"
|
|
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"}]}}
|
|
1
|
+
{"name":"conf:info","type":"error","input":{},"error":"ENOENT: no such file or directory, open '/Users/package.json'","boundaries":{"readFile":[{"input":["/Users/package.json"],"error":"ENOENT: no such file or directory, open '/Users/package.json'"}],"loadCurrentProfile":[]}}
|
|
@@ -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.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript CLI application",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,12 +20,13 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"axios": "^1.8.4",
|
|
23
24
|
"esbuild": "^0.25.0",
|
|
24
25
|
"handlebars": "^4.7.8",
|
|
25
26
|
"minimist": "^1.2.8",
|
|
26
|
-
"@forgehive/record-tape": "0.0.1",
|
|
27
27
|
"@forgehive/schema": "0.1.4",
|
|
28
28
|
"@forgehive/task": "0.1.4",
|
|
29
|
+
"@forgehive/record-tape": "0.0.1",
|
|
29
30
|
"@forgehive/runner": "0.1.4"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
package/src/runner.ts
CHANGED
|
@@ -8,6 +8,17 @@ 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
|
+
import { publish as publishTask } from './tasks/task/publish'
|
|
15
|
+
import { download as downloadTask } from './tasks/task/download'
|
|
16
|
+
|
|
17
|
+
import { add as addProfile } from './tasks/auth/add'
|
|
18
|
+
import { switchProfile } from './tasks/auth/switch'
|
|
19
|
+
import { list as listProfiles } from './tasks/auth/list'
|
|
20
|
+
import { remove as removeProfile } from './tasks/auth/remove'
|
|
21
|
+
|
|
11
22
|
interface CliParsedArguments extends RunnerParsedArguments {
|
|
12
23
|
action: string;
|
|
13
24
|
}
|
|
@@ -30,6 +41,19 @@ runner.load('info', info)
|
|
|
30
41
|
runner.load('task:create', createTaskCommand)
|
|
31
42
|
runner.load('task:run', taskRunCommand)
|
|
32
43
|
runner.load('task:remove', taskRemoveCommand)
|
|
44
|
+
runner.load('task:publish', publishTask)
|
|
45
|
+
runner.load('task:download', downloadTask)
|
|
46
|
+
|
|
47
|
+
// Runner commands
|
|
48
|
+
runner.load('runner:create', createRunner)
|
|
49
|
+
runner.load('runner:remove', removeRunner)
|
|
50
|
+
runner.load('runner:bundle', bundleRunner)
|
|
51
|
+
|
|
52
|
+
// Auth commands
|
|
53
|
+
runner.load('auth:add', addProfile)
|
|
54
|
+
runner.load('auth:switch', switchProfile)
|
|
55
|
+
runner.load('auth:list', listProfiles)
|
|
56
|
+
runner.load('auth:remove', removeProfile)
|
|
33
57
|
|
|
34
58
|
// Set handler
|
|
35
59
|
runner.setHandler(async (data: ParsedArgs): Promise<unknown> => {
|
|
@@ -48,14 +72,48 @@ runner.setHandler(async (data: ParsedArgs): Promise<unknown> => {
|
|
|
48
72
|
try {
|
|
49
73
|
let result
|
|
50
74
|
|
|
51
|
-
const
|
|
52
|
-
|
|
75
|
+
const commandsWithDescriptor = ['task:create', 'task:remove', 'task:publish']
|
|
76
|
+
const commandsWithRunner = ['runner:create', 'runner:remove']
|
|
77
|
+
|
|
78
|
+
if (commandsWithDescriptor.includes(taskName)) {
|
|
79
|
+
console.log('Running:', taskName, action)
|
|
53
80
|
result = await task.run({ descriptorName: action })
|
|
81
|
+
} else if (commandsWithRunner.includes(taskName)) {
|
|
82
|
+
result = await task.run({
|
|
83
|
+
runnerName: action
|
|
84
|
+
})
|
|
85
|
+
} else if (taskName === 'runner:bundle') {
|
|
86
|
+
const paths = args as { targetPath: string }
|
|
87
|
+
|
|
88
|
+
result = await task.run({
|
|
89
|
+
runnerName: action,
|
|
90
|
+
targetPath: paths.targetPath
|
|
91
|
+
})
|
|
92
|
+
} else if (taskName === 'task:download') {
|
|
93
|
+
const { uuid } = args as { uuid: string }
|
|
94
|
+
|
|
95
|
+
result = await task.run({
|
|
96
|
+
descriptorName: action,
|
|
97
|
+
uuid
|
|
98
|
+
})
|
|
54
99
|
} else if (taskName === 'task:run') {
|
|
55
100
|
result = await task.run({
|
|
56
101
|
descriptorName: action,
|
|
57
102
|
args
|
|
58
103
|
})
|
|
104
|
+
} else if (taskName === 'auth:add') {
|
|
105
|
+
const { apiKey, apiSecret, url } = args as { name: string, apiKey: string, apiSecret: string, url: string }
|
|
106
|
+
|
|
107
|
+
result = await task.run({
|
|
108
|
+
name: action,
|
|
109
|
+
apiKey,
|
|
110
|
+
apiSecret,
|
|
111
|
+
url
|
|
112
|
+
})
|
|
113
|
+
} else if (taskName === 'auth:switch' || taskName === 'auth:remove') {
|
|
114
|
+
result = await task.run({
|
|
115
|
+
profileName: action
|
|
116
|
+
})
|
|
59
117
|
} else {
|
|
60
118
|
result = await task.run(args)
|
|
61
119
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// TASK: add
|
|
2
|
+
// Run this task with:
|
|
3
|
+
// forge task:run auth:add
|
|
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 os from 'os'
|
|
10
|
+
|
|
11
|
+
import { load as loadProfiles } from './load'
|
|
12
|
+
import { type Profiles } from '../types'
|
|
13
|
+
|
|
14
|
+
const schema = new Schema({
|
|
15
|
+
name: Schema.string(),
|
|
16
|
+
apiKey: Schema.string(),
|
|
17
|
+
apiSecret: Schema.string(),
|
|
18
|
+
url: Schema.string()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const boundaries = {
|
|
22
|
+
loadProfiles: loadProfiles.asBoundary(),
|
|
23
|
+
persistProfiles: async (profiles: Profiles): Promise<void> => {
|
|
24
|
+
const buildsPath = path.join(os.homedir(), '.forge')
|
|
25
|
+
const profilesPath = path.join(buildsPath, 'profiles.json')
|
|
26
|
+
await fs.writeFile(profilesPath, JSON.stringify(profiles, null, 2))
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const add = createTask(
|
|
31
|
+
schema,
|
|
32
|
+
boundaries,
|
|
33
|
+
async function ({ name, apiKey, apiSecret, url }, { loadProfiles, persistProfiles }) {
|
|
34
|
+
const profiles = await loadProfiles({})
|
|
35
|
+
|
|
36
|
+
// Check if profile with same name already exists
|
|
37
|
+
const existingProfileIndex = profiles.profiles.findIndex(p => p.name === name)
|
|
38
|
+
if (existingProfileIndex >= 0) {
|
|
39
|
+
// Replace existing profile
|
|
40
|
+
profiles.profiles[existingProfileIndex] = { name, apiKey, apiSecret, url }
|
|
41
|
+
} else {
|
|
42
|
+
// Add new profile
|
|
43
|
+
profiles.profiles.push({ name, apiKey, apiSecret, url })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Set as default profile
|
|
47
|
+
profiles.default = name
|
|
48
|
+
|
|
49
|
+
// Persist profiles
|
|
50
|
+
await persistProfiles(profiles)
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
status: 'Ok',
|
|
54
|
+
message: `Profile '${name}' added and set as default`
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// TASK: list
|
|
2
|
+
// Run this task with:
|
|
3
|
+
// forge task:run auth:list
|
|
4
|
+
|
|
5
|
+
import { createTask } from '@forgehive/task'
|
|
6
|
+
import { Schema } from '@forgehive/schema'
|
|
7
|
+
|
|
8
|
+
import { load as loadProfiles } from './load'
|
|
9
|
+
import { type Profiles } from '../types'
|
|
10
|
+
|
|
11
|
+
const schema = new Schema({})
|
|
12
|
+
|
|
13
|
+
const boundaries = {
|
|
14
|
+
loadProfiles: loadProfiles.asBoundary()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const list = createTask(
|
|
18
|
+
schema,
|
|
19
|
+
boundaries,
|
|
20
|
+
async function (_argv, { loadProfiles }) {
|
|
21
|
+
const profiles: Profiles = await loadProfiles({})
|
|
22
|
+
|
|
23
|
+
if (profiles.profiles.length === 0) {
|
|
24
|
+
console.log('No profiles found. Use auth:add to create one.')
|
|
25
|
+
return { status: 'Ok', profiles: [] }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
console.log('Available profiles:')
|
|
29
|
+
|
|
30
|
+
profiles.profiles.forEach(profile => {
|
|
31
|
+
const isDefault = profile.name === profiles.default
|
|
32
|
+
const prefix = isDefault ? '* ' : ' '
|
|
33
|
+
console.log(`${prefix}${profile.name} - API Key: ${profile.apiKey}`)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
console.log('\nUse auth:add to create or update a profile')
|
|
37
|
+
console.log('\nUse auth:switch to switch to a profile')
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
default: profiles.default
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// TASK: load
|
|
2
|
+
// Run this task with:
|
|
3
|
+
// forge task:run auth:load
|
|
4
|
+
|
|
5
|
+
import os from 'os'
|
|
6
|
+
import path from 'path'
|
|
7
|
+
import fs from 'fs/promises'
|
|
8
|
+
|
|
9
|
+
import { createTask } from '@forgehive/task'
|
|
10
|
+
import { Schema } from '@forgehive/schema'
|
|
11
|
+
|
|
12
|
+
import { type Profiles } from '../types'
|
|
13
|
+
|
|
14
|
+
const schema = new Schema({})
|
|
15
|
+
|
|
16
|
+
const boundaries = {
|
|
17
|
+
ensureBuildsFolder: async (): Promise<string> => {
|
|
18
|
+
const buildsPath = path.join(os.homedir(), '.forge')
|
|
19
|
+
try {
|
|
20
|
+
await fs.access(buildsPath)
|
|
21
|
+
} catch {
|
|
22
|
+
await fs.mkdir(buildsPath, { recursive: true })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return buildsPath
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const load = createTask(
|
|
30
|
+
schema,
|
|
31
|
+
boundaries,
|
|
32
|
+
async function (argv, { ensureBuildsFolder }) {
|
|
33
|
+
const buildsPath = await ensureBuildsFolder()
|
|
34
|
+
|
|
35
|
+
let profiles: Profiles = {
|
|
36
|
+
default: '',
|
|
37
|
+
profiles: []
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const profilesPath = path.join(buildsPath, 'profiles.json')
|
|
41
|
+
try {
|
|
42
|
+
const content = await fs.readFile(profilesPath, 'utf-8')
|
|
43
|
+
profiles = JSON.parse(content) as Profiles
|
|
44
|
+
} catch (_error) {
|
|
45
|
+
console.log('Creating profiles.json')
|
|
46
|
+
await fs.writeFile(profilesPath, '{"profiles": [], "default": ""}')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return profiles
|
|
50
|
+
}
|
|
51
|
+
)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// TASK: loadCurrent
|
|
2
|
+
// Run this task with:
|
|
3
|
+
// forge task:run auth:loadCurrent
|
|
4
|
+
|
|
5
|
+
import { createTask } from '@forgehive/task'
|
|
6
|
+
import { Schema } from '@forgehive/schema'
|
|
7
|
+
|
|
8
|
+
import { load as loadProfiles } from './load'
|
|
9
|
+
import { type Profile } from '../types'
|
|
10
|
+
|
|
11
|
+
const schema = new Schema({})
|
|
12
|
+
|
|
13
|
+
const boundaries = {
|
|
14
|
+
loadProfiles: loadProfiles.asBoundary()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const loadCurrent = createTask(
|
|
18
|
+
schema,
|
|
19
|
+
boundaries,
|
|
20
|
+
async function (_argv, { loadProfiles }): Promise<Profile> {
|
|
21
|
+
const profiles = await loadProfiles({})
|
|
22
|
+
|
|
23
|
+
if (!profiles.default || profiles.default === '') {
|
|
24
|
+
throw new Error('No default profile set. Please run forge task:run auth:add to create a profile.')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const defaultProfile = profiles.profiles.find(profile => profile.name === profiles.default)
|
|
28
|
+
|
|
29
|
+
if (!defaultProfile) {
|
|
30
|
+
throw new Error(`Default profile "${profiles.default}" not found in profiles.`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return { ...defaultProfile, name: profiles.default }
|
|
34
|
+
}
|
|
35
|
+
)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// TASK: remove
|
|
2
|
+
// Run this task with:
|
|
3
|
+
// forge task:run auth:remove --profileName [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 os from 'os'
|
|
10
|
+
|
|
11
|
+
import { load as loadProfiles } from './load'
|
|
12
|
+
import { type Profiles } from '../types'
|
|
13
|
+
|
|
14
|
+
const schema = new Schema({
|
|
15
|
+
profileName: Schema.string()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const boundaries = {
|
|
19
|
+
loadProfiles: loadProfiles.asBoundary(),
|
|
20
|
+
persistProfiles: async (profiles: Profiles): Promise<void> => {
|
|
21
|
+
const buildsPath = path.join(os.homedir(), '.forge')
|
|
22
|
+
const profilesPath = path.join(buildsPath, 'profiles.json')
|
|
23
|
+
await fs.writeFile(profilesPath, JSON.stringify(profiles, null, 2))
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const remove = createTask(
|
|
28
|
+
schema,
|
|
29
|
+
boundaries,
|
|
30
|
+
async function ({ profileName }, { loadProfiles, persistProfiles }) {
|
|
31
|
+
const profiles = await loadProfiles({})
|
|
32
|
+
|
|
33
|
+
// Check if profile exists
|
|
34
|
+
const profileExists = profiles.profiles.some(profile => profile.name === profileName)
|
|
35
|
+
|
|
36
|
+
if (!profileExists) {
|
|
37
|
+
throw new Error(`Profile "${profileName}" not found. Use auth:list to see available profiles.`)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Remove the profile using filter
|
|
41
|
+
profiles.profiles = profiles.profiles.filter(profile => profile.name !== profileName)
|
|
42
|
+
|
|
43
|
+
// If the removed profile was the default, update the default
|
|
44
|
+
if (profiles.default === profileName) {
|
|
45
|
+
if (profiles.profiles.length > 0) {
|
|
46
|
+
// Set the first available profile as default
|
|
47
|
+
profiles.default = profiles.profiles[0].name
|
|
48
|
+
console.log(`Default profile set to: ${profiles.default}`)
|
|
49
|
+
} else {
|
|
50
|
+
// No profiles left, set default to empty
|
|
51
|
+
profiles.default = ''
|
|
52
|
+
console.log('No profiles left. Default set to empty.')
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Persist updated profiles
|
|
57
|
+
await persistProfiles(profiles)
|
|
58
|
+
|
|
59
|
+
console.log(`Profile "${profileName}" has been removed.`)
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
status: 'Ok',
|
|
63
|
+
message: `Profile "${profileName}" has been removed.`
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// TASK: switch
|
|
2
|
+
// Run this task with:
|
|
3
|
+
// forge task:run auth:switch --profileName [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 os from 'os'
|
|
10
|
+
|
|
11
|
+
import { load as loadProfiles } from './load'
|
|
12
|
+
import { type Profiles } from '../types'
|
|
13
|
+
|
|
14
|
+
const schema = new Schema({
|
|
15
|
+
profileName: Schema.string()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const boundaries = {
|
|
19
|
+
loadProfiles: loadProfiles.asBoundary(),
|
|
20
|
+
persistProfiles: async (profiles: Profiles): Promise<void> => {
|
|
21
|
+
const buildsPath = path.join(os.homedir(), '.forge')
|
|
22
|
+
const profilesPath = path.join(buildsPath, 'profiles.json')
|
|
23
|
+
await fs.writeFile(profilesPath, JSON.stringify(profiles, null, 2))
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const switchProfile = createTask(
|
|
28
|
+
schema,
|
|
29
|
+
boundaries,
|
|
30
|
+
async function ({ profileName }, { loadProfiles, persistProfiles }) {
|
|
31
|
+
// Load profiles
|
|
32
|
+
const profiles = await loadProfiles({})
|
|
33
|
+
|
|
34
|
+
// Check if profile exists
|
|
35
|
+
const profileExists = profiles.profiles.some(profile => profile.name === profileName)
|
|
36
|
+
|
|
37
|
+
if (!profileExists) {
|
|
38
|
+
throw new Error(`Profile "${profileName}" not found. Use auth:list to see available profiles.`)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Update default profile
|
|
42
|
+
profiles.default = profileName
|
|
43
|
+
|
|
44
|
+
// Save updated profiles
|
|
45
|
+
await persistProfiles(profiles)
|
|
46
|
+
|
|
47
|
+
console.log(`Switched to profile: ${profileName}`)
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
default: profileName
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
)
|
package/src/tasks/conf/info.ts
CHANGED
|
@@ -7,26 +7,34 @@ import { Schema } from '@forgehive/schema'
|
|
|
7
7
|
import * as fs from 'fs'
|
|
8
8
|
import * as path from 'path'
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})
|
|
10
|
+
import { loadCurrent as loadCurrentProfile } from '../auth/loadCurrent'
|
|
11
|
+
|
|
12
|
+
const schema = new Schema({})
|
|
13
13
|
|
|
14
14
|
const boundaries = {
|
|
15
|
-
readFile: async (filePath: string): Promise<string> => fs.promises.readFile(filePath, 'utf-8')
|
|
15
|
+
readFile: async (filePath: string): Promise<string> => fs.promises.readFile(filePath, 'utf-8'),
|
|
16
|
+
loadCurrentProfile: loadCurrentProfile.asBoundary()
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export const info = createTask(
|
|
19
20
|
schema,
|
|
20
21
|
boundaries,
|
|
21
|
-
async function (_argv,
|
|
22
|
+
async function (_argv, { loadCurrentProfile, readFile }) {
|
|
22
23
|
const packageJsonPath = path.join(__dirname, '../../../package.json')
|
|
23
|
-
console.log('packageJsonPath', packageJsonPath)
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
const packageJsonContent = await readFile(packageJsonPath)
|
|
26
27
|
const packageJson = JSON.parse(packageJsonContent)
|
|
27
28
|
|
|
29
|
+
const profile = await loadCurrentProfile({})
|
|
30
|
+
|
|
28
31
|
return {
|
|
29
|
-
version: packageJson.version
|
|
32
|
+
version: packageJson.version,
|
|
33
|
+
profile: {
|
|
34
|
+
name: profile.name,
|
|
35
|
+
url: profile.url,
|
|
36
|
+
apiKey: profile.apiKey
|
|
37
|
+
}
|
|
30
38
|
}
|
|
31
39
|
}
|
|
32
40
|
)
|
|
@@ -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
|
+
)
|