2021-04-23 05:16:53 +03:00
|
|
|
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
const { readFileSync, readdirSync, writeFileSync, copyFileSync } = require('fs')
|
|
|
|
const { copySync } = require('fs-extra')
|
|
|
|
|
|
|
|
/**
|
|
|
|
* append our api modules to `exports` in `package.json` then write it to `./dist`
|
|
|
|
*/
|
|
|
|
const pkg = JSON.parse(readFileSync('package.json', 'utf8'))
|
|
|
|
const modules = readdirSync('src').map((mod) => mod.replace('.ts', ''))
|
|
|
|
if (!pkg.exports) {
|
|
|
|
pkg.exports = {}
|
|
|
|
}
|
|
|
|
|
2021-04-24 15:43:29 +03:00
|
|
|
const outputPkg = {
|
|
|
|
...pkg,
|
|
|
|
exports: Object.assign(
|
|
|
|
{},
|
|
|
|
...modules.map((mod) => {
|
|
|
|
let temp = {}
|
|
|
|
let key = `./${mod}`
|
|
|
|
if (mod === 'index') {
|
|
|
|
key = '.'
|
|
|
|
}
|
|
|
|
|
|
|
|
temp[key] = {
|
|
|
|
import: `./${mod}.js`,
|
|
|
|
require: `./${mod}.cjs`
|
|
|
|
}
|
|
|
|
return temp
|
|
|
|
}),
|
|
|
|
// if for some reason in the future we manually add something in the `exports` field
|
|
|
|
// this will ensure it doesn't get overwritten by the logic above
|
|
|
|
{ ...pkg.exports }
|
|
|
|
)
|
|
|
|
}
|
2021-04-23 05:16:53 +03:00
|
|
|
writeFileSync('dist/package.json', JSON.stringify(outputPkg, undefined, 2))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* copy necessary files like `CHANGELOG.md` and Licenses to `./dist`
|
|
|
|
*/
|
|
|
|
const files = readdirSync('.').filter(
|
2021-05-11 02:28:15 +03:00
|
|
|
(f) => f.startsWith('LICENSE')
|
2021-04-23 05:16:53 +03:00
|
|
|
)
|
|
|
|
files.forEach((f) => copyFileSync(f, `dist/${f}`))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* copy typescript src files to `./dist`
|
|
|
|
*/
|
|
|
|
copySync('src', 'dist')
|