-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
433d5c2
commit 454b097
Showing
7 changed files
with
153 additions
and
19 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const { spawn } = require('@tybys/cgen/bin/util/spawn.js') | ||
const ts = require('@tybys/tsgo/lib/ts.js') | ||
const { bundler } = require('@tybys/tsgo/lib/util.js') | ||
const { readConfigNoCache } = require('@tybys/tsgo/lib/config.js') | ||
|
||
const wasmoutdir = p('./wasm/.cgenbuild') | ||
|
||
function p (...args) { | ||
if (!args.length) return __dirname | ||
return path.isAbsolute(args[0]) ? path.join(...args) : path.join(__dirname, ...args) | ||
} | ||
|
||
function e (cmd) { | ||
return process.platform === 'win32' ? `${cmd}.cmd` : cmd | ||
} | ||
|
||
function mkdir (dir) { | ||
return fs.mkdirSync(dir, { recursive: true }) | ||
} | ||
|
||
function cp (s, t) { | ||
mkdir(path.dirname(t)) | ||
fs.copyFileSync(s, t) | ||
} | ||
|
||
async function invokeTSGO (command, config) { | ||
const r = await require(`@tybys/tsgo/command/${command}.js`).run(config) | ||
if (r !== 0) { | ||
throw new Error(`TSGO command failed: ${command}`) | ||
} | ||
} | ||
|
||
async function main () { | ||
const tsgoConfig = readConfigNoCache(p('./tsgo.config.js')) | ||
await invokeTSGO('lint', tsgoConfig) | ||
|
||
await spawn(e('npx'), ['cgen', 'rebuild', '-e'], path.join(__dirname, 'wasm')) | ||
fs.copyFileSync(p(wasmoutdir, 'wz.js'), p('./src/util/wz.js')) | ||
mkdir(p('./lib/cjs-modern/util')) | ||
mkdir(p('./lib/esm-modern/util')) | ||
mkdir(p('./lib/esm/util')) | ||
cp(p(wasmoutdir, 'wz.wasm'), p('./lib/cjs-modern/util/wz.wasm')) | ||
cp(p(wasmoutdir, 'wz.wasm'), p('./lib/esm-modern/util/wz.wasm')) | ||
ts.compile(p('tsconfig.json')) | ||
ts.compile(p('tsconfig.modern.json')) | ||
|
||
const asm = p('./src/util/wz.js') | ||
cp(p(wasmoutdir, 'wzasm.js'), asm) | ||
fs.writeFileSync(asm, fs.readFileSync(asm, 'utf8').replace('wzasm.js.mem', 'wz.js.mem').replace('wzasm.wasm', 'wz.wasm'), 'utf8') | ||
ts.compile(p('tsconfig.esm.json')) | ||
cp(p(wasmoutdir, 'wzasm.js.mem'), p('./lib/esm/util/wz.js.mem')) | ||
|
||
await bundler.webpack(tsgoConfig) | ||
await bundler.webpack(readConfigNoCache(p('./tsgo.es5.config.js'))) | ||
await invokeTSGO('dts', tsgoConfig) | ||
await invokeTSGO('doc', tsgoConfig) | ||
} | ||
|
||
main().catch(err => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const CopyWebpackPlugin = require('copy-webpack-plugin') | ||
const path = require('path') | ||
|
||
module.exports = { | ||
entry: 'lib/esm/index.js', | ||
output: { | ||
webpack: 'dist', | ||
name: 'wz.es5' | ||
}, | ||
bundler: ['webpack'], | ||
configureWebpack (config) { | ||
config.plugins = [ | ||
...config.plugins, | ||
new CopyWebpackPlugin({ | ||
patterns: [ | ||
{ from: path.join(path.dirname(config.entry[Object.keys(config.entry)[0]][0]), 'util/wz.js.mem'), to: path.join(config.output.path, 'wz.js.mem') } | ||
] | ||
}) | ||
] | ||
} | ||
} |