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
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const rootPath = path.resolve(__dirname, '..');
|
|
|
|
const gniPath = path.resolve(__dirname, '../filenames.auto.gni');
|
2019-02-06 18:27:20 +00:00
|
|
|
|
|
|
|
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-03-20 20:28:31 +00:00
|
|
|
);
|
2019-02-06 18:27:20 +00:00
|
|
|
|
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-03-20 20:28:31 +00:00
|
|
|
];
|
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 => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-'));
|
2019-04-03 00:12:10 +00:00
|
|
|
const child = cp.spawn('node', [
|
2019-06-02 20:03:03 +00:00
|
|
|
'build/webpack/get-outputs.js',
|
|
|
|
`./${webpackTarget.config}`,
|
|
|
|
path.resolve(tmpDir, `${webpackTarget.name}.measure.js`)
|
2019-04-03 00:12:10 +00:00
|
|
|
], {
|
|
|
|
cwd: path.resolve(__dirname, '..')
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
let output = '';
|
2019-04-03 00:12:10 +00:00
|
|
|
child.stdout.on('data', chunk => {
|
2020-03-20 20:28:31 +00:00
|
|
|
output += chunk.toString();
|
|
|
|
});
|
|
|
|
child.stderr.on('data', chunk => console.error(chunk.toString()));
|
2019-04-03 00:12:10 +00:00
|
|
|
await new Promise((resolve, reject) => child.on('exit', (code) => {
|
2019-05-06 15:29:01 +00:00
|
|
|
if (code !== 0) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.error(output);
|
|
|
|
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
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
resolve();
|
|
|
|
}));
|
2019-04-03 00:12:10 +00:00
|
|
|
|
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()
|
|
|
|
};
|
2020-03-20 20:28:31 +00:00
|
|
|
await fs.remove(tmpDir);
|
2020-08-07 20:48:46 +00:00
|
|
|
return webpackTargetWithDeps;
|
2020-03-20 20:28:31 +00:00
|
|
|
}));
|
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-03-20 20:28:31 +00:00
|
|
|
`);
|
|
|
|
};
|
2019-04-03 00:12:10 +00:00
|
|
|
|
|
|
|
if (process.mainModule === module) {
|
|
|
|
main().catch((err) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2019-02-06 18:27:20 +00:00
|
|
|
}
|