Skip to content

Commit f79e385

Browse files
committed
workflow(dev): compatible with Windows
1 parent 50a9ad6 commit f79e385

File tree

1 file changed

+35
-40
lines changed

1 file changed

+35
-40
lines changed

scripts/dev.mts

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type { ASTNode } from 'magicast'
99
import { cyan } from 'kolorist'
1010
import { addVitePlugin } from 'magicast/helpers'
1111

12+
declare const process: NodeJS.Process
13+
1214
type VueVersion = '3' | '2.7' | '2.6'
1315

1416
const vueVersion: VueVersion[] = ['3', '2.7', '2.6']
@@ -54,12 +56,6 @@ async function dev() {
5456
return
5557
}
5658

57-
/* const { shouldUpgradeDependencies } = await prompts({
58-
type: 'confirm',
59-
name: 'shouldUpgradeDependencies',
60-
message: 'Upgrade dependencies',
61-
}) */
62-
6359
console.log(cyan('Fetching origin...'))
6460
spawn.sync('git', ['pull'], { stdio: 'inherit' })
6561

@@ -139,52 +135,51 @@ async function dev() {
139135
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2))
140136
console.log(cyan('Linting package.json...'))
141137
spawn.sync('npx', ['eslint', './package.json', '--fix'], { stdio: 'inherit' })
142-
// if (!shouldUpgradeDependencies) {
143138
await installDependencies()
144-
// }
145139
}
146140

147-
/* if (shouldUpgradeDependencies) {
148-
installDependencies()
149-
} */
150-
151141
spawn.sync('npx', ['vite', '--open'], { stdio: 'inherit' })
152142

153143
async function installDependencies() {
154144
console.log(cyan('Checking pnpm version...'))
155145
const latestPNPMVersion = spawn.sync('npm', ['view', 'pnpm', 'version']).stdout.toString().trim()
156146
const currentPNPMVersion = spawn.sync('pnpm', ['-v']).stdout.toString().trim()
157-
if (latestPNPMVersion !== currentPNPMVersion) {
147+
// Mac 自带 curl,Linux 不一定,Windows 不支持指定 pnpm 版本
148+
if (latestPNPMVersion !== currentPNPMVersion && ['darwin', 'linux'].includes(process.platform)) {
158149
console.log(cyan('Upgrading pnpm...'))
159-
console.log(execSync(`curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=${latestPNPMVersion} sh -`).toString())
160-
/* const curlProcess = spawn.sync('curl', ['-fsSL', 'https://get.pnpm.io/install.sh'], {
161-
env: { PNPM_VERSION: latestPNPMVersion },
162-
stdio: ['pipe', 'pipe', 'pipe'], // Redirect stdin, stdout, and stderr
163-
})
164-
if (curlProcess.status === 0) {
165-
// If curl was successful, execute the shell command
166-
const shCommand = 'sh'
167-
const shArgs = ['-']
168-
169-
const shProcess = spawn.sync(shCommand, shArgs, {
170-
input: curlProcess.stdout, // Pass the stdout of curl as input to sh
171-
stdio: ['pipe', 'inherit', 'inherit'], // Redirect stdin, inherit stdout and stderr
150+
try {
151+
console.log(execSync(`curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=${latestPNPMVersion} sh -`).toString())
152+
/* const curlProcess = spawn.sync('curl', ['-fsSL', 'https://get.pnpm.io/install.sh'], {
153+
env: { PNPM_VERSION: latestPNPMVersion },
154+
stdio: ['pipe', 'pipe', 'pipe'], // Redirect stdin, stdout, and stderr
172155
})
173-
174-
if (shProcess.status === 0) {
175-
console.log('pnpm installation successful.')
156+
if (curlProcess.status === 0) {
157+
// If curl was successful, execute the shell command
158+
const shCommand = 'sh'
159+
const shArgs = ['-']
160+
161+
const shProcess = spawn.sync(shCommand, shArgs, {
162+
input: curlProcess.stdout, // Pass the stdout of curl as input to sh
163+
stdio: ['pipe', 'inherit', 'inherit'], // Redirect stdin, inherit stdout and stderr
164+
})
165+
166+
if (shProcess.status === 0) {
167+
console.log('pnpm installation successful.')
168+
} else {
169+
console.error('pnpm installation failed.')
170+
}
176171
} else {
177-
console.error('pnpm installation failed.')
178-
}
179-
} else {
180-
console.error('curl command failed.')
181-
} */
182-
console.log(cyan('Setting registry...'))
183-
spawn.sync('pnpm', ['config', 'set', 'registry', 'https://registry.npmmirror.com'], { stdio: 'inherit' })
184-
console.log(cyan('Installing node lts...'))
185-
spawn.sync('pnpm', ['env', 'use', '-g', 'lts'], { stdio: 'inherit' })
186-
console.log(cyan('Installing global packages...'))
187-
spawn.sync('pnpm', ['add', 'cnpm', '@antfu/ni', 'only-allow', '-g'], { stdio: 'inherit' })
172+
console.error('curl command failed.')
173+
} */
174+
console.log(cyan('Setting registry...'))
175+
spawn.sync('pnpm', ['config', 'set', 'registry', 'https://registry.npmmirror.com'], { stdio: 'inherit' })
176+
console.log(cyan('Installing node lts...'))
177+
spawn.sync('pnpm', ['env', 'use', '-g', 'lts'], { stdio: 'inherit' })
178+
console.log(cyan('Installing global packages...'))
179+
spawn.sync('pnpm', ['add', 'cnpm', '@antfu/ni', 'only-allow', '-g'], { stdio: 'inherit' })
180+
} catch (e) {
181+
182+
}
188183
}
189184
console.log(cyan('Upgrading dependencies...'))
190185
spawn.sync('pnpm', ['up'], { stdio: 'inherit' })

0 commit comments

Comments
 (0)