| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | const fs = require('fs'); |
| b69ab31 | | | 9 | const path = require('path'); |
| b69ab31 | | | 10 | const util = require('util'); |
| b69ab31 | | | 11 | const exec = util.promisify(require('child_process').exec); |
| b69ab31 | | | 12 | |
| b69ab31 | | | 13 | function deleteFolderRecursive(pathToDelete) { |
| b69ab31 | | | 14 | if (fs.existsSync(pathToDelete)) { |
| b69ab31 | | | 15 | fs.readdirSync(pathToDelete).forEach((file, index) => { |
| b69ab31 | | | 16 | const curPath = path.join(pathToDelete, file); |
| b69ab31 | | | 17 | if (fs.lstatSync(curPath).isDirectory()) { |
| b69ab31 | | | 18 | deleteFolderRecursive(curPath); |
| b69ab31 | | | 19 | } else { |
| b69ab31 | | | 20 | fs.unlinkSync(curPath); |
| b69ab31 | | | 21 | } |
| b69ab31 | | | 22 | }); |
| b69ab31 | | | 23 | fs.rmdirSync(pathToDelete); |
| b69ab31 | | | 24 | } |
| b69ab31 | | | 25 | } |
| b69ab31 | | | 26 | |
| b69ab31 | | | 27 | async function build() { |
| b69ab31 | | | 28 | try { |
| b69ab31 | | | 29 | console.log('Building Extension'); |
| b69ab31 | | | 30 | let {stdout} = await exec('npm run build-extension'); |
| b69ab31 | | | 31 | console.log(stdout); |
| b69ab31 | | | 32 | |
| b69ab31 | | | 33 | console.log('Building Webview'); |
| b69ab31 | | | 34 | let webViewOutput = await exec('npm run build-webview'); |
| b69ab31 | | | 35 | console.log(webViewOutput.stdout); |
| b69ab31 | | | 36 | console.log('Build complete'); |
| b69ab31 | | | 37 | } catch (err) { |
| b69ab31 | | | 38 | console.error(`exec error: ${err}`); |
| b69ab31 | | | 39 | } |
| b69ab31 | | | 40 | } |
| b69ab31 | | | 41 | |
| b69ab31 | | | 42 | // Run production build for publishing to the vscode marketplace |
| b69ab31 | | | 43 | |
| b69ab31 | | | 44 | // We only want to publish open source builds, not internal ones. |
| b69ab31 | | | 45 | // Fail if we see facebook-only files in the repo. |
| b69ab31 | | | 46 | const internalPath = './facebook/README.facebook.md'; |
| b69ab31 | | | 47 | if (fs.existsSync(internalPath)) { |
| b69ab31 | | | 48 | console.error( |
| b69ab31 | | | 49 | `${internalPath} exists. Make sure you only publish the vscode extension from the external repo.`, |
| b69ab31 | | | 50 | ); |
| b69ab31 | | | 51 | process.exit(1); |
| b69ab31 | | | 52 | } |
| b69ab31 | | | 53 | |
| b69ab31 | | | 54 | process.env.NODE_ENV = 'production'; |
| b69ab31 | | | 55 | console.log('Cleaning dist'); |
| b69ab31 | | | 56 | deleteFolderRecursive('./dist'); |
| b69ab31 | | | 57 | build(); |