Skip to content

Commit 77dfc04

Browse files
authored
Merge pull request #6166 from Shopify/remove-workflows-from-theme-init
Removed workflows folder when cloning skeleton theme
2 parents 28fefcd + b47f879 commit 77dfc04

File tree

3 files changed

+80
-4
lines changed

3 files changed

+80
-4
lines changed

.changeset/four-rabbits-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme': patch
3+
---
4+
5+
Removed workflows folder in .github when cloning skeleton theme

packages/theme/src/cli/services/init.test.ts

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {cloneRepoAndCheckoutLatestTag, cloneRepo, promptAndCreateAIFile} from './init.js'
22
import {describe, expect, vi, test, beforeEach} from 'vitest'
3-
import {downloadGitRepository} from '@shopify/cli-kit/node/git'
3+
import {downloadGitRepository, removeGitRemote} from '@shopify/cli-kit/node/git'
44
import {renderSelectPrompt} from '@shopify/cli-kit/node/ui'
5-
import {writeFile} from '@shopify/cli-kit/node/fs'
5+
import {writeFile, rmdir, fileExists} from '@shopify/cli-kit/node/fs'
66
import {fetch} from '@shopify/cli-kit/node/http'
77
import {joinPath} from '@shopify/cli-kit/node/path'
88

@@ -19,7 +19,12 @@ vi.mock('@shopify/cli-kit/node/ui', async () => {
1919
})
2020

2121
describe('cloneRepoAndCheckoutLatestTag()', async () => {
22-
test('calls downloadRepository function from git service to clone a repo without branch', async () => {
22+
beforeEach(() => {
23+
vi.mocked(fileExists).mockResolvedValue(true)
24+
vi.mocked(joinPath).mockImplementation((...paths) => paths.join('/'))
25+
})
26+
27+
test('calls downloadRepository function from git service to clone a repo with latest tag', async () => {
2328
// Given
2429
const repoUrl = 'https://github.com/Shopify/dawn.git'
2530
const destination = 'destination'
@@ -32,9 +37,40 @@ describe('cloneRepoAndCheckoutLatestTag()', async () => {
3237
// Then
3338
expect(downloadGitRepository).toHaveBeenCalledWith({repoUrl, destination, latestTag, shallow})
3439
})
40+
41+
test('removes git remote after cloning', async () => {
42+
// Given
43+
const repoUrl = 'https://github.com/Shopify/dawn.git'
44+
const destination = 'destination'
45+
46+
// When
47+
await cloneRepoAndCheckoutLatestTag(repoUrl, destination)
48+
49+
// Then
50+
expect(removeGitRemote).toHaveBeenCalledWith(destination)
51+
})
52+
53+
test('removes .github directory from skeleton theme after cloning when it exists', async () => {
54+
// Given
55+
const repoUrl = 'https://github.com/Shopify/skeleton-theme.git'
56+
const destination = 'destination'
57+
vi.mocked(fileExists).mockResolvedValue(true)
58+
59+
// When
60+
await cloneRepoAndCheckoutLatestTag(repoUrl, destination)
61+
62+
// Then
63+
expect(fileExists).toHaveBeenCalledWith('destination/.github')
64+
expect(rmdir).toHaveBeenCalledWith('destination/.github')
65+
})
3566
})
3667

3768
describe('cloneRepo()', async () => {
69+
beforeEach(() => {
70+
vi.mocked(fileExists).mockResolvedValue(true)
71+
vi.mocked(joinPath).mockImplementation((...paths) => paths.join('/'))
72+
})
73+
3874
test('calls downloadRepository function from git service to clone a repo without branch', async () => {
3975
// Given
4076
const repoUrl = 'https://github.com/Shopify/dawn.git'
@@ -46,6 +82,32 @@ describe('cloneRepo()', async () => {
4682
// Then
4783
expect(downloadGitRepository).toHaveBeenCalledWith({repoUrl, destination, shallow})
4884
})
85+
86+
test('removes git remote after cloning', async () => {
87+
// Given
88+
const repoUrl = 'https://github.com/Shopify/dawn.git'
89+
const destination = 'destination'
90+
91+
// When
92+
await cloneRepo(repoUrl, destination)
93+
94+
// Then
95+
expect(removeGitRemote).toHaveBeenCalledWith(destination)
96+
})
97+
98+
test('removes .github directory from skeleton theme after cloning when it exists', async () => {
99+
// Given
100+
const repoUrl = 'https://github.com/Shopify/skeleton-theme.git'
101+
const destination = 'destination'
102+
vi.mocked(fileExists).mockResolvedValue(true)
103+
104+
// When
105+
await cloneRepo(repoUrl, destination)
106+
107+
// Then
108+
expect(fileExists).toHaveBeenCalledWith('destination/.github')
109+
expect(rmdir).toHaveBeenCalledWith('destination/.github')
110+
})
49111
})
50112

51113
describe('promptAndCreateAIFile()', () => {

packages/theme/src/cli/services/init.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {renderSelectPrompt, renderTasks} from '@shopify/cli-kit/node/ui'
22
import {downloadGitRepository, removeGitRemote} from '@shopify/cli-kit/node/git'
33
import {joinPath} from '@shopify/cli-kit/node/path'
4-
import {mkdir, writeFile} from '@shopify/cli-kit/node/fs'
4+
import {mkdir, writeFile, rmdir, fileExists} from '@shopify/cli-kit/node/fs'
55
import {fetch} from '@shopify/cli-kit/node/http'
66

77
export async function cloneRepo(repoUrl: string, destination: string) {
@@ -24,11 +24,20 @@ async function downloadRepository(repoUrl: string, destination: string, latestTa
2424
shallow: true,
2525
})
2626
await removeGitRemote(destination)
27+
await removeSkeletonGitHubFolder(destination)
2728
},
2829
},
2930
])
3031
}
3132

33+
async function removeSkeletonGitHubFolder(destination: string) {
34+
const githubDir = joinPath(destination, '.github')
35+
36+
if (await fileExists(githubDir)) {
37+
await rmdir(githubDir)
38+
}
39+
}
40+
3241
export async function promptAndCreateAIFile(destination: string) {
3342
const aiChoice = await renderSelectPrompt({
3443
message: 'Set up AI dev support?',

0 commit comments

Comments
 (0)