@launch77/cli 1.2.0 → 1.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/CHANGELOG.md +11 -0
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/infrastructure/git.d.ts +37 -0
- package/dist/infrastructure/git.d.ts.map +1 -0
- package/dist/infrastructure/git.js +82 -0
- package/dist/infrastructure/git.js.map +1 -0
- package/dist/infrastructure/github.d.ts +43 -0
- package/dist/infrastructure/github.d.ts.map +1 -0
- package/dist/infrastructure/github.js +89 -0
- package/dist/infrastructure/github.js.map +1 -0
- package/dist/modules/catalog/schemas/catalog-ui-components.schema.json +2 -18
- package/dist/modules/git/commands/git-connect.d.ts +3 -0
- package/dist/modules/git/commands/git-connect.d.ts.map +1 -0
- package/dist/modules/git/commands/git-connect.js +156 -0
- package/dist/modules/git/commands/git-connect.js.map +1 -0
- package/dist/modules/git/commands/git-setup-releases.d.ts +3 -0
- package/dist/modules/git/commands/git-setup-releases.d.ts.map +1 -0
- package/dist/modules/git/commands/git-setup-releases.js +128 -0
- package/dist/modules/git/commands/git-setup-releases.js.map +1 -0
- package/dist/modules/git/errors/git-errors.d.ts +18 -0
- package/dist/modules/git/errors/git-errors.d.ts.map +1 -0
- package/dist/modules/git/errors/git-errors.js +35 -0
- package/dist/modules/git/errors/git-errors.js.map +1 -0
- package/dist/modules/git/index.d.ts +3 -0
- package/dist/modules/git/index.d.ts.map +1 -0
- package/dist/modules/git/index.js +3 -0
- package/dist/modules/git/index.js.map +1 -0
- package/dist/modules/git/services/git-service.d.ts +19 -0
- package/dist/modules/git/services/git-service.d.ts.map +1 -0
- package/dist/modules/git/services/git-service.js +46 -0
- package/dist/modules/git/services/git-service.js.map +1 -0
- package/dist/modules/git/services/github-service.d.ts +27 -0
- package/dist/modules/git/services/github-service.d.ts.map +1 -0
- package/dist/modules/git/services/github-service.js +45 -0
- package/dist/modules/git/services/github-service.js.map +1 -0
- package/dist/modules/workspace/commands/init-workspace.d.ts.map +1 -1
- package/dist/modules/workspace/commands/init-workspace.js +4 -5
- package/dist/modules/workspace/commands/init-workspace.js.map +1 -1
- package/dist/modules/workspace/services/workspace-service.d.ts +2 -1
- package/dist/modules/workspace/services/workspace-service.d.ts.map +1 -1
- package/dist/modules/workspace/services/workspace-service.js +27 -1
- package/dist/modules/workspace/services/workspace-service.js.map +1 -1
- package/dist/templates/workspace/.github/workflows/ci.yml +99 -0
- package/dist/templates/workspace/package.json +15 -1
- package/package.json +2 -2
- package/src/cli.ts +5 -0
- package/src/infrastructure/git.ts +86 -0
- package/src/infrastructure/github.ts +111 -0
- package/src/modules/git/commands/git-connect.ts +183 -0
- package/src/modules/git/commands/git-setup-releases.ts +148 -0
- package/src/modules/git/errors/git-errors.ts +37 -0
- package/src/modules/git/index.ts +2 -0
- package/src/modules/git/services/git-service.ts +52 -0
- package/src/modules/git/services/github-service.ts +52 -0
- package/src/modules/workspace/commands/init-workspace.ts +4 -6
- package/src/modules/workspace/services/workspace-service.ts +30 -1
- package/templates/workspace/.github/workflows/ci.yml +99 -0
- package/templates/workspace/package.json +4 -0
- package/dist/app-templates/webapp/.env.ci +0 -6
- package/dist/app-templates/webapp/.env.example +0 -9
- package/dist/app-templates/webapp/.eslintrc.json +0 -6
- package/dist/app-templates/webapp/README.md.hbs +0 -80
- package/dist/app-templates/webapp/app/about/page.tsx.hbs +0 -41
- package/dist/app-templates/webapp/app/dashboard/page.tsx.hbs +0 -51
- package/dist/app-templates/webapp/app/globals.css +0 -31
- package/dist/app-templates/webapp/app/layout.tsx.hbs +0 -26
- package/dist/app-templates/webapp/app/page.tsx.hbs +0 -30
- package/dist/app-templates/webapp/next.config.js +0 -99
- package/dist/app-templates/webapp/package.json.hbs +0 -30
- package/dist/app-templates/webapp/postcss.config.js +0 -6
- package/dist/app-templates/webapp/tailwind.config.ts +0 -24
- package/dist/app-templates/webapp/tsconfig.json +0 -29
- package/dist/app-templates/webapp/vercel.json.hbs +0 -7
- package/dist/modules/catalog/schemas/schemas/catalog-ui-components.schema.json +0 -145
- package/dist/plugins/theme/package.json +0 -32
- package/dist/plugins/theme/plugin.json +0 -9
- package/dist/plugins/theme/src/generator.ts +0 -92
- package/dist/plugins/theme/src/utils/config-modifier.ts +0 -142
- package/dist/plugins/theme/src/utils/css-modifier.ts +0 -89
- package/dist/plugins/theme/templates/app/theme-test/page.tsx +0 -156
- package/dist/plugins/theme/templates/src/modules/theme/README.md +0 -209
- package/dist/plugins/theme/templates/src/modules/theme/config/brand.css +0 -23
- package/dist/plugins/theme/tsconfig.json +0 -14
- package/dist/plugins/theme/tsup.config.ts +0 -10
- package/dist/templates/templates/startup/apps/.gitkeep +0 -8
- package/dist/templates/templates/workspace/.launch77/workspace.json +0 -3
- package/dist/templates/templates/workspace/README.md +0 -62
- package/dist/templates/templates/workspace/app-templates/.gitkeep +0 -1
- package/dist/templates/templates/workspace/apps/.gitkeep +0 -1
- package/dist/templates/templates/workspace/libraries/.gitkeep +0 -1
- package/dist/templates/templates/workspace/package.json +0 -31
- package/dist/templates/templates/workspace/plugins/.gitkeep +0 -1
- package/dist/templates/templates/workspace/tsconfig.json +0 -22
- package/dist/templates/templates/workspace/turbo.json +0 -25
- /package/dist/templates/{templates/workspace → workspace}/.eslintignore +0 -0
- /package/dist/templates/{templates/workspace → workspace}/.eslintrc.js +0 -0
- /package/dist/templates/{templates/workspace → workspace}/.husky/pre-push +0 -0
- /package/dist/templates/{templates/workspace → workspace}/.lintstagedrc.json +0 -0
- /package/dist/templates/{templates/workspace → workspace}/.prettierrc +0 -0
package/src/cli.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Command } from 'commander'
|
|
|
5
5
|
import { createAppCommand, deleteAppCommand, generateManifestCommand, validateManifestCommand } from './modules/app/index.js'
|
|
6
6
|
import { scanCommand, createGenerateCommand } from './modules/catalog/index.js'
|
|
7
7
|
import { deployInitCommand, deployLogsCommand, deployStatusCommand } from './modules/deploy/index.js'
|
|
8
|
+
import { gitConnectCommand, gitSetupReleasesCommand } from './modules/git/index.js'
|
|
8
9
|
import { pluginInstallCommand } from './modules/plugin/index.js'
|
|
9
10
|
import { createStartupCommand } from './modules/startup/index.js'
|
|
10
11
|
import { getPackageVersion } from './utils/version.js'
|
|
@@ -26,6 +27,10 @@ program.addCommand(pluginInstallCommand())
|
|
|
26
27
|
program.addCommand(scanCommand())
|
|
27
28
|
program.addCommand(createGenerateCommand())
|
|
28
29
|
|
|
30
|
+
// Git commands
|
|
31
|
+
program.addCommand(gitConnectCommand())
|
|
32
|
+
program.addCommand(gitSetupReleasesCommand())
|
|
33
|
+
|
|
29
34
|
// Deploy commands
|
|
30
35
|
program.addCommand(deployInitCommand())
|
|
31
36
|
program.addCommand(deployStatusCommand())
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { execa } from 'execa'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if git is installed
|
|
5
|
+
*/
|
|
6
|
+
export async function isGitInstalled(): Promise<boolean> {
|
|
7
|
+
try {
|
|
8
|
+
await execa('git', ['--version'])
|
|
9
|
+
return true
|
|
10
|
+
} catch {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Check if a directory is a git repository
|
|
17
|
+
*/
|
|
18
|
+
export async function isGitRepository(cwd: string): Promise<boolean> {
|
|
19
|
+
try {
|
|
20
|
+
await execa('git', ['rev-parse', '--git-dir'], { cwd })
|
|
21
|
+
return true
|
|
22
|
+
} catch {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Initialize a git repository
|
|
29
|
+
*/
|
|
30
|
+
export async function gitInit(cwd: string): Promise<void> {
|
|
31
|
+
await execa('git', ['init'], { cwd })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Check if there are any commits in the repository
|
|
36
|
+
*/
|
|
37
|
+
export async function hasCommits(cwd: string): Promise<boolean> {
|
|
38
|
+
try {
|
|
39
|
+
await execa('git', ['rev-parse', 'HEAD'], { cwd })
|
|
40
|
+
return true
|
|
41
|
+
} catch {
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Stage all files
|
|
48
|
+
*/
|
|
49
|
+
export async function gitAddAll(cwd: string): Promise<void> {
|
|
50
|
+
await execa('git', ['add', '.'], { cwd })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Create a commit
|
|
55
|
+
*/
|
|
56
|
+
export async function gitCommit(cwd: string, message: string): Promise<void> {
|
|
57
|
+
await execa('git', ['commit', '-m', message], { cwd })
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get current branch name
|
|
62
|
+
*/
|
|
63
|
+
export async function getCurrentBranch(cwd: string): Promise<string> {
|
|
64
|
+
const result = await execa('git', ['branch', '--show-current'], { cwd })
|
|
65
|
+
return result.stdout.trim()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Check if a remote exists
|
|
70
|
+
*/
|
|
71
|
+
export async function hasRemote(cwd: string, remoteName: string): Promise<boolean> {
|
|
72
|
+
try {
|
|
73
|
+
await execa('git', ['remote', 'get-url', remoteName], { cwd })
|
|
74
|
+
return true
|
|
75
|
+
} catch {
|
|
76
|
+
return false
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get the URL of a remote
|
|
82
|
+
*/
|
|
83
|
+
export async function getRemoteUrl(cwd: string, remoteName: string): Promise<string> {
|
|
84
|
+
const result = await execa('git', ['remote', 'get-url', remoteName], { cwd })
|
|
85
|
+
return result.stdout.trim()
|
|
86
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { execa } from 'execa'
|
|
2
|
+
|
|
3
|
+
export interface GitHubOwner {
|
|
4
|
+
login: string
|
|
5
|
+
type: 'User' | 'Organization'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if gh CLI is installed
|
|
10
|
+
*/
|
|
11
|
+
export async function isGhInstalled(): Promise<boolean> {
|
|
12
|
+
try {
|
|
13
|
+
await execa('gh', ['--version'])
|
|
14
|
+
return true
|
|
15
|
+
} catch {
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Check if gh is authenticated
|
|
22
|
+
*/
|
|
23
|
+
export async function isGhAuthenticated(): Promise<boolean> {
|
|
24
|
+
try {
|
|
25
|
+
await execa('gh', ['auth', 'status'])
|
|
26
|
+
return true
|
|
27
|
+
} catch {
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get authenticated user's username
|
|
34
|
+
*/
|
|
35
|
+
export async function getUsername(): Promise<string> {
|
|
36
|
+
const result = await execa('gh', ['api', 'user', '--jq', '.login'])
|
|
37
|
+
return result.stdout.trim()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get user's organizations
|
|
42
|
+
*/
|
|
43
|
+
export async function getOrganizations(): Promise<string[]> {
|
|
44
|
+
const result = await execa('gh', ['api', 'user/orgs', '--jq', '.[].login'])
|
|
45
|
+
const output = result.stdout.trim()
|
|
46
|
+
return output ? output.split('\n') : []
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get all available owners (user + organizations)
|
|
51
|
+
*/
|
|
52
|
+
export async function getAvailableOwners(): Promise<GitHubOwner[]> {
|
|
53
|
+
const [username, orgs] = await Promise.all([getUsername(), getOrganizations()])
|
|
54
|
+
|
|
55
|
+
const owners: GitHubOwner[] = [
|
|
56
|
+
{
|
|
57
|
+
login: username,
|
|
58
|
+
type: 'User',
|
|
59
|
+
},
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
for (const org of orgs) {
|
|
63
|
+
owners.push({
|
|
64
|
+
login: org,
|
|
65
|
+
type: 'Organization',
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return owners
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Create a GitHub repository
|
|
74
|
+
*/
|
|
75
|
+
export async function createRepository(
|
|
76
|
+
owner: string,
|
|
77
|
+
repo: string,
|
|
78
|
+
options: {
|
|
79
|
+
visibility: 'private' | 'public'
|
|
80
|
+
cwd: string
|
|
81
|
+
}
|
|
82
|
+
): Promise<string> {
|
|
83
|
+
const repoName = `${owner}/${repo}`
|
|
84
|
+
const visibilityFlag = `--${options.visibility}`
|
|
85
|
+
|
|
86
|
+
await execa('gh', ['repo', 'create', repoName, visibilityFlag, '--source=.', '--remote=origin', '--push'], {
|
|
87
|
+
cwd: options.cwd,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// Return the repository URL
|
|
91
|
+
return `https://github.com/${owner}/${repo}`
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get the current repository information (owner/repo)
|
|
96
|
+
*/
|
|
97
|
+
export async function getCurrentRepository(cwd: string): Promise<{ owner: string; repo: string }> {
|
|
98
|
+
const result = await execa('gh', ['repo', 'view', '--json', 'owner,name'], { cwd })
|
|
99
|
+
const data = JSON.parse(result.stdout)
|
|
100
|
+
return {
|
|
101
|
+
owner: data.owner.login,
|
|
102
|
+
repo: data.name,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Set a repository secret using gh CLI
|
|
108
|
+
*/
|
|
109
|
+
export async function setRepositorySecret(owner: string, repo: string, secretName: string, secretValue: string): Promise<void> {
|
|
110
|
+
await execa('gh', ['secret', 'set', secretName, '-R', `${owner}/${repo}`, '--body', secretValue])
|
|
111
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import { Command } from 'commander'
|
|
3
|
+
import { select, input, confirm } from '@inquirer/prompts'
|
|
4
|
+
import ora from 'ora'
|
|
5
|
+
|
|
6
|
+
import { detectLaunch77Context } from '../../../utils/launch77-context.js'
|
|
7
|
+
import { GitHubCLINotInstalledError, GitHubNotAuthenticatedError, NotInWorkspaceError, GitNotInstalledError } from '../errors/git-errors.js'
|
|
8
|
+
import { GitHubService } from '../services/github-service.js'
|
|
9
|
+
import { GitService } from '../services/git-service.js'
|
|
10
|
+
|
|
11
|
+
interface ConnectOptions {
|
|
12
|
+
owner?: string
|
|
13
|
+
repo?: string
|
|
14
|
+
private?: boolean
|
|
15
|
+
public?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function gitConnectCommand(): Command {
|
|
19
|
+
return new Command('git:connect')
|
|
20
|
+
.description('Connect Launch77 workspace to GitHub repository')
|
|
21
|
+
.option('--owner <name>', 'GitHub owner (username or organization)')
|
|
22
|
+
.option('--repo <name>', 'Repository name (defaults to workspace name)')
|
|
23
|
+
.option('--private', 'Create private repository (default)')
|
|
24
|
+
.option('--public', 'Create public repository')
|
|
25
|
+
.action(async (options: ConnectOptions) => {
|
|
26
|
+
console.log(chalk.blue('\n🔗 Connecting workspace to GitHub...\n'))
|
|
27
|
+
|
|
28
|
+
const cwd = process.cwd()
|
|
29
|
+
const githubService = new GitHubService()
|
|
30
|
+
const gitService = new GitService()
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
// 1. Verify we're in a workspace root
|
|
34
|
+
const context = await detectLaunch77Context(cwd)
|
|
35
|
+
if (!context.isValid || context.locationType !== 'workspace-root') {
|
|
36
|
+
throw new NotInWorkspaceError(cwd)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 2. Verify prerequisites
|
|
40
|
+
const spinner = ora('Checking prerequisites...').start()
|
|
41
|
+
|
|
42
|
+
await gitService.verifyGitInstalled()
|
|
43
|
+
await githubService.verifyPrerequisites()
|
|
44
|
+
|
|
45
|
+
spinner.succeed('Prerequisites verified')
|
|
46
|
+
|
|
47
|
+
// 3. Check if already connected to a remote
|
|
48
|
+
const hasOrigin = await gitService.hasRemote(context.workspaceRoot)
|
|
49
|
+
|
|
50
|
+
if (hasOrigin) {
|
|
51
|
+
const remoteUrl = await gitService.getRemoteUrl(context.workspaceRoot)
|
|
52
|
+
|
|
53
|
+
console.log(chalk.yellow('\n⚠ This workspace is already connected to a git remote:\n'))
|
|
54
|
+
console.log(chalk.gray(` origin: ${chalk.cyan(remoteUrl)}\n`))
|
|
55
|
+
|
|
56
|
+
const shouldExit = await confirm({
|
|
57
|
+
message: 'Workspace already connected. Exit?',
|
|
58
|
+
default: true,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
if (shouldExit) {
|
|
62
|
+
console.log(chalk.green('\n✅ No changes made.\n'))
|
|
63
|
+
process.exit(0)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log(chalk.yellow('\n⚠ Continuing may fail if remote "origin" cannot be overwritten...\n'))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 4. Get available owners
|
|
70
|
+
const availableOwners = await githubService.getAvailableOwners()
|
|
71
|
+
|
|
72
|
+
// 5. Determine owner
|
|
73
|
+
let owner: string
|
|
74
|
+
if (options.owner) {
|
|
75
|
+
owner = options.owner
|
|
76
|
+
} else {
|
|
77
|
+
const ownerChoices = availableOwners.map((o) => ({
|
|
78
|
+
name: o.type === 'User' ? `${o.login} (personal)` : o.login,
|
|
79
|
+
value: o.login,
|
|
80
|
+
}))
|
|
81
|
+
|
|
82
|
+
owner = await select({
|
|
83
|
+
message: 'Select repository owner:',
|
|
84
|
+
choices: ownerChoices,
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 6. Determine repository name
|
|
89
|
+
let repoName: string
|
|
90
|
+
if (options.repo) {
|
|
91
|
+
repoName = options.repo
|
|
92
|
+
} else {
|
|
93
|
+
repoName = await input({
|
|
94
|
+
message: 'Repository name:',
|
|
95
|
+
default: context.workspaceName,
|
|
96
|
+
validate: (value) => {
|
|
97
|
+
if (!value || value.trim().length === 0) {
|
|
98
|
+
return 'Repository name cannot be empty'
|
|
99
|
+
}
|
|
100
|
+
// GitHub repo name validation (simplified)
|
|
101
|
+
const validPattern = /^[a-zA-Z0-9._-]+$/
|
|
102
|
+
if (!validPattern.test(value)) {
|
|
103
|
+
return 'Repository name must contain only letters, numbers, dots, hyphens, and underscores'
|
|
104
|
+
}
|
|
105
|
+
return true
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 7. Determine visibility
|
|
111
|
+
let visibility: 'private' | 'public'
|
|
112
|
+
if (options.public) {
|
|
113
|
+
visibility = 'public'
|
|
114
|
+
} else if (options.private) {
|
|
115
|
+
visibility = 'private'
|
|
116
|
+
} else {
|
|
117
|
+
const visibilityChoice = await select({
|
|
118
|
+
message: 'Repository visibility:',
|
|
119
|
+
choices: [
|
|
120
|
+
{ name: 'Private', value: 'private' as const },
|
|
121
|
+
{ name: 'Public', value: 'public' as const },
|
|
122
|
+
],
|
|
123
|
+
default: 'private' as const,
|
|
124
|
+
})
|
|
125
|
+
visibility = visibilityChoice
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 8. Ensure git repository is ready
|
|
129
|
+
await gitService.ensureRepositoryReady(context.workspaceRoot)
|
|
130
|
+
|
|
131
|
+
// 9. Create GitHub repository and push
|
|
132
|
+
const createSpinner = ora('Creating GitHub repository and pushing...').start()
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const repoUrl = await githubService.createAndPushRepository(owner, repoName, visibility, context.workspaceRoot)
|
|
136
|
+
|
|
137
|
+
createSpinner.succeed('Repository created and code pushed')
|
|
138
|
+
|
|
139
|
+
// Success message
|
|
140
|
+
console.log(chalk.green(`\n✅ Workspace connected to GitHub!\n`))
|
|
141
|
+
console.log(chalk.white(` Repository: ${chalk.cyan(repoUrl)}\n`))
|
|
142
|
+
console.log(chalk.gray(`Next steps:\n` + ` - Your code has been pushed to GitHub\n` + ` - GitHub Actions will run automatically\n` + ` - View your repository: ${chalk.cyan('gh repo view --web')}\n` + `\n` + ` ${chalk.yellow('📦 Enable automatic releases (recommended):')}\n` + ` - Run: ${chalk.cyan('launch77 git:setup-releases')}\n` + ` - This sets up the RELEASE_TOKEN for creating release PRs\n`))
|
|
143
|
+
} catch (error) {
|
|
144
|
+
createSpinner.fail('Failed to create repository')
|
|
145
|
+
|
|
146
|
+
// Check if it's a "repository already exists" error
|
|
147
|
+
if (error instanceof Error && error.message.includes('already exists')) {
|
|
148
|
+
console.error(chalk.red(`\n❌ Repository ${owner}/${repoName} already exists on GitHub\n`))
|
|
149
|
+
console.log(chalk.gray(` View existing repository: ${chalk.cyan(`https://github.com/${owner}/${repoName}`)}\n`))
|
|
150
|
+
} else {
|
|
151
|
+
throw error
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (error instanceof GitHubCLINotInstalledError) {
|
|
156
|
+
console.error(chalk.red(`\n❌ ${error.message}\n`))
|
|
157
|
+
console.log(chalk.gray(` Install with: ${chalk.cyan('brew install gh')}\n`))
|
|
158
|
+
console.log(chalk.gray(` Or visit: ${chalk.cyan('https://cli.github.com/')}\n`))
|
|
159
|
+
process.exit(1)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (error instanceof GitHubNotAuthenticatedError) {
|
|
163
|
+
console.error(chalk.red(`\n❌ ${error.message}\n`))
|
|
164
|
+
console.log(chalk.gray(` Authenticate with: ${chalk.cyan('gh auth login')}\n`))
|
|
165
|
+
process.exit(1)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (error instanceof NotInWorkspaceError) {
|
|
169
|
+
console.error(chalk.red(`\n❌ ${error.message}\n`))
|
|
170
|
+
console.log(chalk.gray(` This command must be run from a Launch77 workspace root directory\n`))
|
|
171
|
+
process.exit(1)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (error instanceof GitNotInstalledError) {
|
|
175
|
+
console.error(chalk.red(`\n❌ ${error.message}\n`))
|
|
176
|
+
console.log(chalk.gray(` Install git from: ${chalk.cyan('https://git-scm.com/downloads')}\n`))
|
|
177
|
+
process.exit(1)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
throw error
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import { Command } from 'commander'
|
|
3
|
+
import { password, confirm } from '@inquirer/prompts'
|
|
4
|
+
import ora from 'ora'
|
|
5
|
+
|
|
6
|
+
import { detectLaunch77Context } from '../../../utils/launch77-context.js'
|
|
7
|
+
import { GitHubCLINotInstalledError, GitHubNotAuthenticatedError, NotInWorkspaceError } from '../errors/git-errors.js'
|
|
8
|
+
import { GitHubService } from '../services/github-service.js'
|
|
9
|
+
import { GitService } from '../services/git-service.js'
|
|
10
|
+
|
|
11
|
+
interface SetupReleasesOptions {
|
|
12
|
+
token?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function gitSetupReleasesCommand(): Command {
|
|
16
|
+
return new Command('git:setup-releases')
|
|
17
|
+
.description('Configure GitHub RELEASE_TOKEN for automated release PRs')
|
|
18
|
+
.option('--token <token>', 'Personal Access Token (for automation)')
|
|
19
|
+
.action(async (options: SetupReleasesOptions) => {
|
|
20
|
+
console.log(chalk.blue('\n🔐 Setting up GitHub release automation...\n'))
|
|
21
|
+
|
|
22
|
+
const cwd = process.cwd()
|
|
23
|
+
const githubService = new GitHubService()
|
|
24
|
+
const gitService = new GitService()
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
// 1. Verify we're in a workspace root
|
|
28
|
+
const context = await detectLaunch77Context(cwd)
|
|
29
|
+
if (!context.isValid || context.locationType !== 'workspace-root') {
|
|
30
|
+
throw new NotInWorkspaceError(cwd)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 2. Verify prerequisites
|
|
34
|
+
const spinner = ora('Checking prerequisites...').start()
|
|
35
|
+
|
|
36
|
+
await githubService.verifyPrerequisites()
|
|
37
|
+
|
|
38
|
+
spinner.succeed('Prerequisites verified')
|
|
39
|
+
|
|
40
|
+
// 3. Check if repository has a remote
|
|
41
|
+
const hasOrigin = await gitService.hasRemote(context.workspaceRoot)
|
|
42
|
+
if (!hasOrigin) {
|
|
43
|
+
console.error(chalk.red('\n❌ This workspace is not connected to a GitHub repository\n'))
|
|
44
|
+
console.log(chalk.gray(` Connect to GitHub first: ${chalk.cyan('launch77 git:connect')}\n`))
|
|
45
|
+
process.exit(1)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 4. Get current repository information
|
|
49
|
+
const repoSpinner = ora('Detecting repository...').start()
|
|
50
|
+
const { owner, repo } = await githubService.getCurrentRepository(context.workspaceRoot)
|
|
51
|
+
repoSpinner.succeed(`Repository: ${owner}/${repo}`)
|
|
52
|
+
|
|
53
|
+
// 5. Explain what RELEASE_TOKEN is
|
|
54
|
+
console.log(chalk.cyan('\n📋 About RELEASE_TOKEN:\n'))
|
|
55
|
+
console.log(chalk.white('The RELEASE_TOKEN is a GitHub Personal Access Token (PAT) that allows'))
|
|
56
|
+
console.log(chalk.white('the Changesets action to create Pull Requests for version updates.\n'))
|
|
57
|
+
console.log(chalk.white('Why is this needed?'))
|
|
58
|
+
console.log(chalk.gray(' • The default GITHUB_TOKEN has limited permissions'))
|
|
59
|
+
console.log(chalk.gray(' • Creating PRs that trigger CI requires a PAT'))
|
|
60
|
+
console.log(chalk.gray(' • This enables automated release workflows\n'))
|
|
61
|
+
console.log(chalk.white('Required permissions:'))
|
|
62
|
+
console.log(chalk.gray(' • Contents: Read and write'))
|
|
63
|
+
console.log(chalk.gray(' • Pull requests: Read and write\n'))
|
|
64
|
+
|
|
65
|
+
// 6. Provide link to create PAT
|
|
66
|
+
const tokenUrl = 'https://github.com/settings/personal-access-tokens/new'
|
|
67
|
+
console.log(chalk.cyan('🔗 Create your token:'))
|
|
68
|
+
console.log(chalk.gray(` ${chalk.cyan(tokenUrl)}`))
|
|
69
|
+
console.log(chalk.gray(` Name: Launch77 Release Token`))
|
|
70
|
+
console.log(chalk.gray(` Permissions: Contents (Read and write), Pull requests (Read and write)\n`))
|
|
71
|
+
|
|
72
|
+
// 7. Get the token (from option or prompt)
|
|
73
|
+
let token: string
|
|
74
|
+
if (options.token) {
|
|
75
|
+
token = options.token
|
|
76
|
+
} else {
|
|
77
|
+
token = await password({
|
|
78
|
+
message: 'Paste your Personal Access Token (PAT):',
|
|
79
|
+
mask: '*',
|
|
80
|
+
validate: (value) => {
|
|
81
|
+
if (!value || value.trim().length === 0) {
|
|
82
|
+
return 'Token cannot be empty'
|
|
83
|
+
}
|
|
84
|
+
// GitHub PATs start with specific prefixes
|
|
85
|
+
if (!value.startsWith('ghp_') && !value.startsWith('github_pat_')) {
|
|
86
|
+
return 'Invalid token format. GitHub PATs should start with "ghp_" or "github_pat_"'
|
|
87
|
+
}
|
|
88
|
+
return true
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 8. Confirm if token already might exist
|
|
94
|
+
console.log(chalk.yellow('\n⚠ Note: This will overwrite any existing RELEASE_TOKEN secret\n'))
|
|
95
|
+
const shouldContinue = await confirm({
|
|
96
|
+
message: 'Continue and set RELEASE_TOKEN?',
|
|
97
|
+
default: true,
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
if (!shouldContinue) {
|
|
101
|
+
console.log(chalk.green('\n✅ No changes made.\n'))
|
|
102
|
+
process.exit(0)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 9. Set the repository secret
|
|
106
|
+
const setSpinner = ora('Setting RELEASE_TOKEN secret...').start()
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
await githubService.setRepositorySecret(owner, repo, 'RELEASE_TOKEN', token)
|
|
110
|
+
setSpinner.succeed('RELEASE_TOKEN configured successfully!')
|
|
111
|
+
|
|
112
|
+
// Success message
|
|
113
|
+
console.log(chalk.green('\n✅ Release automation is ready!\n'))
|
|
114
|
+
console.log(chalk.white('What happens now:'))
|
|
115
|
+
console.log(chalk.gray(' • When you push to main, CI runs as usual'))
|
|
116
|
+
console.log(chalk.gray(' • Changesets detects version changes'))
|
|
117
|
+
console.log(chalk.gray(' • A "Version Packages" PR is created automatically'))
|
|
118
|
+
console.log(chalk.gray(' • Merge the PR to publish your packages\n'))
|
|
119
|
+
console.log(chalk.cyan('📚 Learn more:'))
|
|
120
|
+
console.log(chalk.gray(` ${chalk.cyan('https://github.com/changesets/changesets')}\n`))
|
|
121
|
+
} catch (error) {
|
|
122
|
+
setSpinner.fail('Failed to set RELEASE_TOKEN')
|
|
123
|
+
throw error
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (error instanceof GitHubCLINotInstalledError) {
|
|
127
|
+
console.error(chalk.red(`\n❌ ${error.message}\n`))
|
|
128
|
+
console.log(chalk.gray(` Install with: ${chalk.cyan('brew install gh')}\n`))
|
|
129
|
+
console.log(chalk.gray(` Or visit: ${chalk.cyan('https://cli.github.com/')}\n`))
|
|
130
|
+
process.exit(1)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (error instanceof GitHubNotAuthenticatedError) {
|
|
134
|
+
console.error(chalk.red(`\n❌ ${error.message}\n`))
|
|
135
|
+
console.log(chalk.gray(` Authenticate with: ${chalk.cyan('gh auth login')}\n`))
|
|
136
|
+
process.exit(1)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (error instanceof NotInWorkspaceError) {
|
|
140
|
+
console.error(chalk.red(`\n❌ ${error.message}\n`))
|
|
141
|
+
console.log(chalk.gray(` This command must be run from a Launch77 workspace root directory\n`))
|
|
142
|
+
process.exit(1)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
throw error
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class GitHubCLINotInstalledError extends Error {
|
|
2
|
+
constructor() {
|
|
3
|
+
super('GitHub CLI (gh) is not installed')
|
|
4
|
+
this.name = 'GitHubCLINotInstalledError'
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class GitHubNotAuthenticatedError extends Error {
|
|
9
|
+
constructor() {
|
|
10
|
+
super('GitHub CLI is not authenticated')
|
|
11
|
+
this.name = 'GitHubNotAuthenticatedError'
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class NotInWorkspaceError extends Error {
|
|
16
|
+
constructor(cwd: string) {
|
|
17
|
+
super(`Not in a Launch77 workspace root. Current directory: ${cwd}`)
|
|
18
|
+
this.name = 'NotInWorkspaceError'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class GitNotInstalledError extends Error {
|
|
23
|
+
constructor() {
|
|
24
|
+
super('Git is not installed')
|
|
25
|
+
this.name = 'GitNotInstalledError'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class RepositoryAlreadyExistsError extends Error {
|
|
30
|
+
constructor(
|
|
31
|
+
public owner: string,
|
|
32
|
+
public repo: string
|
|
33
|
+
) {
|
|
34
|
+
super(`Repository ${owner}/${repo} already exists`)
|
|
35
|
+
this.name = 'RepositoryAlreadyExistsError'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as git from '../../../infrastructure/git.js'
|
|
2
|
+
import { GitNotInstalledError } from '../errors/git-errors.js'
|
|
3
|
+
|
|
4
|
+
export class GitService {
|
|
5
|
+
/**
|
|
6
|
+
* Verify git is installed
|
|
7
|
+
*/
|
|
8
|
+
async verifyGitInstalled(): Promise<void> {
|
|
9
|
+
const isInstalled = await git.isGitInstalled()
|
|
10
|
+
if (!isInstalled) {
|
|
11
|
+
throw new GitNotInstalledError()
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Initialize git repository if needed and create initial commit if needed
|
|
17
|
+
*/
|
|
18
|
+
async ensureRepositoryReady(cwd: string): Promise<void> {
|
|
19
|
+
// Check if git repository exists
|
|
20
|
+
const isRepo = await git.isGitRepository(cwd)
|
|
21
|
+
|
|
22
|
+
if (!isRepo) {
|
|
23
|
+
console.log('Initializing git repository...')
|
|
24
|
+
await git.gitInit(cwd)
|
|
25
|
+
console.log('✓ Git repository initialized')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Check if there are any commits
|
|
29
|
+
const hasAnyCommits = await git.hasCommits(cwd)
|
|
30
|
+
|
|
31
|
+
if (!hasAnyCommits) {
|
|
32
|
+
console.log('Creating initial commit...')
|
|
33
|
+
await git.gitAddAll(cwd)
|
|
34
|
+
await git.gitCommit(cwd, 'Initial commit')
|
|
35
|
+
console.log('✓ Initial commit created')
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Check if repository already has a remote
|
|
41
|
+
*/
|
|
42
|
+
async hasRemote(cwd: string, remoteName: string = 'origin'): Promise<boolean> {
|
|
43
|
+
return git.hasRemote(cwd, remoteName)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the URL of a remote
|
|
48
|
+
*/
|
|
49
|
+
async getRemoteUrl(cwd: string, remoteName: string = 'origin'): Promise<string> {
|
|
50
|
+
return git.getRemoteUrl(cwd, remoteName)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as github from '../../../infrastructure/github.js'
|
|
2
|
+
import { GitHubCLINotInstalledError, GitHubNotAuthenticatedError } from '../errors/git-errors.js'
|
|
3
|
+
|
|
4
|
+
import type { GitHubOwner } from '../../../infrastructure/github.js'
|
|
5
|
+
|
|
6
|
+
export class GitHubService {
|
|
7
|
+
/**
|
|
8
|
+
* Verify GitHub CLI prerequisites (installed and authenticated)
|
|
9
|
+
*/
|
|
10
|
+
async verifyPrerequisites(): Promise<void> {
|
|
11
|
+
const isInstalled = await github.isGhInstalled()
|
|
12
|
+
if (!isInstalled) {
|
|
13
|
+
throw new GitHubCLINotInstalledError()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const isAuthenticated = await github.isGhAuthenticated()
|
|
17
|
+
if (!isAuthenticated) {
|
|
18
|
+
throw new GitHubNotAuthenticatedError()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get all available repository owners (personal + organizations)
|
|
24
|
+
*/
|
|
25
|
+
async getAvailableOwners(): Promise<GitHubOwner[]> {
|
|
26
|
+
return github.getAvailableOwners()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a GitHub repository and push initial commit
|
|
31
|
+
*/
|
|
32
|
+
async createAndPushRepository(owner: string, repo: string, visibility: 'private' | 'public', cwd: string): Promise<string> {
|
|
33
|
+
return github.createRepository(owner, repo, {
|
|
34
|
+
visibility,
|
|
35
|
+
cwd,
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the current repository (owner/repo) from the working directory
|
|
41
|
+
*/
|
|
42
|
+
async getCurrentRepository(cwd: string): Promise<{ owner: string; repo: string }> {
|
|
43
|
+
return github.getCurrentRepository(cwd)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Set a repository secret
|
|
48
|
+
*/
|
|
49
|
+
async setRepositorySecret(owner: string, repo: string, secretName: string, secretValue: string): Promise<void> {
|
|
50
|
+
return github.setRepositorySecret(owner, repo, secretName, secretValue)
|
|
51
|
+
}
|
|
52
|
+
}
|