fix(unified-desktop-gui branch): initial installation on windows (#18247)

This commit is contained in:
userquin
2021-09-25 20:18:17 +02:00
committed by GitHub
parent cf05740557
commit 8614e97802
35 changed files with 182 additions and 64 deletions

View File

@@ -46,7 +46,13 @@ export async function spawned (
spawningApps.add(prefix)
const [executable, ...rest] = command.split(' ')
const cp = spawn(executable, rest, {
let useExecutable = executable
if (process.platform === 'win32' && !useExecutable.endsWith('.cmd')) {
useExecutable = `${executable}.cmd`
}
const cp = spawn(useExecutable, rest, {
stdio: 'pipe',
env: {
FORCE_COLOR: '1',
@@ -91,12 +97,38 @@ export async function spawned (
return new Promise((resolve, reject) => {
if (waitForExit) {
cp.once('exit', () => {
resolve(cp)
if (process.platform === 'win32') {
cp.on('exit', (code, signal) => {
console.log(`Exit code: ${code} => ${signal}`)
resolve(cp)
})
} else {
cp.once('exit', (code, signal) => {
console.log(`Exit code: ${code} => ${signal}`)
resolve(cp)
})
}
cp.once('error', (e) => {
console.log(`error executing ${command}`, e)
reject(e)
})
} else {
if (process.platform === 'win32') {
cp.on('exit', (code, signal) => {
console.log(`Exit code: ${code} => ${signal}`)
})
} else {
cp.once('exit', (code, signal) => {
console.log(`Exit code: ${code} => ${signal}`)
})
}
cp.once('error', (e) => {
console.log(`error executing ${command}`, e)
reject(e)
})
cp.once('error', reject)
} else {
cp.stdout?.once('data', () => {
spawningApps.delete(prefix)
resolve(cp)

View File

@@ -22,16 +22,38 @@ function prefixTypegen (s: string) {
return `${chalk.cyan('nexusTypegen')}: ${s}`
}
async function windowsTouch (filename: string, time: Date) {
// `fs.utimesSync` is used here to prevent existing file contents from being overwritten.
// It also updates the last modification timestamp of the file, which is consistent with what POSIX touch does.
try {
fs.utimesSync(filename, time, time)
} catch (e) {
fs.closeSync(fs.openSync(filename, 'w'))
}
}
export async function nexusTypegen (cfg: NexusTypegenCfg) {
const dfd = pDefer()
if (cfg.outputPath) {
await fs.ensureDir(path.join(monorepoPaths.pkgGraphql, 'src/gen'))
execSync(`touch ${path.join(monorepoPaths.pkgGraphql, 'src/gen/cloud-source-types.gen.ts')}`)
execSync(`touch ${cfg.outputPath}`)
const pkgGraphql = path.join(monorepoPaths.pkgGraphql, 'src/gen/cloud-source-types.gen.ts')
// on windows there is no `touch` equivalent command
if (process.platform === 'win32') {
const time = new Date()
await windowsTouch(pkgGraphql, time)
await windowsTouch(cfg.outputPath, time)
} else {
execSync(`touch ${pkgGraphql}`)
execSync(`touch ${cfg.outputPath}`)
}
}
const out = spawn('node', ['-r', '@packages/ts/register', cfg.filePath], {
const nodeCmd = `node${process.platform === 'win32' ? '.cmd' : ''}`
const out = spawn(nodeCmd, ['-r', '@packages/ts/register', cfg.filePath], {
cwd: cfg.cwd,
env: {
...process.env,