Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
npm-debug.log
node_modules/
bin/
/esm/
apis-config/
39 changes: 24 additions & 15 deletions buildpackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ const UglifyES = require("uglify-es");
(async function() {

// Clean bin directory
console.log("# Cleaning bin. Running shelljs rm -rf ./bin");
shell.rm("-rf", "./bin");
console.log("# Cleaning bin/ and esm/. Running shelljs rm -rf ./bin ./esm");
shell.rm("-rf", "./bin", "./esm");

// Compile typescript
console.log("# Compiling TypeScript. Executing `node_modules\\.bin\\tsc -p ./tsconfig.json`.");
// On Windows, we need `\`, on Unix we need `/`.
const tsc = path.join("node_modules", ".bin", "tsc");

// Compile typescript ./bin folder
console.log(`# Compiling TypeScript. Executing \`${tsc} -p ./tsconfig.json\`.`);
try {
execSync("node_modules\\.bin\\tsc -p ./tsconfig.json", {
execSync(`${tsc} -p ./tsconfig.json`, {
stdio: [0, 1, 2],
shell: true,
cwd: __dirname,
Expand All @@ -29,17 +32,23 @@ const UglifyES = require("uglify-es");
process.exit(1);
}

// Copy ts files to bin
console.log("# Copy declare files to bin.");
// Compile typescript ./esm folder
console.log(`# Compiling TypeScript to ESM. Executing \`${tsc} -p ./tsconfig.esm.json\`.`);
try {
await copy(path.join(__dirname, "src"), path.join(__dirname, "bin"), {
filter: f => {
return f.endsWith(".d.ts");
},
});
} catch (e) {
console.log("Copy failed. " + error);
execSync(`${tsc} -p ./tsconfig.esm.json`, {
stdio: [0, 1, 2],
shell: true,
cwd: __dirname,
});
} catch (error) {
console.log("ERROR: Failed to build TypeScript ESM.");
process.exit(1);
}
console.log("# Creating ./esm/package.json to show files in ./esm are ESM");
fs.writeFileSync("./esm/package.json", '{"type": "module"}\n');
// Move ./esm folder into ./bin/esm
console.log("# Moving ./esm folder to ./bin/esm");
fs.renameSync("./esm", "./bin/esm");

// Uglify JavaScript
console.log("# Minifying JS using the UglifyES API, replacing un-minified files.");
Expand All @@ -56,7 +65,7 @@ const UglifyES = require("uglify-es");
});

for (const file of files) {
if (file.includes("node_modules/")) {
if (file.includes("node_modules/") || file.includes("esm/")) {
continue;
}
fs.writeFileSync(
Expand Down
Loading