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 +1,2 @@
/node_modules/
/dist/
121 changes: 85 additions & 36 deletions npm-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,59 @@ const path = require('path');
const process = require('process');
const { execSync } = require('child_process');
const { version } = require('./package.json');
const pkg = require('./package.json');
const { resolve } = require("path");
const { build } = require("esbuild");
const { readFile, writeFile } = require("fs/promises");

const task = process.argv.slice(2).join(' ');

const ESLINT_PATHS = [ 'src', 'test' ].join(' ');
const rootDir = "./";
const outDir = "./dist";

// eslint-disable-next-line no-console
console.log(`npm-scripts.js [INFO] running task "${task}"`);

switch (task)
{
case 'grammar': {
grammar();

break;
}

case 'lint': {
lint();

break;
}

case 'test': {
test();

break;
}

case 'release': {
lint();
test();
executeCmd(`git commit -am '${version}'`);
executeCmd(`git tag -a ${version} -m '${version}'`);
executeCmd('git push origin master && git push origin --tags');
executeCmd('npm publish');

// eslint-disable-next-line no-console
console.log('update tryit-jssip and JsSIP website');

break;
}

default: {
throw new TypeError(`unknown task "${task}"`);
async function main() {
switch (task)
{
case 'grammar': {
grammar();
break;
}

case 'lint': {
lint();
break;
}

case 'test': {
test();
break;
}

case 'build': {
await buildMin(rootDir, outDir);
break;
}

case 'release': {
lint();
test();
executeCmd(`git commit -am '${version}'`);
executeCmd(`git tag -a ${version} -m '${version}'`);
executeCmd('git push origin master && git push origin --tags');
executeCmd('npm publish');

// eslint-disable-next-line no-console
console.log('update tryit-jssip and JsSIP website');
break;
}

default: {
throw new TypeError(`unknown task "${task}"`);
}
}
}

Expand Down Expand Up @@ -93,6 +102,41 @@ function grammar()
logInfo('grammar done');
}


// Build a Minified version of JsSIP into /dist/ for publishing
async function buildMin(rootDir, outDir) {
const entry = resolve(rootDir, "src/JsSIP.js");
const outfile = resolve(outDir, "jssip.min.js");
const banner = `/*!
* JsSIP ${pkg.version}
* ${pkg.description}
* Copyright: 2012-${new Date().getFullYear()} ${pkg.contributors.join(' ')}
* Homepage: ${pkg.homepage}
* License: ${pkg.license}
*/`;

await build({
entryPoints: [entry],
outfile,
bundle: true,
minify: true,
sourcemap: false,
// https://esbuild.github.io/api/#global-name
format: "iife",
globalName: "JsSIP",
platform: "browser",
target: ["es2015"],
// Make the generated output a single line
supported: {
"template-literal": false,
},
// Add a banner
banner: {
js: banner,
},
});
}

function executeCmd(command)
{
// eslint-disable-next-line no-console
Expand All @@ -114,3 +158,8 @@ function logInfo(...args)
// eslint-disable-next-line no-console
console.log(`npm-scripts.mjs \x1b[36m[INFO] [${task}]\x1b[0m`, ...args);
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@eslint/js": "^9.39.2",
"@types/debug": "^4.1.12",
"@types/events": "^3.0.3",
"esbuild": "^0.27.2",
"eslint": "^9.39.1",
"eslint-plugin-jest": "^29.12.1",
"globals": "^17.0.0",
Expand All @@ -45,6 +46,7 @@
"scripts": {
"lint": "node npm-scripts.js lint",
"test": "node npm-scripts.js test",
"build": "node npm-scripts.js build",
"release": "node npm-scripts.js release"
}
}