2020-08-07 20:48:46 +00:00
|
|
|
import * as cp from 'child_process';
|
|
|
|
import * as fs from 'fs-extra';
|
|
|
|
import * as os from 'os';
|
|
|
|
import * as path from 'path';
|
2019-02-06 18:27:20 +00:00
|
|
|
|
2019-04-03 00:12:10 +00:00
|
|
|
const rootPath = path.resolve(__dirname, '..');
|
2019-02-06 18:27:20 +00:00
|
|
|
const gniPath = path.resolve(__dirname, '../filenames.auto.gni');
|
|
|
|
|
|
|
|
const allDocs = fs.readdirSync(path.resolve(__dirname, '../docs/api'))
|
|
|
|
.map(doc => `docs/api/${doc}`)
|
|
|
|
.concat(
|
|
|
|
fs.readdirSync(path.resolve(__dirname, '../docs/api/structures'))
|
|
|
|
.map(doc => `docs/api/structures/${doc}`)
|
|
|
|
);
|
|
|
|
|
2020-05-30 09:56:54 +00:00
|
|
|
const typingFiles = fs.readdirSync(path.resolve(__dirname, '../typings')).map(child => `typings/${child}`);
|
|
|
|
|
2019-04-03 00:12:10 +00:00
|
|
|
const main = async () => {
|
2019-06-02 20:03:03 +00:00
|
|
|
const webpackTargets = [
|
2019-04-03 00:12:10 +00:00
|
|
|
{
|
2019-06-02 20:03:03 +00:00
|
|
|
name: 'sandbox_bundle_deps',
|
|
|
|
config: 'webpack.config.sandboxed_renderer.js'
|
2019-04-03 00:12:10 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-02 20:03:03 +00:00
|
|
|
name: 'isolated_bundle_deps',
|
|
|
|
config: 'webpack.config.isolated_renderer.js'
|
2019-04-03 00:12:10 +00:00
|
|
|
},
|
2019-06-02 20:03:03 +00:00
|
|
|
{
|
|
|
|
name: 'browser_bundle_deps',
|
|
|
|
config: 'webpack.config.browser.js'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'renderer_bundle_deps',
|
|
|
|
config: 'webpack.config.renderer.js'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'worker_bundle_deps',
|
|
|
|
config: 'webpack.config.worker.js'
|
2020-07-16 18:38:31 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'asar_bundle_deps',
|
|
|
|
config: 'webpack.config.asar.js'
|
2019-04-03 00:12:10 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2020-08-07 20:48:46 +00:00
|
|
|
const webpackTargetsWithDeps = await Promise.all(webpackTargets.map(async webpackTarget => {
|
2019-04-03 00:12:10 +00:00
|
|
|
const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-'));
|
|
|
|
const child = cp.spawn('node', [
|
2020-10-20 19:10:15 +00:00
|
|
|
'./node_modules/webpack-cli/bin/cli.js',
|
|
|
|
'--config', `./build/webpack/${webpackTarget.config}`,
|
|
|
|
'--display', 'errors-only',
|
|
|
|
`--output-path=${tmpDir}`,
|
|
|
|
`--output-filename=${webpackTarget.name}.measure.js`,
|
|
|
|
'--env.PRINT_WEBPACK_GRAPH'
|
2019-04-03 00:12:10 +00:00
|
|
|
], {
|
|
|
|
cwd: path.resolve(__dirname, '..')
|
|
|
|
});
|
|
|
|
let output = '';
|
|
|
|
child.stdout.on('data', chunk => {
|
|
|
|
output += chunk.toString();
|
|
|
|
});
|
2019-05-06 15:29:01 +00:00
|
|
|
child.stderr.on('data', chunk => console.error(chunk.toString()));
|
2021-01-22 19:25:47 +00:00
|
|
|
await new Promise<void>((resolve, reject) => child.on('exit', (code) => {
|
2019-05-06 15:29:01 +00:00
|
|
|
if (code !== 0) {
|
|
|
|
console.error(output);
|
2019-06-02 20:03:03 +00:00
|
|
|
return reject(new Error(`Failed to list webpack dependencies for entry: ${webpackTarget.name}`));
|
2019-05-06 15:29:01 +00:00
|
|
|
}
|
2019-04-03 00:12:10 +00:00
|
|
|
|
|
|
|
resolve();
|
|
|
|
}));
|
|
|
|
|
2020-08-07 20:48:46 +00:00
|
|
|
const webpackTargetWithDeps = {
|
|
|
|
...webpackTarget,
|
|
|
|
dependencies: (JSON.parse(output) as string[])
|
|
|
|
// Remove whitespace
|
|
|
|
.map(line => line.trim())
|
|
|
|
// Get the relative path
|
|
|
|
.map(line => path.relative(rootPath, line).replace(/\\/g, '/'))
|
|
|
|
// Only care about files in //electron
|
|
|
|
.filter(line => !line.startsWith('..'))
|
|
|
|
// Only care about our own files
|
|
|
|
.filter(line => !line.startsWith('node_modules'))
|
|
|
|
// All webpack builds depend on the tsconfig and package json files
|
|
|
|
.concat(['tsconfig.json', 'tsconfig.electron.json', 'package.json', ...typingFiles])
|
|
|
|
// Make the generated list easier to read
|
|
|
|
.sort()
|
|
|
|
};
|
2019-04-03 00:12:10 +00:00
|
|
|
await fs.remove(tmpDir);
|
2020-08-07 20:48:46 +00:00
|
|
|
return webpackTargetWithDeps;
|
2019-04-03 00:12:10 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
gniPath,
|
|
|
|
`# THIS FILE IS AUTO-GENERATED, PLEASE DO NOT EDIT BY HAND
|
2019-02-06 18:27:20 +00:00
|
|
|
auto_filenames = {
|
|
|
|
api_docs = [
|
|
|
|
${allDocs.map(doc => ` "${doc}",`).join('\n')}
|
|
|
|
]
|
2019-04-03 00:12:10 +00:00
|
|
|
|
2020-08-07 20:48:46 +00:00
|
|
|
${webpackTargetsWithDeps.map(target => ` ${target.name} = [
|
2019-04-03 00:12:10 +00:00
|
|
|
${target.dependencies.map(dep => ` "${dep}",`).join('\n')}
|
|
|
|
]`).join('\n\n')}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
};
|
|
|
|
|
2020-09-17 22:08:57 +00:00
|
|
|
if (require.main === module) {
|
2019-04-03 00:12:10 +00:00
|
|
|
main().catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2019-02-06 18:27:20 +00:00
|
|
|
}
|