| 53 | }; |
| 54 | |
| 55 | const build = async (tempPath, manifestPath, envExtension = {}) => { |
| 56 | const binPath = join(tempPath, 'bin'); |
| 57 | const zipPath = join(tempPath, 'zip'); |
| 58 | const mergedEnv = {...process.env, ...envExtension}; |
| 59 | |
| 60 | const webpackPath = join(__dirname, 'node_modules', '.bin', 'webpack'); |
| 61 | execSync( |
| 62 | `${webpackPath} --config webpack.config.js --output-path ${binPath}`, |
| 63 | { |
| 64 | cwd: __dirname, |
| 65 | env: mergedEnv, |
| 66 | stdio: 'inherit', |
| 67 | }, |
| 68 | ); |
| 69 | |
| 70 | // Make temp dir |
| 71 | await ensureDir(zipPath); |
| 72 | |
| 73 | const copiedManifestPath = join(zipPath, 'manifest.json'); |
| 74 | |
| 75 | let webpackStatsFilePath = null; |
| 76 | // Copy unbuilt source files to zip dir to be packaged: |
| 77 | await copy(binPath, join(zipPath, 'build'), { |
| 78 | filter: filePath => { |
| 79 | if (basename(filePath).startsWith('webpack-stats.')) { |
| 80 | webpackStatsFilePath = filePath; |
| 81 | // The ZIP is the actual extension and doesn't need this metadata. |
| 82 | return false; |
| 83 | } |
| 84 | return true; |
| 85 | }, |
| 86 | }); |
| 87 | if (webpackStatsFilePath !== null) { |
| 88 | await copy( |
| 89 | webpackStatsFilePath, |
| 90 | join(tempPath, basename(webpackStatsFilePath)), |
| 91 | ); |
| 92 | webpackStatsFilePath = join(tempPath, basename(webpackStatsFilePath)); |
| 93 | } |
| 94 | await copy(manifestPath, copiedManifestPath); |
| 95 | await Promise.all( |
| 96 | STATIC_FILES.map(file => copy(join(__dirname, file), join(zipPath, file))), |
| 97 | ); |
| 98 | |
| 99 | const commit = getGitCommit(); |
| 100 | const dateString = new Date().toLocaleDateString(); |
| 101 | const manifest = JSON.parse(readFileSync(copiedManifestPath).toString()); |
| 102 | const versionDateString = `${manifest.version} (${dateString})`; |
| 103 | if (manifest.version_name) { |
| 104 | manifest.version_name = versionDateString; |
| 105 | } |
| 106 | manifest.description += `\n\nCreated from revision ${commit} on ${dateString}.`; |
| 107 | |
| 108 | if (process.env.NODE_ENV === 'development') { |
| 109 | // When building the local development version of the |
| 110 | // extension we want to be able to have a stable extension ID |
| 111 | // for the local build (in order to be able to reliably detect |
| 112 | // duplicate installations of DevTools). |