You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2026/06/07 04:01:41 UTC
(cordova-browser) branch master updated: feat!: directory restructure (#154)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-browser.git
The following commit(s) were added to refs/heads/master by this push:
new 44b6adc feat!: directory restructure (#154)
44b6adc is described below
commit 44b6adc16e03a5182c72b1c3a9d495e6399bd45d
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Sun Jun 7 13:01:36 2026 +0900
feat!: directory restructure (#154)
* feat: move /bin/lib to /lib
* feat: move /bin/template/cordova/lib to /lib
* feat: move browser_*.js files to /lib
* feat: move /bin/template to /templates
* feat: split Api.js, do not copy node_modules, & fix tests
* chore: resolve lint errors
* chore(test): stop creating empty dest dir
* chore: resolve codeql
---
.github/workflows/ci.yml | 4 +-
.gitignore | 2 +-
eslint.config.js | 6 +-
{bin/template/cordova => lib}/Api.js | 30 ++++------
{bin/template/cordova => lib}/browser_handler.js | 0
{bin/template/cordova => lib}/browser_parser.js | 0
{bin/template/cordova/lib => lib}/build.js | 0
{bin/lib => lib}/check_reqs.js | 0
{bin/template/cordova/lib => lib}/clean.js | 0
{bin/lib => lib}/create.js | 57 +++++++------------
{bin/template/cordova/lib => lib}/run.js | 0
{bin/lib => lib}/update.js | 0
package.json | 8 +--
spec/browser_handler.spec.js | 7 ++-
spec/create.spec.js | 2 +-
spec/fixtures/default-config.xml | 34 ++++++++++++
spec/projectApi.spec.js | 61 +++++++++++++--------
.../cordova/version => templates/cordova/Api.js | 7 +--
{bin/template => templates}/cordova/defaults.xml | 0
{bin/template => templates}/cordova/version | 0
{bin/template => templates}/www/css/index.css | 0
{bin/template => templates}/www/favicon.ico | Bin
{bin/template => templates}/www/img/logo.png | Bin
{bin/template => templates}/www/img/splash.png | Bin
{bin/template => templates}/www/index.html | 0
{bin/template => templates}/www/js/index.js | 0
{bin/template => templates}/www/manifest.json | 0
27 files changed, 120 insertions(+), 98 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2fe5e92..0028461 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -53,7 +53,7 @@ jobs:
node --version
npm --version
- # "bin/template/www/cordova.js" is ignored because it is a generated file.
+ # "templates/www/cordova.js" is ignored because it is a generated file.
# It contains mixed content from the npm package "cordova-js" and "./cordova-js-src".
# The report might not be resolvable because of the external package.
# If the report is related to this repository, it would be detected when scanning "./cordova-js-src".
@@ -65,7 +65,7 @@ jobs:
paths-ignore:
- coverage
- node_modules
- - bin/template/www/cordova.js
+ - templates/www/cordova.js
- name: npm install and test
run: |
diff --git a/.gitignore b/.gitignore
index 82180d3..4ba5ff6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,4 +34,4 @@ temp
*.tgz
# Other
-bin/template/www/cordova.js
+templates/www/cordova.js
diff --git a/eslint.config.js b/eslint.config.js
index 10446cd..63f0b53 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -25,12 +25,12 @@ const browserConfig = require('@cordova/eslint-config/browser');
module.exports = defineConfig([
globalIgnores([
'**/coverage/',
- 'bin/template/www/cordova.js'
+ 'templates/www/cordova.js'
]),
...nodeConfig.map(config => ({
files: [
'**/*.js',
- 'bin/template/cordova/version'
+ 'templates/cordova/version'
],
...config
})),
@@ -41,7 +41,7 @@ module.exports = defineConfig([
...browserConfig.map(config => ({
files: [
'cordova-js-src/**/*.js',
- 'bin/template/www/**/*.js'
+ 'templates/www/**/*.js'
],
...config,
languageOptions: {
diff --git a/bin/template/cordova/Api.js b/lib/Api.js
similarity index 96%
rename from bin/template/cordova/Api.js
rename to lib/Api.js
index ffa9a8f..ac9f915 100644
--- a/bin/template/cordova/Api.js
+++ b/lib/Api.js
@@ -37,6 +37,8 @@ const PluginInfoProvider = cdvcmn.PluginInfoProvider;
const CordovaError = cdvcmn.CordovaError;
const FileUpdater = cdvcmn.FileUpdater;
+const { createProject } = require('./create');
+
const PLATFORM_NAME = 'browser';
function setupEvents (externalEventEmitter) {
@@ -65,9 +67,7 @@ function dirExists (dir) {
function Api (platform, platformRootDir, events) {
this.platform = platform || PLATFORM_NAME;
-
- // MyApp/platforms/browser
- this.root = path.resolve(__dirname, '..');
+ this.root = platformRootDir;
this.events = setupEvents(events);
if (!dirExists(this.root) || !dirExists(path.join(this.root, 'cordova'))) {
throw new CordovaError('The provided path "' + this.root + '" is not a valid browser project.');
@@ -84,7 +84,7 @@ function Api (platform, platformRootDir, events) {
defaultConfigXml: path.join(this.root, 'cordova/defaults.xml'),
build: path.join(this.root, 'build'),
// NOTE: Due to platformApi spec we need to return relative paths here
- cordovaJs: 'bin/templates/project/assets/www/cordova.js',
+ cordovaJs: 'templates/project/assets/www/cordova.js',
cordovaJsSrc: 'cordova-js-src'
};
@@ -94,20 +94,13 @@ function Api (platform, platformRootDir, events) {
}
Api.createPlatform = function (dest, config, options, events) {
- const creator = require('../../lib/create');
events = setupEvents(events);
- let name = 'HelloCordova';
- let id = 'io.cordova.hellocordova';
- if (config) {
- name = config.name();
- id = config.packageName();
- }
+ const name = config.name().normalize('NFD');
- let result;
try {
// we create the project using our scripts in this platform
- result = creator.createProject(dest, id, name, options)
+ return createProject(dest, config.packageName(), name, options, config)
.then(function () {
// after platform is created we return Api instance based on new Api.js location
// Api.js has been copied to the new project
@@ -119,7 +112,6 @@ Api.createPlatform = function (dest, config, options, events) {
events.emit('error', 'createPlatform is not callable from the browser project API.');
throw (e);
}
- return result;
};
Api.updatePlatform = function (dest, options, events) {
@@ -547,22 +539,22 @@ Api.prototype._removeModulesInfo = function (plugin, targetDir) {
Api.prototype.build = function (buildOptions) {
const self = this;
- return require('./lib/check_reqs').run()
+ return require('./check_reqs').run()
.then(function () {
- return require('./lib/build').run.call(self, buildOptions);
+ return require('./build').run.call(self, buildOptions);
});
};
Api.prototype.run = function (runOptions) {
- return require('./lib/run').run(runOptions);
+ return require('./run').run(runOptions);
};
Api.prototype.clean = function (cleanOptions) {
- return require('./lib/clean').run(cleanOptions);
+ return require('./clean').run(cleanOptions);
};
Api.prototype.requirements = function () {
- return require('./lib/check_reqs').run();
+ return require('./check_reqs').run();
};
module.exports = Api;
diff --git a/bin/template/cordova/browser_handler.js b/lib/browser_handler.js
similarity index 100%
rename from bin/template/cordova/browser_handler.js
rename to lib/browser_handler.js
diff --git a/bin/template/cordova/browser_parser.js b/lib/browser_parser.js
similarity index 100%
rename from bin/template/cordova/browser_parser.js
rename to lib/browser_parser.js
diff --git a/bin/template/cordova/lib/build.js b/lib/build.js
similarity index 100%
rename from bin/template/cordova/lib/build.js
rename to lib/build.js
diff --git a/bin/lib/check_reqs.js b/lib/check_reqs.js
similarity index 100%
rename from bin/lib/check_reqs.js
rename to lib/check_reqs.js
diff --git a/bin/template/cordova/lib/clean.js b/lib/clean.js
similarity index 100%
rename from bin/template/cordova/lib/clean.js
rename to lib/clean.js
diff --git a/bin/lib/create.js b/lib/create.js
similarity index 58%
rename from bin/lib/create.js
rename to lib/create.js
index 6042248..f8ef75e 100644
--- a/bin/lib/create.js
+++ b/lib/create.js
@@ -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
@@ -21,52 +19,37 @@
const fs = require('node:fs');
const path = require('node:path');
-const ROOT = path.join(__dirname, '..', '..');
-const events = require('cordova-common').events;
+const ROOT = path.join(__dirname, '..');
+const { CordovaError, events } = require('cordova-common');
const check_reqs = require('./check_reqs');
// exported method to create a project, returns a promise that resolves with null
-module.exports.createProject = function (project_path, package_name, project_name) {
-/*
- // create the dest and the standard place for our api to live
- // platforms/platformName/cordova/Api.js
-*/
-
- events.emit('log', 'Creating Cordova project for cordova-browser:');
- events.emit('log', '\tPath: ' + project_path);
- events.emit('log', '\tName: ' + project_name);
-
- // Set default values for path, package and name
- project_path = project_path || 'CordovaExample';
+module.exports.createProject = function (project_path, package_name, project_name, opts = {}, root_config) {
+ project_path = path.relative(process.cwd(), project_path);
// Check if project already exists
if (fs.existsSync(project_path)) {
- events.emit('error', 'Oops, destination already exists! Delete it and try again');
- } else {
- fs.mkdirSync(project_path);
+ throw new CordovaError('Project already exists');
}
+ package_name = package_name || 'org.apache.cordova.hellocordova';
+ project_name = project_name || 'Hello Cordova';
+
+ events.emit('log', 'Creating Cordova project for the browser platform:');
+ events.emit('log', `\tPath: ${project_path}`);
+ events.emit('log', `\tPackage: ${package_name}`);
+ events.emit('log', `\tName: ${project_name}`);
+
+ fs.mkdirSync(project_path);
+
// Check that requirements are met and proper targets are installed
if (!check_reqs.run()) {
// TODO: use events.emit
events.emit('error', 'Please make sure you meet the software requirements in order to build a browser cordova project');
}
- // copy template/* to project_path directory ( recursive )
- fs.cpSync(path.join(ROOT, 'bin/template'), project_path, { recursive: true });
-
- // TODO: stop copying cordova-browser logic into platforms/browser/
- // recreate our node_modules structure in the new project
- const nodeModulesDir = path.join(ROOT, 'node_modules');
- if (fs.existsSync(nodeModulesDir)) {
- fs.cpSync(nodeModulesDir, path.join(project_path, 'cordova/node_modules'), { recursive: true });
- }
-
- // copy check_reqs file
- fs.cpSync(
- path.join(ROOT, 'bin/lib/check_reqs.js'),
- path.join(project_path, 'cordova/lib/check_reqs.js')
- );
+ // copy templates/* to project_path directory ( recursive )
+ fs.cpSync(path.join(ROOT, 'templates'), project_path, { recursive: true });
// create platform_www dir if it does not exist yet
const platform_www = path.join(project_path, 'platform_www');
@@ -74,18 +57,18 @@ module.exports.createProject = function (project_path, package_name, project_nam
// copy cordova js file to platform_www
fs.cpSync(
- path.join(ROOT, 'bin/template/www/cordova.js'),
+ path.join(ROOT, 'templates/www/cordova.js'),
path.join(platform_www, 'cordova.js')
);
// copy favicon file to platform_www
fs.cpSync(
- path.join(ROOT, 'bin/template/www/favicon.ico'),
+ path.join(ROOT, 'templates/www/favicon.ico'),
path.join(platform_www, 'favicon.ico')
);
// load manifest to write name/shortname
- const manifest = require(path.join(ROOT, 'bin/template/www', 'manifest.json'));
+ const manifest = require(path.join(ROOT, 'templates/www', 'manifest.json'));
manifest.name = project_name;
manifest.short_name = project_name;
// copy manifest file to platform_www
diff --git a/bin/template/cordova/lib/run.js b/lib/run.js
similarity index 100%
rename from bin/template/cordova/lib/run.js
rename to lib/run.js
diff --git a/bin/lib/update.js b/lib/update.js
similarity index 100%
rename from bin/lib/update.js
rename to lib/update.js
diff --git a/package.json b/package.json
index 0f5ddac..a2212d2 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "cordova-browser",
"version": "8.0.0-dev",
"description": "cordova-browser release",
- "main": "bin/template/cordova/Api.js",
+ "main": "lib/Api.js",
"repository": "github:apache/cordova-browser",
"bugs": "https://github.com/apache/cordova-browser/issues",
"keywords": [
@@ -11,7 +11,7 @@
"apache"
],
"scripts": {
- "prepare": "cordova-js build > bin/template/www/cordova.js",
+ "prepare": "cordova-js build > templates/www/cordova.js",
"cover": "c8 jasmine",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
@@ -36,8 +36,8 @@
},
"c8": {
"include": [
- "bin/lib/**",
- "bin/templates/cordova/**"
+ "lib/**",
+ "templates/cordova/**"
],
"reporter": [
"lcov",
diff --git a/spec/browser_handler.spec.js b/spec/browser_handler.spec.js
index 2285fc4..f63c115 100644
--- a/spec/browser_handler.spec.js
+++ b/spec/browser_handler.spec.js
@@ -17,7 +17,7 @@
under the License.
*/
-const browser_handler = require('../bin/template/cordova/browser_handler');
+const browser_handler = require('../lib/browser_handler');
const fs = require('node:fs');
const path = require('node:path');
@@ -44,6 +44,8 @@ describe('Asset install tests', function () {
it('if src is a directory, should be called with cpSync recursive force', function () {
const cp = spyOn(fs, 'cpSync').and.callFake(() => {});
+ const mkdirSync = spyOn(fs, 'mkdirSync').and.callFake(() => {});
+
fsstatMock = {
isDirectory: function () {
return true;
@@ -51,6 +53,9 @@ describe('Asset install tests', function () {
};
spyOn(fs, 'statSync').and.returnValue(fsstatMock);
browser_handler.asset.install(asset, plugin_dir, wwwDest);
+ expect(mkdirSync).toHaveBeenCalledWith(wwwDest, {
+ recursive: true
+ });
expect(cp).toHaveBeenCalledWith(jasmine.any(String), path.join('dest', asset.target), {
recursive: true,
force: true
diff --git a/spec/create.spec.js b/spec/create.spec.js
index 0d11532..6c1b13a 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -20,7 +20,7 @@
const fs = require('node:fs');
const path = require('node:path');
const tmp = require('tmp');
-const create = require('../bin/lib/create');
+const create = require('../lib/create');
tmp.setGracefulCleanup();
diff --git a/spec/fixtures/default-config.xml b/spec/fixtures/default-config.xml
new file mode 100644
index 0000000..c3eede9
--- /dev/null
+++ b/spec/fixtures/default-config.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<widget xmlns="http://www.w3.org/ns/widgets"
+ xmlns:cdv="http://cordova.apache.org/ns/1.0"
+ id="org.apache.cordova.hellocordova"
+ version="1.0.0">
+ <name>Hello Cordova</name>
+ <description>
+ A sample Apache Cordova application that responds to the deviceready event.
+ </description>
+ <author email="dev@cordova.apache.org" href="https://cordova.apache.org">
+ Apache Cordova Team
+ </author>
+ <content src="index.html" />
+ <allow-intent href="http://*/*" />
+ <allow-intent href="https://*/*" />
+</widget>
diff --git a/spec/projectApi.spec.js b/spec/projectApi.spec.js
index d5b68e0..3342a71 100644
--- a/spec/projectApi.spec.js
+++ b/spec/projectApi.spec.js
@@ -18,10 +18,22 @@
*/
const path = require('node:path');
+const { Module } = require('node:module');
const EventEmitter = require('node:events');
+const tmp = require('tmp');
-const Api = require('../bin/template/cordova/Api');
-const create = require('../bin/lib/create');
+process.env.NODE_PATH = path.resolve(__dirname, '../../');
+Module._initPaths();
+
+const { ConfigParser } = require('cordova-common');
+const Api = require('../lib/Api');
+
+tmp.setGracefulCleanup();
+
+function makeTempDir () {
+ const tempdir = tmp.dirSync({ unsafeCleanup: true });
+ return path.join(tempdir.name, `cordova-browser-create-test-${Date.now()}`);
+}
describe('can get the Api', function () {
it('should be defined', function () {
@@ -40,23 +52,36 @@ describe('can get the Api', function () {
describe('static createPlatform method', () => {
it('should create a platform app and return the Api', () => {
- // Trick function under test to load our Api after calling createProject
- const testDir = path.join(__dirname, '../bin/template');
+ // Trick function under test to load our Api after callin
+ const testDir = makeTempDir();
+
const testOpts = {};
- spyOn(create, 'createProject').and.returnValue(Promise.resolve());
+ const configXmlPath = path.join(__dirname, 'fixtures/default-config.xml');
+ const config = new ConfigParser(configXmlPath);
- return Api.createPlatform(testDir, null, testOpts, new EventEmitter()).then(api => {
- expect(api).toBeInstanceOf(Api);
- expect(create.createProject).toHaveBeenCalledWith(
- testDir, jasmine.any(String), jasmine.any(String), testOpts
- );
- });
+ return Api.createPlatform(testDir, config, testOpts, new EventEmitter())
+ .then(api => {
+ expect(api).toBeInstanceOf(Api);
+ });
});
});
});
describe('project level Api', function () {
- const testApi = new Api();
+ let testApi = null;
+
+ beforeAll(() => {
+ const testDir = makeTempDir();
+
+ const testOpts = {};
+ const configXmlPath = path.join(__dirname, 'fixtures/default-config.xml');
+ const config = new ConfigParser(configXmlPath);
+
+ return Api.createPlatform(testDir, config, testOpts, new EventEmitter())
+ .then(api => {
+ testApi = api;
+ });
+ });
it('can be created', function () {
expect(testApi).toBeDefined();
@@ -102,15 +127,3 @@ describe('project level Api', function () {
expect(typeof testApi.getPlatformInfo).toBe('function');
});
});
-
-// Static methods
-// Static method: createPlatform
-// returns promise fulfilled with Api
-// emits error using provided emmitter on error
-
-// Static method: updatePlatform
-// returns a promise fulfilled with an Api
-// emits error using provided emmitter on error
-
-// Instance methods
-// requirements, clean, run, build, removePlugin, addPlugin, prepare, getPlatformInfo
diff --git a/bin/template/cordova/version b/templates/cordova/Api.js
old mode 100755
new mode 100644
similarity index 89%
copy from bin/template/cordova/version
copy to templates/cordova/Api.js
index 7b0de4c..1d12e88
--- a/bin/template/cordova/version
+++ b/templates/cordova/Api.js
@@ -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
@@ -19,7 +17,4 @@
under the License.
*/
-// Coho updates this line:
-const VERSION = '8.0.0-dev';
-
-console.log(VERSION);
+module.exports = require('cordova-browser');
diff --git a/bin/template/cordova/defaults.xml b/templates/cordova/defaults.xml
similarity index 100%
rename from bin/template/cordova/defaults.xml
rename to templates/cordova/defaults.xml
diff --git a/bin/template/cordova/version b/templates/cordova/version
similarity index 100%
rename from bin/template/cordova/version
rename to templates/cordova/version
diff --git a/bin/template/www/css/index.css b/templates/www/css/index.css
similarity index 100%
rename from bin/template/www/css/index.css
rename to templates/www/css/index.css
diff --git a/bin/template/www/favicon.ico b/templates/www/favicon.ico
similarity index 100%
rename from bin/template/www/favicon.ico
rename to templates/www/favicon.ico
diff --git a/bin/template/www/img/logo.png b/templates/www/img/logo.png
similarity index 100%
rename from bin/template/www/img/logo.png
rename to templates/www/img/logo.png
diff --git a/bin/template/www/img/splash.png b/templates/www/img/splash.png
similarity index 100%
rename from bin/template/www/img/splash.png
rename to templates/www/img/splash.png
diff --git a/bin/template/www/index.html b/templates/www/index.html
similarity index 100%
rename from bin/template/www/index.html
rename to templates/www/index.html
diff --git a/bin/template/www/js/index.js b/templates/www/js/index.js
similarity index 100%
rename from bin/template/www/js/index.js
rename to templates/www/js/index.js
diff --git a/bin/template/www/manifest.json b/templates/www/manifest.json
similarity index 100%
rename from bin/template/www/manifest.json
rename to templates/www/manifest.json
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org