Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1e5ebd6
feat: move browser_*.js files to /lib
erisu Apr 1, 2026
836e634
feat: move /bin/template to /templates
erisu Apr 1, 2026
160e19a
feat: split Api.js, do not copy node_modules, & fix tests
erisu Apr 1, 2026
4841fe7
refactor: cleanup require blocks
erisu Apr 10, 2026
86f43bf
refactor(Api): convert to class
erisu Apr 11, 2026
1cb95ac
refactor(Api): getPlatformInfo
erisu Apr 11, 2026
32cefd8
refactor(Api): prepare
erisu Apr 11, 2026
ec9b267
refactor(Api): _updateWww
erisu Apr 11, 2026
91b647f
refactor(Api): addPlugin
erisu Apr 11, 2026
f89cf2c
refactor(Api): removePlugin
erisu Apr 11, 2026
0c5b523
refactor(Api): _getInstaller
erisu Apr 11, 2026
a5ca4d7
refactor(Api): _getUninstaller
erisu Apr 11, 2026
2e563a2
refactor(Api): _addModulesInfo
erisu Apr 11, 2026
45a403e
refactor(Api): _writePluginModules & _removeModulesInfo
erisu Apr 11, 2026
2c090fd
refactor(Api): build, run, clean & requirements
erisu Apr 11, 2026
61802e5
refactor(Api): build
erisu Apr 11, 2026
4ab9052
chore(Api): set async where needed
erisu Apr 11, 2026
1d636d5
refactor(Api): dont allow changing of platform name
erisu Apr 11, 2026
f42015d
chore(Api): add static method version & match other platforms
erisu Apr 11, 2026
e217b51
chore: remove unnecessary node shebang
erisu Apr 11, 2026
fb520cd
refactor: module require order
erisu Apr 11, 2026
1daa525
refactor: cleanup events variable naming
erisu Apr 11, 2026
3f6ecbb
refactor: use template literals where possible
erisu Apr 11, 2026
0243bb4
refactor: use arrow functions where possible
erisu Apr 11, 2026
8012581
chore: update private method prefix '#_' to '#'
erisu Apr 13, 2026
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
869 changes: 430 additions & 439 deletions lib/Api.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions lib/browser_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

const path = require('node:path');
const fs = require('node:fs');
const events = require('cordova-common').events;

const { events } = require('cordova-common');

