Skip to content

Commit bfa1e0b

Browse files
committed
chore: wip
1 parent 359b643 commit bfa1e0b

20 files changed

+234
-142
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ docs/.vitepress/cache
1313
/test/.tmp
1414
bin/gitit
1515
bin/gitit*
16+
/my-stack
17+
/stack-example

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ Gitit comes with the following features:
3030
bun install -g @stacksjs/gitit
3131

3232
# or use directly with bunx
33-
bunx @stacksjs/gitit template github:user/repo my-project
33+
bunx @stacksjs/gitit github:user/repo my-project
3434
```
3535

3636
## Usage
3737

3838
```bash
3939
# Basic usage
40-
gitit template github:user/repo my-project
40+
gitit github:user/repo my-project
4141

4242
# With options
43-
gitit template github:user/repo my-project --install --shell
43+
gitit github:user/repo my-project --install --shell
4444

4545
# Clone with custom command
46-
gitit template github:user/repo my-project --command "npm run dev"
46+
gitit github:user/repo my-project --command "npm run dev"
4747

4848
# Use offline cached template
49-
gitit template github:user/repo my-project --offline
49+
gitit github:user/repo my-project --offline
5050

5151
# Clone to a specific directory
52-
gitit template github:user/repo ./path/to/project
52+
gitit github:user/repo ./path/to/project
5353
```
5454

5555
## Available Options

bin/cli.ts

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import type { GitItOptions } from '../src/types'
2+
import { spawn } from 'node:child_process'
23
import { relative } from 'node:path'
34
import process from 'node:process'
45
import { CAC } from 'cac'
56
import { version } from '../package.json'
7+
import { downloadTemplate } from '../src/gitit'
8+
import { startShell } from '../src/utils'
69

710
const cli = new CAC('gitit')
811

@@ -42,22 +45,55 @@ cli
4245
process.chdir(options.cwd)
4346
}
4447

45-
// Placeholder for actual template download logic
46-
const templateDir = dir || './'
47-
const _to = relative(process.cwd(), templateDir) || './'
48-
console.log(`✨ Successfully cloned to \`${_to}\`\n`)
48+
try {
49+
// Use the actual downloadTemplate function instead of placeholder
50+
const result = await downloadTemplate(template, {
51+
dir,
52+
force: options?.force,
53+
forceClean: options?.forceClean,
54+
offline: options?.offline,
55+
preferOffline: options?.preferOffline,
56+
auth: options?.auth,
57+
install: options?.install,
58+
})
4959

50-
// Open a shell if requested
51-
if (options?.shell) {
52-
console.log('Opening shell in cloned directory...')
53-
// Placeholder for shell opening logic
54-
}
60+
const _to = relative(process.cwd(), result.dir) || './'
61+
console.log(`✨ Successfully cloned to \`${_to}\`\n`)
62+
63+
// Open a shell if requested
64+
if (options?.shell) {
65+
startShell(result.dir)
66+
}
67+
68+
// Run custom command if specified
69+
if (options?.command) {
70+
console.log(`Running command: ${options.command}`)
5571

56-
// Run custom command if specified
57-
if (options?.command) {
58-
console.log(`Running command: ${options.command}`)
59-
// Placeholder for command execution
60-
console.log(`Command execution would happen here`)
72+
// Execute the command
73+
const [cmd, ...args] = options.command.split(' ')
74+
const child = spawn(cmd!, args, {
75+
cwd: result.dir,
76+
stdio: 'inherit',
77+
shell: true,
78+
})
79+
80+
// Wait for the command to finish
81+
await new Promise<void>((resolve, reject) => {
82+
child.on('close', (code) => {
83+
if (code === 0) {
84+
resolve()
85+
}
86+
else {
87+
reject(new Error(`Command exited with code ${code}`))
88+
}
89+
})
90+
child.on('error', reject)
91+
})
92+
}
93+
}
94+
catch (error) {
95+
console.error(`Error cloning template: ${error instanceof Error ? error.message : String(error)}`)
96+
process.exit(1)
6197
}
6298
})
6399

docs/advanced/authentication.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ Gitit supports authentication for private repositories across different provider
99
The most common authentication method is using personal access tokens:
1010

1111
```bash
12-
gitit template github:user/private-repo my-project --auth "your-access-token"
12+
gitit github:user/private-repo my-project --auth "your-access-token"
1313
```
1414

1515
You can also provide authentication via environment variables:
1616

1717
```bash
1818
export GITIT_AUTH="your-access-token"
19-
gitit template github:user/private-repo my-project
19+
gitit github:user/private-repo my-project
2020
```
2121

