Skip to content

Commit

Permalink
feat: support including 'extraFiles' in the built pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Feb 5, 2023
1 parent c8864cd commit b130f57
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ await fs.copy('companion', 'pkg/companion')
const srcPackageJson = JSON.parse(await fs.readFile(path.resolve('./package.json')))
const frameworkPackageJson = JSON.parse(await fs.readFile(path.join(frameworkDir, 'package.json')))

// Copy the manifest, overriding some properties
const manifestJson = JSON.parse(await fs.readFile(path.resolve('./companion/manifest.json')))
manifestJson.runtime.entrypoint = '../main.js'
manifestJson.version = srcPackageJson.version
Expand Down Expand Up @@ -69,6 +70,8 @@ const packageJson = {
const webpackExtPath = path.resolve('build-config.cjs')
if (fs.existsSync(webpackExtPath)) {
const webpackExt = require(webpackExtPath)

// Add any external dependencies, with versions matching what is currntly installed
if (webpackExt.externals) {
const extArray = Array.isArray(webpackExt.externals) ? webpackExt.externals : [webpackExt.externals]
for (const extGroup of extArray) {
Expand All @@ -84,6 +87,7 @@ if (fs.existsSync(webpackExtPath)) {
}
}

// Copy across any prebuilds that can be loaded corectly
if (webpackExt.prebuilds) {
await fs.mkdir('pkg/prebuilds')

Expand All @@ -95,22 +99,31 @@ if (fs.existsSync(webpackExtPath)) {
}
}
}

// copy extra files
if (Array.isArray(webpackExt.extraFiles)) {
const files = await globby(webpackExt.extraFiles)
for (const file of files) {
await fs.copy(file, path.join('pkg', file), {
recursive: true,
overwrite: false,
})
}
}
}

// Write the package.json
// packageJson.bundleDependencies = Object.keys(packageJson.dependencies)
await fs.writeFile('pkg/package.json', JSON.stringify(packageJson))

// If we found any depenendencies for the pkg, install them
if (Object.keys(packageJson.dependencies).length) {
await $`yarn --cwd pkg`
await $`yarn --cwd pkg install`
}

// Create tgz of the build
// await $`yarn --cwd pkg pack --filename pkg/package.tgz`

await tar
.c(
// or tar.create
.create(
{
gzip: true,
},
Expand Down

0 comments on commit b130f57

Please sign in to comment.