mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(utils): add a script for watching various builds (#3545)
Watches our main typescript compilation, webpacks, type generation, and rpc channel generation.
This commit is contained in:
parent
86815d70e0
commit
0d03cc0f9a
@ -22,7 +22,7 @@
|
||||
"clean": "rimraf lib && rimraf types",
|
||||
"prepare": "node install-from-github.js",
|
||||
"build": "node utils/runWebpack.js --mode='development' && tsc -p . && npm run generate-types",
|
||||
"watch": "node utils/runWebpack.js --mode='development' --watch --silent | tsc -w -p .",
|
||||
"watch": "node utils/watch.js",
|
||||
"test-types": "npm run generate-types && npx -p typescript@3.7.5 tsc -p utils/generate_types/test/tsconfig.json && npm run typecheck-tests",
|
||||
"generate-types": "node utils/generate_types/",
|
||||
"generate-channels": "node utils/generate_channels.js",
|
||||
|
||||
49
utils/watch.js
Normal file
49
utils/watch.js
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const child_process = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const spawns = [
|
||||
child_process.spawn('node', [path.join(__dirname, 'runWebpack.js'), '--mode="development"', '--watch', '--silent'], { stdio: 'inherit', shell: true }),
|
||||
child_process.spawn('npx', ['tsc', '-w', '--preserveWatchOutput', '-p', path.join(__dirname, '..')], { stdio: 'inherit', shell: true }),
|
||||
];
|
||||
process.on('exit', () => spawns.forEach(s => s.kill()));
|
||||
|
||||
runOnChanges(['src/rpc/protocol.yml'], 'utils/generate_channels.js');
|
||||
runOnChanges(['docs/api.md', 'utils/generate_types/overrides.d.ts', 'utils/generate_types/exported.json'], 'utils/generate_types/index.js');
|
||||
|
||||
/**
|
||||
* @param {string[][]} paths
|
||||
* @param {string} nodeFile
|
||||
*/
|
||||
function runOnChanges(paths, nodeFile) {
|
||||
for (const p of [...paths, nodeFile]) {
|
||||
const filePath = path.join(__dirname, '..', ...p.split('/'));
|
||||
if (!fs.existsSync(filePath)) {
|
||||
console.error('could not find file', filePath);
|
||||
process.exit(1);
|
||||
}
|
||||
fs.watchFile(filePath, callback);
|
||||
}
|
||||
|
||||
callback();
|
||||
|
||||
function callback() {
|
||||
child_process.spawnSync('node', [path.join(__dirname, '..', ...nodeFile.split('/'))]);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user