2222
The environment variable `GITIT_AUTH` is checked by default if no `--auth` parameter is provided.
@@ -34,7 +34,7 @@ Authorization: Bearer your-access-token
3434
For GitHub, you need a [Personal Access Token (PAT)](https://github.com/settings/tokens):
3535

3636
```bash
37-
gitit template github:user/private-repo my-project --auth "ghp_xxxxxxxxxxxxxxx"
37+
gitit github:user/private-repo my-project --auth "ghp_xxxxxxxxxxxxxxx"
3838
```
3939

4040
GitHub API calls use the following headers:
@@ -50,23 +50,23 @@ X-GitHub-Api-Version: 2022-11-28
5050
For GitLab, you need a [Personal Access Token](https://gitlab.com/-/profile/personal_access_tokens):
5151

5252
```bash
53-
gitit template gitlab:user/private-repo my-project --auth "glpat-xxxxxxxxxxxxxxx"
53+
gitit gitlab:user/private-repo my-project --auth "glpat-xxxxxxxxxxxxxxx"
5454
```
5555

5656
### Bitbucket
5757

5858
For Bitbucket, you need an [App Password](https://bitbucket.org/account/settings/app-passwords/):
5959

6060
```bash
61-
gitit template bitbucket:user/private-repo my-project --auth "your-app-password"
61+
gitit bitbucket:user/private-repo my-project --auth "your-app-password"
6262
```
6363

6464
### SourceHut
6565

6666
For SourceHut, use your [OAuth token](https://meta.sr.ht/oauth):
6767

6868
```bash
69-
gitit template sourcehut:user/private-repo my-project --auth "your-oauth-token"
69+
gitit sourcehut:user/private-repo my-project --auth "your-oauth-token"
7070
```
7171

7272
## Custom GitHub or GitLab Instances
@@ -76,11 +76,11 @@ If you're using a GitHub Enterprise or custom GitLab instance, you can set the A
7676
```bash
7777
# For GitHub Enterprise
7878
export GITIT_GITHUB_URL="https://github.your-company.com/api/v3"
79-
gitit template github:user/private-repo my-project
79+
gitit github:user/private-repo my-project
8080

8181
# For GitLab self-hosted
8282
export GITIT_GITLAB_URL="https://gitlab.your-company.com"
83-
gitit template gitlab:user/private-repo my-project
83+
gitit gitlab:user/private-repo my-project
8484
```
8585

8686
## Secure Authentication Practices
@@ -118,7 +118,7 @@ jobs:
118118
steps:
119119
- uses: actions/checkout@v3
120120
- name: Clone template
121-
run: gitit template github:user/private-repo my-project
121+
run: gitit github:user/private-repo my-project
122122
env:
123123
GITIT_AUTH: ${{ secrets.GITHUB_TOKEN }}
124124
```

docs/advanced/bitbucket-private-repos.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Bitbucket uses App Passwords for API authentication. To create one:
1919
3. Select **Personal settings** from the menu
2020
4. In the left sidebar, click on **App passwords**
2121
5. Click the **Create app password** button
22-
6. Give your app password a descriptive name (e.g., "Gitit Template Access")
22+
6. Give your app password a descriptive name (e.g., "gitit Access")
2323
7. Select the following permissions:
2424
- **Repository**: Read
2525
- **Pull requests**: Read (optional)
@@ -31,7 +31,7 @@ Bitbucket uses App Passwords for API authentication. To create one:
3131
Once you have your app password, you can use it to clone private repositories:
3232

3333
```bash
34-
gitit template bitbucket:username/private-repo my-project --auth "your-app-password"
34+
gitit bitbucket:username/private-repo my-project --auth "your-app-password"
3535
```
3636

3737
Replace:
@@ -46,7 +46,7 @@ For security and convenience, you can set your app password as an environment va
4646

4747
```bash
4848
export GITIT_AUTH="your-app-password"
49-
gitit template bitbucket:username/private-repo my-project
49+
gitit bitbucket:username/private-repo my-project
5050
```
5151

5252
Add this to your `.bashrc`, `.zshrc`, or equivalent shell configuration file for persistent access.
@@ -84,23 +84,23 @@ If you get authentication errors:
8484
To clone a specific branch from a private Bitbucket repository:
8585

8686
```bash
87-
gitit template bitbucket:username/private-repo#develop my-project --auth "your-app-password"
87+
gitit bitbucket:username/private-repo#develop my-project --auth "your-app-password"
8888
```
8989

9090
### Cloning Subdirectories
9191

9292
To clone only a specific subdirectory from a private repository:
9393

9494
```bash
95-
gitit template bitbucket:username/private-repo/path/to/directory my-project --auth "your-app-password"
95+
gitit bitbucket:username/private-repo/path/to/directory my-project --auth "your-app-password"
9696
```
9797

9898
### Combined Branch and Subdirectory
9999

100100
You can specify both a branch and a subdirectory:
101101

102102
```bash
103-
gitit template bitbucket:username/private-repo/path/to/directory#develop my-project --auth "your-app-password"
103+
gitit bitbucket:username/private-repo/path/to/directory#develop my-project --auth "your-app-password"
104104
```
105105

106106
## Configuration File
@@ -129,7 +129,7 @@ jobs:
129129
steps:
130130
- uses: actions/checkout@v3
131131
- name: Clone Bitbucket template
132-
run: gitit template bitbucket:username/private-repo my-project
132+
run: gitit bitbucket:username/private-repo my-project
133133
env:
134134
GITIT_AUTH: ${{ secrets.BITBUCKET_APP_PASSWORD }}
135135
```

docs/advanced/custom-templates.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ This configuration file defines the template's metadata, variables, and lifecycl
8383
You can use custom templates just like any other template with Gitit:
8484

8585
```bash
86-
gitit template github:username/my-custom-template new-project
86+
gitit github:username/my-custom-template new-project
8787
```
8888

8989
If your template includes variables, you'll be prompted to provide values during the creation process.
@@ -93,7 +93,7 @@ If your template includes variables, you'll be prompted to provide values during
9393
You can also use local template directories:
9494

9595
```bash
96-
gitit template ./path/to/local/template new-project
96+
gitit ./path/to/local/template new-project
9797
```
9898

9999
This is useful during template development or for templates not hosted in a Git repository.
@@ -104,7 +104,7 @@ To share your custom templates with others:
104104

105105
1. Push your template repository to a Git hosting service
106106
2. Share the template URL with your team or community
107-
3. Consider adding your template to the Gitit template registry (forthcoming feature)
107+
3. Consider adding your template to the gitit registry (forthcoming feature)
108108

109109
## Best Practices
110110

docs/advanced/github-private-repos.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ To access private repositories, you'll need a Personal Access Token:
2020
4. Scroll down to the bottom of the left sidebar and click on **Developer settings**
2121
5. Click on **Personal access tokens****Tokens (classic)**
2222
6. Click **Generate new token****Generate new token (classic)**
23-
7. Give your token a descriptive name (e.g., "Gitit Template Access")
23+
7. Give your token a descriptive name (e.g., "gitit Access")
2424
8. Select the following scopes:
2525
- **repo** (Full control of private repositories)
2626
- **read:packages** (Optional - if you need to access template packages)
@@ -32,7 +32,7 @@ To access private repositories, you'll need a Personal Access Token:
3232
Once you have your personal access token, you can use it to clone private repositories:
3333

3434
```bash
35-
gitit template github:username/private-repo my-project --auth "ghp_your_token_here"
35+
gitit github:username/private-repo my-project --auth "ghp_your_token_here"
3636
```
3737

3838
Replace:
@@ -47,7 +47,7 @@ For security and convenience, you can set your token as an environment variable:
4747

4848
```bash
4949
export GITIT_AUTH="ghp_your_token_here"
50-
gitit template github:username/private-repo my-project
50+
gitit github:username/private-repo my-project
5151
```
5252

5353
Add this to your `.bashrc`, `.zshrc`, or equivalent shell configuration file for persistent access.
@@ -91,31 +91,31 @@ If you're using GitHub Enterprise, you can set a custom API URL:
9191

9292
```bash
9393
export GITIT_GITHUB_URL="https://github.your-company.com/api/v3"
94-
gitit template github:username/private-repo my-project --auth "your-token"
94+
gitit github:username/private-repo my-project --auth "your-token"
9595
```
9696

9797
### Specifying Branches
9898

9999
To clone a specific branch from a private GitHub repository:
100100

101101
```bash
102-
gitit template github:username/private-repo#develop my-project --auth "your-token"
102+
gitit github:username/private-repo#develop my-project --auth "your-token"
103103
```
104104

105105
### Cloning Subdirectories
106106

107107
To clone only a specific subdirectory from a private repository:
108108

109109
```bash
110-
gitit template github:username/private-repo/path/to/directory my-project --auth "your-token"
110+
gitit github:username/private-repo/path/to/directory my-project --auth "your-token"
111111
```
112112

113113
### Combined Branch and Subdirectory
114114

115115
You can specify both a branch and a subdirectory:
116116

117117
```bash
118-
gitit template github:username/private-repo/path/to/directory#develop my-project --auth "your-token"
118+
gitit github:username/private-repo/path/to/directory#develop my-project --auth "your-token"
119119
```
120120

121121
## Configuration File
@@ -144,7 +144,7 @@ jobs:
144144
steps:
145145
- uses: actions/checkout@v3
146146
- name: Clone GitHub template
147-
run: gitit template github:username/private-repo my-project
147+
run: gitit github:username/private-repo my-project
148148
env:
149149
GITIT_AUTH: ${{ secrets.GITHUB_TOKEN }}
150150
```
@@ -167,7 +167,7 @@ If you're using GitHub CLI (`gh`), you can create a token and use it directly:
167167
gh auth token
168168
169169
# Use the token with gitit
170-
gitit template github:username/private-repo my-project --auth "$(gh auth token)"
170+
gitit github:username/private-repo my-project --auth "$(gh auth token)"
171171
```
172172

173173
This approach avoids storing the token in your environment or files.

docs/advanced/plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ providers: {
156156
This would allow users to use templates with:
157157

158158
```bash
159-
gitit template myCompany:template-name my-project
159+
gitit myCompany:template-name my-project
160160
```
161161

162162
## Plugin Configuration

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default config
8181
_Then run:_
8282

8383
```bash
84-
gitit template github:user/repo my-project
84+
gitit github:user/repo my-project
8585
```
8686

8787
To learn more, head over to the [documentation](https://gitit.sh/).

0 commit comments

Comments
 (0)