mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 12:57:47 +00:00
* Imlement `now-client` deployments in Now CLI * Move now-client to dev dependencies * Fix missing config for legacy deployments * Restore no files warning * Improve error handling * Port over `--prod` * Handle single files and warnings better * Fix legacy deployment env config * Handle build errors in events * Don't use ncc for now-client * Extract `for...await` logic into a `.ts` file * Revert "Don't use ncc for now-client" This reverts commit e481a04058952f7011bf5523445256f1b8882dda. * Add `typings` field to `now-client` * Regenerate yarn.lock * Add bootstrap step to CircleCI * Add bootstrap step before build * Revert "Add bootstrap step before build" This reverts commit db9e1113937f113cca8c7c05d5c800fd5d61e84b. * Revert "Add bootstrap step to CircleCI" This reverts commit 02c0006a073614814fd174ccbaf1e4e0d8dd3dbf. * Build `now-client` before CLI * Sort build scripts * Tweak empty deployment detection * Add bootstrap step before build * Remove now-client dependency from now-client * Use local dependencies * Fix paths and regenerate lockfile * Bypass broken linting rule * Remove lint ignore * Use `tsc` instead of `ncc` for `now-client` Co-Authored-By: Steven <steven@ceriously.com> * Fix output path for tsc build * [test] Supress TS warning * Update packages/now-cli/src/commands/deploy/latest.js Co-Authored-By: Steven <steven@ceriously.com> * Update packages/now-cli/src/commands/deploy/latest.js Co-Authored-By: Steven <steven@ceriously.com> * Update packages/now-client/package.json Co-Authored-By: Steven <steven@ceriously.com> * Change `now-client` output to `dist` * Implement file events in now-client and bring back progressbar * Update build script sorting * Add new logic tests for `now-client` * Remove redundant target check * Remove now-client dependency and use local code * Set exact dependency versions * Revert "Set exact dependency versions" This reverts commit e0a31eaf10e498271c9253439d4bbd650738c694. * Revert local now-client import * Revert `now-client` dependency to local path * Implement feedback * Fix formatting * Only handle alias errors if `readyState` is `READY` * Update packages/now-cli/src/commands/deploy/latest.js Co-Authored-By: Andy <AndyBitz@users.noreply.github.com> * Update packages/now-cli/src/commands/deploy/latest.js Co-Authored-By: Andy <AndyBitz@users.noreply.github.com>
113 lines
2.9 KiB
JavaScript
113 lines
2.9 KiB
JavaScript
const { execSync, spawn } = require('child_process');
|
|
const { join, relative } = require('path');
|
|
const { readdirSync } = require('fs');
|
|
|
|
async function main() {
|
|
const script = process.argv[2];
|
|
const all = process.argv[3];
|
|
let matches = [];
|
|
|
|
if (!script) {
|
|
console.error('Please provide at least one argument');
|
|
process.exit(2);
|
|
}
|
|
|
|
if (all === 'all') {
|
|
matches = readdirSync(join(__dirname, 'packages'));
|
|
console.log(`Running script "${script}" for all packages`);
|
|
} else {
|
|
const branch = execSync('git branch | grep "*" | cut -d " " -f2')
|
|
.toString()
|
|
.trim();
|
|
|
|
const gitPath = branch === 'master' ? 'HEAD~1' : 'origin/canary...HEAD';
|
|
const diff = execSync(`git diff ${gitPath} --name-only`).toString();
|
|
|
|
const changed = diff
|
|
.split('\n')
|
|
.filter(item => Boolean(item) && item.includes('packages/'))
|
|
.map(item => relative('packages', item).split('/')[0]);
|
|
|
|
matches = Array.from(new Set(changed));
|
|
|
|
if (matches.length === 0) {
|
|
matches.push('now-cli');
|
|
matches.push('now-node');
|
|
console.log('No packages changed. Using default packages.');
|
|
}
|
|
|
|
console.log(
|
|
`Running "${script}" on branch "${branch}" with the following packages:`
|
|
);
|
|
}
|
|
|
|
// Sort the matches such that `utils` modules are compiled first,
|
|
// because other packages may rely on them
|
|
// We also need to ensure that `now-client` is built before the CLI
|
|
|
|
matches.sort((a, b) => {
|
|
if (a.endsWith('-utils') && !b.endsWith('-utils')) {
|
|
return -1;
|
|
}
|
|
if (b.endsWith('-utils') && !a.endsWith('-utils')) {
|
|
return 1;
|
|
}
|
|
if (a === 'now-cli' && b !== 'now-cli') {
|
|
return 1;
|
|
}
|
|
if (b === 'now-cli' && a !== 'now-cli') {
|
|
return -1;
|
|
}
|
|
return b - a;
|
|
});
|
|
|
|
console.log(matches.join('\n') + '\n');
|
|
|
|
for (const pkgName of matches) {
|
|
await runScript(pkgName, script);
|
|
}
|
|
}
|
|
|
|
function runScript(pkgName, script) {
|
|
return new Promise((resolve, reject) => {
|
|
const cwd = join(__dirname, 'packages', pkgName);
|
|
let pkgJson = null;
|
|
try {
|
|
pkgJson = require(join(cwd, 'package.json'));
|
|
} catch (e) {
|
|
pkgJson = null;
|
|
}
|
|
if (pkgJson && pkgJson.scripts && pkgJson.scripts[script]) {
|
|
console.log(`\n[${pkgName}] Running yarn ${script}`);
|
|
const child = spawn('yarn', [script], { cwd, stdio: 'inherit' });
|
|
child.on('error', reject);
|
|
child.on('close', (code, signal) => {
|
|
if (code === 0) {
|
|
return resolve();
|
|
}
|
|
reject(
|
|
new Error(
|
|
`[${pkgName}] Exited script "${script}" with code ${code ||
|
|
signal}.`
|
|
)
|
|
);
|
|
});
|
|
} else {
|
|
console.log(
|
|
`[${pkgName}] Skipping since script "${script}" is missing from package.json`
|
|
);
|
|
resolve();
|
|
}
|
|
});
|
|
}
|
|
|
|
main()
|
|
.then(() => {
|
|
console.log('Success!');
|
|
process.exit(0);
|
|
})
|
|
.catch(e => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|