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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

env:
CI: true
NODE_VERSION: 20
NODE_VERSION: 22

jobs:
test:
Expand Down
22 changes: 22 additions & 0 deletions build/tasks/common/platforms.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// maps this project's own platform identifiers (which mirror Node's
// process.platform) to the platform identifiers used by nw-builder
const nwBuildPlatforms = {
win32 : "win",
darwin: "osx",
linux : "linux"
};


module.exports = {
platforms: {
win32: {
Expand All @@ -24,6 +33,19 @@ module.exports = {
}
},

/**
* Get the `platform` and `arch` values expected by nw-builder for one of
* this project's own platform identifiers (eg. "win32", "linux64", ...).
*/
getNwBuildTarget( name ) {
const { platform, arch } = this.platforms[ name ];

return {
platform: nwBuildPlatforms[ platform ],
arch
};
},

getList() {
const list = Object.keys( this.platforms ).join( ":" );

Expand Down
97 changes: 55 additions & 42 deletions build/tasks/configs/nwjs.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,92 @@
const files = [
"<%= dir.tmp_prod %>/**"
const platforms = require( "../common/platforms" );

// srcDir globs are resolved relative to the "cwd" option below (see build/tasks/custom/nwjs.js),
// not to the grunt process's own cwd, so that nw-builder's file copy logic - which resolves each
// matched file's path directly against outDir without stripping any srcDir prefix - places files
// at the root of the built package instead of nesting them under a "build/tmp/prod/" subdirectory.
const srcDir = [
"**"
];
const ignoreBinWin32 = "!<%= dir.tmp_prod %>/bin/win32/**";
const ignoreBinWin64 = "!<%= dir.tmp_prod %>/bin/win64/**";
const ignoreBinWin32 = "!bin/win32/**";
const ignoreBinWin64 = "!bin/win64/**";

const winIco = "<%= dir.resources %>/icons/icon-16-32-48-256.ico";
const macIcns = "<%= dir.resources %>/icons/icon-1024.icns";


module.exports = {
options: {
files,
buildDir: "<%= dir.releases %>",
cwd : "<%= dir.tmp_prod %>",
cacheDir: "<%= dir.cache %>",
flavor : "normal",
zip : false,
winIco : "<%= dir.resources %>/icons/icon-16-32-48-256.ico",
macIcns : "<%= dir.resources %>/icons/icon-1024.icns",
macPlist: {
CFBundleIdentifier : "<%= main['app-identifier'] %>",
CFBundleName : "<%= main['display-name'] %>",
CFBundleDisplayName: "<%= main['display-name'] %>"
}
zip : false
},

win32: {
options: {
platforms: [ "win32" ],
options: Object.assign( {}, platforms.getNwBuildTarget( "win32" ), {
version: "0.83.0",
files: [
...files,
outDir : "<%= dir.releases %>/<%= package.name %>/win32",
srcDir : [
...srcDir,
ignoreBinWin64
]
}
],
app: {
icon: winIco
}
})
},
win64: {
options: {
platforms: [ "win64" ],
options: Object.assign( {}, platforms.getNwBuildTarget( "win64" ), {
version: "0.83.0",
files: [
...files,
outDir : "<%= dir.releases %>/<%= package.name %>/win64",
srcDir : [
...srcDir,
ignoreBinWin32
]
}
],
app: {
icon: winIco
}
})
},

osx64: {
options: {
platforms: [ "osx64" ],
options: Object.assign( {}, platforms.getNwBuildTarget( "osx64" ), {
version: "0.83.0",
files: [
...files,
outDir : "<%= dir.releases %>/<%= package.name %>/osx64",
srcDir : [
...srcDir,
ignoreBinWin32,
ignoreBinWin64
]
}
],
app: {
icon : macIcns,
CFBundleIdentifier : "<%= main['app-identifier'] %>",
CFBundleName : "<%= main['display-name'] %>",
CFBundleDisplayName: "<%= main['display-name'] %>"
}
})
},

linux32: {
options: {
platforms: [ "linux32" ],
options: Object.assign( {}, platforms.getNwBuildTarget( "linux32" ), {
version: "0.83.0",
files: [
...files,
outDir : "<%= dir.releases %>/<%= package.name %>/linux32",
srcDir : [
...srcDir,
ignoreBinWin32,
ignoreBinWin64
]
}
})
},
linux64: {
options: {
platforms: [ "linux64" ],
options: Object.assign( {}, platforms.getNwBuildTarget( "linux64" ), {
version: "0.83.0",
files: [
...files,
outDir : "<%= dir.releases %>/<%= package.name %>/linux64",
srcDir : [
...srcDir,
ignoreBinWin32,
ignoreBinWin64
]
}
})
}
};
8 changes: 4 additions & 4 deletions build/tasks/configs/run.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module.exports = {
options: Object.assign( {}, require( "./nwjs" ).options, {
flavor: "sdk",
argv: "--remote-debugging-port=8888"
argv: [ "--remote-debugging-port=8888" ]
}),

dev: {
src: "<%= dir.tmp_dev %>/**"
src: "<%= dir.tmp_dev %>"
},

prod: {
src: "<%= dir.tmp_prod %>/**"
src: "<%= dir.tmp_prod %>"
},

debug: {
src: "<%= dir.tmp_prod %>/**"
src: "<%= dir.tmp_prod %>"
}
};
2 changes: 1 addition & 1 deletion build/tasks/configs/runtest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
options: {
path: "build/tmp/test/**"
path: "build/tmp/test"
}
};
24 changes: 15 additions & 9 deletions build/tasks/custom/nwjs.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
module.exports = function( grunt ) {
const NwBuilder = require( "nw-builder" );

function taskNwjs() {
const done = this.async();
const options = this.options();
const { cwd, ...options } = this.options();

if ( this.flags.debug ) {
options.flavor = "sdk";
}

const nw = new NwBuilder( options );
options.mode = "build";

nw.on( "log", grunt.log.debug );
nw.on( "stdout", grunt.log.debug );
nw.on( "stderr", grunt.log.debug );
// nw-builder resolves each globbed srcDir file directly against outDir without
// stripping any srcDir prefix, so srcDir globs are written relative to `cwd`
// (see build/tasks/configs/nwjs.js) and applied here instead.
const prevCwd = process.cwd();
if ( cwd ) {
process.chdir( cwd );
}

nw.build()
import( "nw-builder" )
.then( ( { default: nwbuild } ) => nwbuild( options ) )
.then( () => {
grunt.log.ok( "NW.js application created." );
}, grunt.fail.fatal )
.finally( () => {
process.chdir( prevCwd );
done();
}, grunt.fail.fatal );
});
}

grunt.registerMultiTask(
Expand Down
21 changes: 9 additions & 12 deletions build/tasks/custom/run.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
module.exports = function( grunt ) {
const NwBuilder = require( "nw-builder" );
const platforms = require( "../common/platforms" );
const { resolve: r } = require( "path" );

function taskRun() {
const done = this.async();
const options = this.options({
platforms: [ platforms.getPlatform() ]
});
const options = this.options(
platforms.getNwBuildTarget( platforms.getPlatform() )
);

options.files = r( process.cwd(), this.data.src );
options.mode = "run";
options.glob = false;
options.srcDir = r( process.cwd(), this.data.src );

const nw = new NwBuilder( options );

nw.on( "log", grunt.log.writeln.bind( grunt.log ) );
nw.on( "stdout", grunt.log.writeln.bind( grunt.log ) );
nw.on( "stderr", grunt.log.writeln.bind( grunt.log ) );

nw.run().then( done, grunt.fail.fatal );
import( "nw-builder" )
.then( ( { default: nwbuild } ) => nwbuild( options ) )
.then( done, grunt.fail.fatal );
}

grunt.task.registerMultiTask(
Expand Down
72 changes: 33 additions & 39 deletions build/tasks/custom/runtest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = function( grunt ) {
grunt.registerTask( "runtest", "Run the tests in NW.js", function() {
const NwBuilder = require( "nw-builder" );
const cdpConnect = require( "../common/cdp/connect" );
const cdpQUnit = require( "../common/cdp/qunit" );
const cdpCoverage = require( "../common/cdp/coverage" );
Expand Down Expand Up @@ -30,23 +29,23 @@ module.exports = function( grunt ) {
argv.unshift( "--disable-gpu", "--no-sandbox" );
}
const nwjsOptions = Object.assign( {}, nwOptions, nwPlatformOptions, {
mode : "run",
glob : false,
flavor: "sdk",
files: options.path,
srcDir: options.path,
argv
});
const nwjs = new NwBuilder( nwjsOptions );

let nwProcess;

function kill() {
if ( nwjs.isAppRunning() ) {
const appProcess = nwjs.getAppProcess();

if ( nwProcess ) {
// workaround for the close event log message
appProcess.removeAllListeners( "close" );
nwjs._nwProcess = undefined;
nwProcess.removeAllListeners( "close" );

// now kill the child process
appProcess.kill();
nwProcess.kill();
nwProcess = undefined;

grunt.log.debug( "NW.js stopped" );
process.removeListener( "exit", kill );
Expand All @@ -65,39 +64,34 @@ module.exports = function( grunt ) {
new Promise( ( resolve, reject ) => {
process.on( "exit", kill );

nwjs.on( "log", grunt.log.writeln.bind( grunt.log ) );
nwjs.on( "stdout", grunt.log.writeln.bind( grunt.log ) );
nwjs.on( "stderr", grunt.log.writeln.bind( grunt.log ) );

// listen for the appstart event
nwjs.on( "appstart", () => {
grunt.log.debug( "NW.js started" );

const nwjsProcess = nwjs.getAppProcess();
nwjsProcess.on( "close", () => {
reject( "NW.js exited prematurely" );
});

// connect to NW.js
cdpConnect( options, grunt.log.error )
.then( async cdp => {
grunt.log.debug( `Connected to ${options.host}:${options.port}` );

// set up and start QUnit
await cdpQUnit( grunt, options, cdp );
if ( isCoverage ) {
await cdpCoverage( grunt, options, cdp );
}
})
// resolve on a successful test run
.then( resolve, reject );
});

grunt.log.debug( "Starting NW.js..." );

// start the NW.js process (or download NW.js first)
// reject if NW.js exited prematurely
nwjs.run().then( reject, reject );
// reject if NW.js fails to start or exits prematurely
import( "nw-builder" )
.then( ( { default: nwbuild } ) => nwbuild( nwjsOptions ) )
.then( childProcess => {
grunt.log.debug( "NW.js started" );

nwProcess = childProcess;
nwProcess.on( "close", () => {
reject( "NW.js exited prematurely" );
});

// connect to NW.js
return cdpConnect( options, grunt.log.error )
.then( async cdp => {
grunt.log.debug( `Connected to ${options.host}:${options.port}` );

// set up and start QUnit
await cdpQUnit( grunt, options, cdp );
if ( isCoverage ) {
await cdpCoverage( grunt, options, cdp );
}
});
})
// resolve on a successful test run
.then( resolve, reject );
})
// make sure to terminate the NW.js process
.then( noShutdown => {
Expand Down
4 changes: 2 additions & 2 deletions build/tasks/webpack/configurators/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ module.exports = {
new NwjsPlugin(
grunt.config( "nwjs" ),
{
files: `${grunt.config( "dir" )[ path ]}/**`,
srcDir: `${grunt.config( "dir" )[ path ]}`,
flavor: "sdk",
argv: "--remote-debugging-port=8888"
argv: [ "--remote-debugging-port=8888" ]
}
)
);
Expand Down
Loading