module.exports = {
www_dir: function (project_dir) {
Expand Down Expand Up @@ -53,9 +54,9 @@ module.exports = {
// Read in the file, prepend the cordova.define, and write it back out.
let scriptContent = fs.readFileSync(moduleSource, 'utf-8').replace(/^\ufeff/, ''); // Window BOM
if (moduleSource.match(/.*\.json$/)) {
scriptContent = 'module.exports = ' + scriptContent;
scriptContent = `module.exports = ${scriptContent}`;
}
scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) { ' + scriptContent + '\n});\n';
scriptContent = `cordova.define("${moduleName}", function(require, exports, module) { ${scriptContent}\n});\n`;

const moduleDestination = path.resolve(www_dir, 'plugins', plugin_id, jsModule.src);
fs.mkdirSync(path.dirname(moduleDestination), { recursive: true });
Expand All @@ -64,7 +65,7 @@ module.exports = {
uninstall: function (jsModule, www_dir, plugin_id) {
const pluginRelativePath = path.join('plugins', plugin_id, jsModule.src);
// common.removeFileAndParents(www_dir, pluginRelativePath);
console.log('js-module uninstall called : ' + pluginRelativePath);
console.log(`js-module uninstall called : ${pluginRelativePath}`);
}
},
'source-file': {
Expand Down
15 changes: 9 additions & 6 deletions lib/browser_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@

const fs = require('node:fs');
const path = require('node:path');
const CordovaError = require('cordova-common').CordovaError;
const events = require('cordova-common').events;
const FileUpdater = require('cordova-common').FileUpdater;

const {
CordovaError,
FileUpdater,
events
} = require('cordova-common');

function dirExists (dir) {
return fs.existsSync(dir) && fs.statSync(dir).isDirectory();
}

function browser_parser (project) {
if (!dirExists(project) || !dirExists(path.join(project, 'cordova'))) {
throw new CordovaError('The provided path "' + project + '" is not a valid browser project.');
throw new CordovaError(`The provided path "${project}" is not a valid browser project.`);
}
this.path = project;
}
Expand All @@ -44,7 +47,7 @@ browser_parser.prototype.www_dir = function () {
* Logs all file operations via the verbose event stream, indented.
*/
function logFileOp (message) {
events.emit('verbose', ' ' + message);
events.emit('verbose', ` ${message}`);
}

// Replace the www dir with contents of platform_www and app www.
Expand All @@ -67,7 +70,7 @@ browser_parser.prototype.update_www = function (cordovaProject, opts) {

// targetDir points to browser/www
const targetDir = path.relative(cordovaProject.root, my_www);
events.emit('verbose', 'Merging and updating files from [' + sourceDirs.join(', ') + '] to ' + targetDir);
events.emit('verbose', `Merging and updating files from [${sourceDirs.join(', ')}] to ${targetDir}`);
FileUpdater.mergeAndUpdateDir(sourceDirs, targetDir, { rootDir: cordovaProject.root }, logFileOp);
};

Expand Down
5 changes: 2 additions & 3 deletions lib/build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand All @@ -20,6 +18,7 @@
*/

const path = require('node:path');

const check_reqs = require('./check_reqs');

/**
Expand All @@ -33,5 +32,5 @@ module.exports.run = function () {
module.exports.help = function () {
console.log('Usage: cordova build browser');
const wwwPath = path.resolve(path.join(__dirname, '../../www'));
console.log("Build will create the packaged app in '" + wwwPath + "'.");
console.log(`Build will create the packaged app in '${wwwPath}'.`);
};
2 changes: 0 additions & 2 deletions lib/check_reqs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand Down
6 changes: 3 additions & 3 deletions lib/clean.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand All @@ -21,7 +19,9 @@

const fs = require('node:fs');
const path = require('node:path');

const check_reqs = require('./check_reqs');

const platformBuildDir = path.join('platforms', 'browser', 'www');

const run = function () {
Expand All @@ -37,7 +37,7 @@ const run = function () {
fs.rmSync(platformBuildDir, { recursive: true });
}
} catch (err) {
console.log('could not remove ' + platformBuildDir + ' : ' + err.message);
console.log(`could not remove ${platformBuildDir} : ${err.message}`);
}
};

Expand Down
9 changes: 7 additions & 2 deletions lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@

const fs = require('node:fs');
const path = require('node:path');
const ROOT = path.join(__dirname, '..');
const { CordovaError, events } = require('cordova-common');
const {
CordovaError,
events
} = require('cordova-common');

const check_reqs = require('./check_reqs');

const ROOT = path.join(__dirname, '..');

// exported method to create a project, returns a promise that resolves with null
module.exports.createProject = function (project_path, package_name, project_name, opts = {}, root_config) {
project_path = path.relative(process.cwd(), project_path);
Expand Down
9 changes: 4 additions & 5 deletions lib/run.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand All @@ -22,6 +20,7 @@
const fs = require('node:fs');
const path = require('node:path');
const url = require('node:url');

const cordovaServe = require('cordova-serve');

module.exports.run = function (args) {
Expand All @@ -41,7 +40,7 @@ module.exports.run = function (args) {
const manifest = require(manifestFilePath);
startPage = manifest.start_url;
} catch (err) {
console.log('failed to require manifest ... ' + err);
console.log(`failed to require manifest ... ${err}`);
}
}

Expand All @@ -55,8 +54,8 @@ module.exports.run = function (args) {

const projectUrl = (new url.URL(`http://localhost:${server.port}/${startPage}`)).href;

console.log('startPage = ' + startPage);
console.log('Static file server running @ ' + projectUrl + '\nCTRL + C to shut down');
console.log(`startPage = ${startPage}`);
console.log(`Static file server running @ ${projectUrl}\nCTRL + C to shut down`);
return server.launchBrowser({ target: args.target, url: projectUrl });
})
.catch(function (error) {
Expand Down
4 changes: 3 additions & 1 deletion lib/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
under the License.
*/

const create = require('./create');
const fs = require('node:fs');

const { CordovaError } = require('cordova-common');

const create = require('./create');

module.exports.help = function () {
console.log('WARNING : Make sure to back up your project before updating!');
console.log('Usage: update PathToProject ');
Expand Down
3 changes: 2 additions & 1 deletion spec/browser_handler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
under the License.
*/

const browser_handler = require('../lib/browser_handler');
const fs = require('node:fs');
const path = require('node:path');

const browser_handler = require('../lib/browser_handler');

describe('Asset install tests', function () {
let fsstatMock;
const asset = {
Expand Down
5 changes: 2 additions & 3 deletions spec/projectApi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ const path = require('node:path');
const { Module } = require('node:module');
const EventEmitter = require('node:events');
const tmp = require('tmp');
const { ConfigParser } = require('cordova-common');
const Api = require('../lib/Api');

process.env.NODE_PATH = path.resolve(__dirname, '../../');
Module._initPaths();

const { ConfigParser } = require('cordova-common');
const Api = require('../lib/Api');

tmp.setGracefulCleanup();

function makeTempDir () {
Expand Down
5 changes: 2 additions & 3 deletions templates/cordova/version
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
under the License.
*/

// Coho updates this line:
const VERSION = '8.0.0-dev';
const Api = require('./Api');

console.log(VERSION);
console.log(Api.version());
Loading