MCPcopy
hub / github.com/antfu/skills / initSubmodules

Function initSubmodules

scripts/cli.ts:73–176  ·  view source on GitHub ↗
(skipPrompt = false)

Source from the content-addressed store, hash-verified

71}
72
73async function initSubmodules(skipPrompt = false) {
74 const allProjects: Project[] = [
75 ...Object.entries(submodules).map(([name, url]) => ({
76 name,
77 url,
78 type: 'source' as const,
79 path: `sources/${name}`,
80 })),
81 ...Object.entries(vendors).map(([name, config]) => ({
82 name,
83 url: (config as VendorConfig).source,
84 type: 'vendor' as const,
85 path: `vendor/${name}`,
86 })),
87 ]
88
89 const spinner = p.spinner()
90
91 // Check for extra submodules that are not in meta.ts
92 const existingSubmodulePaths = getExistingSubmodulePaths()
93 const expectedPaths = new Set(allProjects.map(p => p.path))
94 const extraSubmodules = existingSubmodulePaths.filter(path => !expectedPaths.has(path))
95
96 if (extraSubmodules.length > 0) {
97 p.log.warn(`Found ${extraSubmodules.length} submodule(s) not in meta.ts:`)
98 for (const path of extraSubmodules) {
99 p.log.message(` - ${path}`)
100 }
101
102 const shouldRemove = skipPrompt
103 ? true
104 : await p.confirm({
105 message: 'Remove these extra submodules?',
106 initialValue: true,
107 })
108
109 if (p.isCancel(shouldRemove)) {
110 p.cancel('Cancelled')
111 return
112 }
113
114 if (shouldRemove) {
115 for (const submodulePath of extraSubmodules) {
116 spinner.start(`Removing submodule: ${submodulePath}`)
117 try {
118 removeSubmodule(submodulePath)
119 spinner.stop(`Removed: ${submodulePath}`)
120 }
121 catch (e) {
122 spinner.stop(`Failed to remove ${submodulePath}: ${e}`)
123 }
124 }
125 }
126 }
127
128 const existingProjects = allProjects.filter(p => submoduleExists(p.path))
129 const newProjects = allProjects.filter(p => !submoduleExists(p.path))
130

Callers 1

mainFunction · 0.85

Calls 4

removeSubmoduleFunction · 0.85
submoduleExistsFunction · 0.85
execFunction · 0.85

Tested by

no test coverage detected