-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix executable linking on windows for real
- Loading branch information
Showing
9 changed files
with
138 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { execSync } = require('child_process') | ||
|
||
// env detection | ||
exports.hasYarn = (() => { | ||
if (process.env.VUE_CLI_TEST) { | ||
return true | ||
} | ||
try { | ||
execSync('yarnpkg --version', { stdio: 'ignore' }) | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
})() | ||
|
||
exports.hasGit = () => { | ||
if (process.env.VUE_CLI_TEST) { | ||
return true | ||
} | ||
try { | ||
execSync('git --version', { stdio: 'ignore' }) | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,4 @@ | ||
const joi = require('joi') | ||
const chalk = require('chalk') | ||
const spinner = require('./spinner') | ||
const readline = require('readline') | ||
const { execSync } = require('child_process') | ||
const padStart = require('string.prototype.padstart') | ||
|
||
const format = (label, msg) => { | ||
return msg.split('\n').map((line, i) => { | ||
return i === 0 | ||
? `${label} ${line}` | ||
: padStart(line, chalk.reset(label).length) | ||
}).join('\n') | ||
} | ||
|
||
Object.assign(exports, spinner) | ||
|
||
exports.log = msg => console.log(msg || '') | ||
|
||
exports.info = msg => { | ||
console.log(format(chalk.bgBlue.black(' INFO '), msg)) | ||
} | ||
|
||
exports.done = msg => { | ||
console.log(format(chalk.bgGreen.black(' DONE '), msg)) | ||
} | ||
|
||
exports.warn = msg => { | ||
console.warn(format(chalk.bgYellow.black(' WARN '), chalk.yellow(msg))) | ||
} | ||
|
||
exports.error = msg => { | ||
console.error(format(chalk.bgRed(' ERROR '), chalk.red(msg))) | ||
if (msg instanceof Error) { | ||
console.error(msg.stack) | ||
} | ||
} | ||
|
||
exports.clearConsole = title => { | ||
if (process.stdout.isTTY) { | ||
const blank = '\n'.repeat(process.stdout.rows) | ||
console.log(blank) | ||
readline.cursorTo(process.stdout, 0, 0) | ||
readline.clearScreenDown(process.stdout) | ||
if (title) { | ||
console.log(title) | ||
} | ||
} | ||
} | ||
|
||
// silent all logs except errors during tests and keep record | ||
if (process.env.VUE_CLI_TEST) { | ||
const logs = {} | ||
Object.keys(exports).forEach(key => { | ||
if (key !== 'error') { | ||
exports[key] = (...args) => { | ||
if (!logs[key]) logs[key] = [] | ||
logs[key].push(args) | ||
} | ||
} | ||
}) | ||
exports.logs = logs | ||
} | ||
|
||
// proxy to joi for option validation | ||
exports.createSchema = fn => fn(joi) | ||
|
||
exports.validate = (obj, schema, options = {}) => { | ||
joi.validate(obj, schema, options, err => { | ||
if (err) { | ||
throw err | ||
} | ||
}) | ||
} | ||
|
||
// env detection | ||
exports.hasYarn = (() => { | ||
if (process.env.VUE_CLI_TEST) { | ||
return true | ||
} | ||
try { | ||
execSync('yarnpkg --version', { stdio: 'ignore' }) | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
})() | ||
|
||
exports.hasGit = () => { | ||
if (process.env.VUE_CLI_TEST) { | ||
return true | ||
} | ||
try { | ||
execSync('git --version', { stdio: 'ignore' }) | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
} | ||
Object.assign(exports, require('./env')) | ||
Object.assign(exports, require('./logger')) | ||
Object.assign(exports, require('./validate')) | ||
Object.assign(exports, require('./linkBin')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable vue-libs/no-async-functions */ | ||
|
||
// cross-platform executable link, mostly for Windows | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const { promisify } = require('util') | ||
|
||
const chmod = promisify(fs.chmod) | ||
const symlink = promisify(fs.symlink) | ||
const mkdirp = promisify(require('mkdirp')) | ||
const cmdShim = promisify(require('cmd-shim')) | ||
|
||
exports.linkBin = async (src, dest) => { | ||
if (!process.env.VUE_CLI_TEST && !process.env.VUE_CLI_DEBUG) { | ||
throw new Error(`linkBin should only be used during tests or debugging.`) | ||
} | ||
if (process.platform === 'win32') { | ||
// not doing mutex lock because this is only used in dev and the | ||
// src will not be modified | ||
await cmdShim(src, dest) | ||
} else { | ||
await mkdirp(path.dirname(dest)) | ||
await symlink(src, dest) | ||
await chmod(dest, '755') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const chalk = require('chalk') | ||
const spinner = require('./spinner') | ||
const readline = require('readline') | ||
const padStart = require('string.prototype.padstart') | ||
|
||
Object.assign(exports, spinner) | ||
|
||
const format = (label, msg) => { | ||
return msg.split('\n').map((line, i) => { | ||
return i === 0 | ||
? `${label} ${line}` | ||
: padStart(line, chalk.reset(label).length) | ||
}).join('\n') | ||
} | ||
|
||
exports.log = msg => console.log(msg || '') | ||
|
||
exports.info = msg => { | ||
console.log(format(chalk.bgBlue.black(' INFO '), msg)) | ||
} | ||
|
||
exports.done = msg => { | ||
console.log(format(chalk.bgGreen.black(' DONE '), msg)) | ||
} | ||
|
||
exports.warn = msg => { | ||
console.warn(format(chalk.bgYellow.black(' WARN '), chalk.yellow(msg))) | ||
} | ||
|
||
exports.error = msg => { | ||
console.error(format(chalk.bgRed(' ERROR '), chalk.red(msg))) | ||
if (msg instanceof Error) { | ||
console.error(msg.stack) | ||
} | ||
} | ||
|
||
exports.clearConsole = title => { | ||
if (process.stdout.isTTY) { | ||
const blank = '\n'.repeat(process.stdout.rows) | ||
console.log(blank) | ||
readline.cursorTo(process.stdout, 0, 0) | ||
readline.clearScreenDown(process.stdout) | ||
if (title) { | ||
console.log(title) | ||
} | ||
} | ||
} | ||
|
||
// silent all logs except errors during tests and keep record | ||
if (process.env.VUE_CLI_TEST) { | ||
const logs = {} | ||
Object.keys(exports).forEach(key => { | ||
if (key !== 'error') { | ||
exports[key] = (...args) => { | ||
if (!logs[key]) logs[key] = [] | ||
logs[key].push(args) | ||
} | ||
} | ||
}) | ||
exports.logs = logs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const joi = require('joi') | ||
|
||
// proxy to joi for option validation | ||
exports.createSchema = fn => fn(joi) | ||
|
||
exports.validate = (obj, schema, options = {}) => { | ||
joi.validate(obj, schema, options, err => { | ||
if (err) { | ||
throw err | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters