# Install the archiver
yarn install archiver --dev
# Run the shell
node build.cjs
Last active
December 13, 2022 11:41
-
-
Save HereOrCode/9d3f21ddc4b660416d4bbb850d9a871c to your computer and use it in GitHub Desktop.
Build Browser Extension Zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// build.cjs | |
#!/usr/bin/env node | |
const fs = require('fs') | |
const path = require('path') | |
// eslint-disable-next-line | |
var archiver = require('archiver') | |
const extPackageJson = require('../src/manifest.json') | |
const DEST_DIR = path.join(__dirname, '../dist') | |
const DEST_ZIP_DIR = path.join(__dirname, '../dist-zip') | |
const extractExtensionData = () => ({ | |
name: extPackageJson.name, | |
version: extPackageJson.version, | |
}) | |
const makeDestZipDirIfNotExists = () => { | |
if (!fs.existsSync(DEST_ZIP_DIR)) { | |
fs.mkdirSync(DEST_ZIP_DIR) | |
} | |
} | |
const buildZip = (src, dist, zipFilename) => { | |
console.info(`Building ${zipFilename}...`) | |
const output = fs.createWriteStream(path.join(dist, zipFilename)) | |
const archive = archiver('zip') | |
archive.pipe(output) | |
archive.directory(src, false) | |
archive.finalize() | |
} | |
const main = () => { | |
const { name, version } = extractExtensionData() | |
const zipFilename = `${name}-v${version}.zip` | |
makeDestZipDirIfNotExists() | |
buildZip(DEST_DIR, DEST_ZIP_DIR, zipFilename) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment