addons/vscode/buildForPublish.jsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318const fs = require('fs');
b69ab319const path = require('path');
b69ab3110const util = require('util');
b69ab3111const exec = util.promisify(require('child_process').exec);
b69ab3112
b69ab3113function deleteFolderRecursive(pathToDelete) {
b69ab3114 if (fs.existsSync(pathToDelete)) {
b69ab3115 fs.readdirSync(pathToDelete).forEach((file, index) => {
b69ab3116 const curPath = path.join(pathToDelete, file);
b69ab3117 if (fs.lstatSync(curPath).isDirectory()) {
b69ab3118 deleteFolderRecursive(curPath);
b69ab3119 } else {
b69ab3120 fs.unlinkSync(curPath);
b69ab3121 }
b69ab3122 });
b69ab3123 fs.rmdirSync(pathToDelete);
b69ab3124 }
b69ab3125}
b69ab3126
b69ab3127async function build() {
b69ab3128 try {
b69ab3129 console.log('Building Extension');
b69ab3130 let {stdout} = await exec('npm run build-extension');
b69ab3131 console.log(stdout);
b69ab3132
b69ab3133 console.log('Building Webview');
b69ab3134 let webViewOutput = await exec('npm run build-webview');
b69ab3135 console.log(webViewOutput.stdout);
b69ab3136 console.log('Build complete');
b69ab3137 } catch (err) {
b69ab3138 console.error(`exec error: ${err}`);
b69ab3139 }
b69ab3140}
b69ab3141
b69ab3142// Run production build for publishing to the vscode marketplace
b69ab3143
b69ab3144// We only want to publish open source builds, not internal ones.
b69ab3145// Fail if we see facebook-only files in the repo.
b69ab3146const internalPath = './facebook/README.facebook.md';
b69ab3147if (fs.existsSync(internalPath)) {
b69ab3148 console.error(
b69ab3149 `${internalPath} exists. Make sure you only publish the vscode extension from the external repo.`,
b69ab3150 );
b69ab3151 process.exit(1);
b69ab3152}
b69ab3153
b69ab3154process.env.NODE_ENV = 'production';
b69ab3155console.log('Cleaning dist');
b69ab3156deleteFolderRecursive('./dist');
b69ab3157build();