Skip to content
Merged
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/
115 changes: 79 additions & 36 deletions npm-scripts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const esbuild = require("esbuild");
const fs = require('fs');
const path = require('path');
const process = require('process');
const { execSync } = require('child_process');
const { version } = require('./package.json');
const pkg = require('./package.json');

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

Expand All @@ -11,42 +12,49 @@ const ESLINT_PATHS = [ 'src', 'test' ].join(' ');
// 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;
}
void run();

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

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

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

case 'build': {
await build(true /* minify */);
await build(false /* minify */);

break;
}

case 'release': {
lint();
test();
executeCmd(`git commit -am '${pkg.version}'`);
executeCmd(`git tag -a ${pkg.version} -m '${pkg.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 +101,41 @@ function grammar()
logInfo('grammar done');
}

// Build sources into a file for publishing.
async function build(minify = true) {
const entry = path.resolve("src/JsSIP.js");
const outfile = path.resolve("./dist", `jssip${minify ? '.min' : ''}.js`);
const banner = `
/*
* JsSIP ${pkg.version}
* ${pkg.description}
* Copyright: 2012-${new Date().getFullYear()} ${pkg.contributors.join(' ')}
* Homepage: ${pkg.homepage}
* License: ${pkg.license}
*/`;

await esbuild.build({
entryPoints: [entry],
outfile,
bundle: true,
minify,
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 banner.
banner: {
js: banner,
},
});
}

function executeCmd(command)
{
// eslint-disable-next-line no-console
Expand Down
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"
}
}