Skip to content

Commit

Permalink
refactor!: do not copy JS lib to platform project (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphinesse committed Jul 13, 2021
1 parent f6d1dee commit 16ff6e1
Show file tree
Hide file tree
Showing 105 changed files with 89 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bin/templates/project/assets/www/cordova.js
templates/project/assets/www/cordova.js
test/android/app
test/androidx/app
2 changes: 1 addition & 1 deletion .ratignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.properties
bin
templates
gen
proguard-project.txt
spec
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 12 additions & 12 deletions bin/templates/cordova/Api.js → lib/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const VERSION = '10.0.0-dev';

var path = require('path');

var AndroidProject = require('./lib/AndroidProject');
var AndroidProject = require('./AndroidProject');
var PluginManager = require('cordova-common').PluginManager;

var CordovaLogger = require('cordova-common').CordovaLogger;
var selfEvents = require('cordova-common').events;
var ConfigParser = require('cordova-common').ConfigParser;
const prepare = require('./lib/prepare').prepare;
const prepare = require('./prepare').prepare;

var PLATFORM = 'android';

Expand Down Expand Up @@ -86,7 +86,7 @@ class Api {
javaSrc: path.join(appMain, 'java')
};

this._builder = require('./lib/builders/builders').getBuilder(this.root);
this._builder = require('./builders/builders').getBuilder(this.root);
}

/**
Expand Down Expand Up @@ -249,8 +249,8 @@ class Api {
build (buildOptions) {
var self = this;

return require('./lib/check_reqs').run().then(function () {
return require('./lib/build').run.call(self, buildOptions);
return require('./check_reqs').run().then(function () {
return require('./build').run.call(self, buildOptions);
}).then(function (buildResults) {
// Cast build result to array of build artifacts
return buildResults.paths.map(function (apkPath) {
Expand Down Expand Up @@ -278,8 +278,8 @@ class Api {
*/
run (runOptions) {
var self = this;
return require('./lib/check_reqs').run().then(function () {
return require('./lib/run').run.call(self, runOptions);
return require('./check_reqs').run().then(function () {
return require('./run').run.call(self, runOptions);
});
}

Expand All @@ -297,10 +297,10 @@ class Api {
cleanOptions = {};
}

return require('./lib/check_reqs').run().then(function () {
return require('./lib/build').runClean.call(self, cleanOptions);
return require('./check_reqs').run().then(function () {
return require('./build').runClean.call(self, cleanOptions);
}).then(function () {
return require('./lib/prepare').clean.call(self, cleanOptions);
return require('./prepare').clean.call(self, cleanOptions);
});
}

Expand All @@ -313,7 +313,7 @@ class Api {
* objects for current platform.
*/
requirements () {
return require('./lib/check_reqs').check_all(this.root);
return require('./check_reqs').check_all(this.root);
}

/**
Expand All @@ -338,7 +338,7 @@ class Api {
events = setupEvents(events);
var result;
try {
result = require('../../lib/create').create(destination, config, options, events).then(function (destination) {
result = require('./create').create(destination, config, options, events).then(function (destination) {
return new Api(PLATFORM, destination, events);
});
} catch (e) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class ProjectBuilder {
// Makes the project buildable, minus the gradle wrapper.
prepBuildFiles () {
// Update the version of build.gradle in each dependent library.
var pluginBuildGradle = path.join(this.root, 'cordova', 'lib', 'plugin-build.gradle');
var pluginBuildGradle = path.join(__dirname, 'plugin-build.gradle');
var propertiesObj = this.readProjectProperties();
var subProjects = propertiesObj.libs;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 11 additions & 15 deletions bin/lib/create.js → lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

var path = require('path');
var fs = require('fs-extra');
var utils = require('../templates/cordova/lib/utils');
var check_reqs = require('./../templates/cordova/lib/check_reqs');
var ROOT = path.join(__dirname, '..', '..');
var utils = require('./utils');
var check_reqs = require('./check_reqs');
var ROOT = path.join(__dirname, '..');
const { createEditor } = require('properties-parser');

var CordovaError = require('cordova-common').CordovaError;
var AndroidManifest = require('../templates/cordova/lib/AndroidManifest');
var AndroidManifest = require('./AndroidManifest');

// Export all helper functions, and make sure internally within this module, we
// reference these methods via the `exports` object - this helps with testing
Expand All @@ -45,7 +45,7 @@ function getFrameworkDir (projectPath, shared) {

function copyJsAndLibrary (projectPath, shared, projectName, targetAPI) {
var nestedCordovaLibPath = getFrameworkDir(projectPath, false);
var srcCordovaJsPath = path.join(ROOT, 'bin', 'templates', 'project', 'assets', 'www', 'cordova.js');
var srcCordovaJsPath = path.join(ROOT, 'templates', 'project', 'assets', 'www', 'cordova.js');
var app_path = path.join(projectPath, 'app', 'src', 'main');
const platform_www = path.join(projectPath, 'platform_www');

Expand Down Expand Up @@ -89,7 +89,7 @@ function extractSubProjectPaths (data) {

function writeProjectProperties (projectPath, target_api) {
var dstPath = path.join(projectPath, 'project.properties');
var templatePath = path.join(ROOT, 'bin', 'templates', 'project', 'project.properties');
var templatePath = path.join(ROOT, 'templates', 'project', 'project.properties');
var srcPath = fs.existsSync(dstPath) ? dstPath : templatePath;

var data = fs.readFileSync(srcPath, 'utf8');
Expand All @@ -113,12 +113,12 @@ function writeProjectProperties (projectPath, target_api) {

// This makes no sense, what if you're building with a different build system?
function prepBuildFiles (projectPath) {
var buildModule = require('../templates/cordova/lib/builders/builders');
var buildModule = require('./builders/builders');
buildModule.getBuilder(projectPath).prepBuildFiles();
}

function copyBuildRules (projectPath, isLegacy) {
var srcDir = path.join(ROOT, 'bin', 'templates', 'project');
var srcDir = path.join(ROOT, 'templates', 'project');

if (isLegacy) {
// The project's build.gradle is identical to the earlier build.gradle, so it should still work
Expand All @@ -134,16 +134,12 @@ function copyBuildRules (projectPath, isLegacy) {
}

function copyScripts (projectPath) {
var bin = path.join(ROOT, 'bin');
var srcScriptsDir = path.join(bin, 'templates', 'cordova');
var srcScriptsDir = path.join(ROOT, 'templates', 'cordova');
var destScriptsDir = path.join(projectPath, 'cordova');
// Delete old scripts directory if this is an update.
fs.removeSync(destScriptsDir);
// Copy in the new ones.
fs.copySync(srcScriptsDir, destScriptsDir);

const nodeModulesDir = path.join(ROOT, 'node_modules');
if (fs.existsSync(nodeModulesDir)) fs.copySync(nodeModulesDir, path.join(destScriptsDir, 'node_modules'));
}

/**
Expand Down Expand Up @@ -247,7 +243,7 @@ exports.create = function (project_path, config, options, events) {

events.emit('verbose', 'Copying android template project to ' + project_path);

var project_template_dir = options.customTemplate || path.join(ROOT, 'bin', 'templates', 'project');
var project_template_dir = options.customTemplate || path.join(ROOT, 'templates', 'project');
var app_path = path.join(project_path, 'app', 'src', 'main');

// copy project template
Expand Down Expand Up @@ -300,7 +296,7 @@ exports.create = function (project_path, config, options, events) {
};

function generateDoneMessage (type, link) {
var pkg = require('../../package');
var pkg = require('../package');
var msg = 'Android project ' + (type === 'update' ? 'updated ' : 'created ') + 'with ' + pkg.name + '@' + pkg.version;
if (link) {
msg += ' and has a linked CordovaLib';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ const ABS_MODULE_PATH = '/framework/cdv-gradle-config-defaults.json';

try {
// Try relative require first, …
const REPO_ROOT = '../../../..';
module.exports = require(REPO_ROOT + ABS_MODULE_PATH);
module.exports = require('..' + ABS_MODULE_PATH);
} catch (error) {
// … then fall back to installed-package require
if (error.code !== 'MODULE_NOT_FOUND') throw error;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cordova-android",
"version": "10.0.0-dev",
"description": "cordova-android release",
"main": "bin/templates/cordova/Api.js",
"main": "lib/Api.js",
"repository": "github:apache/cordova-android",
"bugs": "https://github.com/apache/cordova-android/issues",
"keywords": [
Expand All @@ -12,7 +12,7 @@
],
"scripts": {
"test": "npm run lint && npm run cover && npm run java-unit-tests",
"lint": "eslint . \"bin/**/!(*.*|gitignore)\"",
"lint": "eslint lib spec test \"templates/cordova/**/!(*.*)\"",
"unit-tests": "jasmine --config=spec/unit/jasmine.json",
"cover": "nyc jasmine --config=spec/coverage.json",
"e2e-tests": "jasmine --config=spec/e2e/jasmine.json",
Expand Down Expand Up @@ -45,8 +45,7 @@
},
"nyc": {
"include": [
"bin/lib/**",
"bin/templates/cordova/**"
"lib"
],
"reporter": [
"lcov",
Expand Down
4 changes: 2 additions & 2 deletions spec/e2e/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const fs = require('fs-extra');
const path = require('path');
const { EventEmitter } = require('events');
const { ConfigParser, PluginInfoProvider } = require('cordova-common');
const Api = require('../../bin/templates/cordova/Api');
const Api = require('../../lib/Api');

function makeTempDir () {
const tmpDirTemplate = path.join(os.tmpdir(), 'cordova-android-test-');
return fs.realpathSync(fs.mkdtempSync(tmpDirTemplate));
}

async function makeProject (projectPath) {
const configXmlPath = path.join(__dirname, '../../bin/templates/project/res/xml/config.xml');
const configXmlPath = path.join(__dirname, '../../templates/project/res/xml/config.xml');
const config = new ConfigParser(configXmlPath);
config.setPackageName('io.cordova.testapp');
config.setName('TestApp');
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/Adb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Adb', () => {
let execaSpy;

beforeEach(() => {
Adb = rewire('../../bin/templates/cordova/lib/Adb');
Adb = rewire('../../lib/Adb');
execaSpy = jasmine.createSpy('execa');
Adb.__set__('execa', execaSpy);
});
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/AndroidManifest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('AndroidManifest', () => {
beforeEach(() => {
createTempManifestFile(DEFAULT_MANIFEST);

AndroidManifest = rewire('../../bin/templates/cordova/lib/AndroidManifest');
AndroidManifest = rewire('../../lib/AndroidManifest');
manifest = new AndroidManifest(manifestPath);
});

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/AndroidProject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('AndroidProject', () => {
let AndroidStudioSpy;

beforeEach(() => {
AndroidProject = rewire('../../bin/templates/cordova/lib/AndroidProject');
AndroidProject = rewire('../../lib/AndroidProject');

AndroidStudioSpy = jasmine.createSpyObj('AndroidStudio', ['isAndroidStudioProject']);
AndroidProject.__set__('AndroidStudio', AndroidStudioSpy);
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/Api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var path = require('path');
var common = require('cordova-common');
const EventEmitter = require('events');

var Api = require('../../bin/templates/cordova/Api');
var AndroidProject = require('../../bin/templates/cordova/lib/AndroidProject');
var Api = require('../../lib/Api');
var AndroidProject = require('../../lib/AndroidProject');

var PluginInfo = common.PluginInfo;

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/android_sdk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('android_sdk', () => {
let execaSpy;

beforeEach(() => {
android_sdk = rewire('../../bin/templates/cordova/lib/android_sdk');
android_sdk = rewire('../../lib/android_sdk');
execaSpy = jasmine.createSpy('execa');
android_sdk.__set__('execa', execaSpy);
});
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/builders/ProjectBuilder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('ProjectBuilder', () => {

beforeEach(() => {
execaSpy = jasmine.createSpy('execa').and.returnValue(new Promise(() => {}));
ProjectBuilder = rewire('../../../bin/templates/cordova/lib/builders/ProjectBuilder');
ProjectBuilder = rewire('../../../lib/builders/ProjectBuilder');
ProjectBuilder.__set__('execa', execaSpy);

builder = new ProjectBuilder(rootDir);
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/builders/builders.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
const rewire = require('rewire');

const CordovaError = require('cordova-common').CordovaError;
const ProjectBuilder = require('../../../bin/templates/cordova/lib/builders/ProjectBuilder');
const ProjectBuilder = require('../../../lib/builders/ProjectBuilder');

describe('builders', () => {
let builders;

beforeEach(() => {
builders = rewire('../../../bin/templates/cordova/lib/builders/builders');
builders = rewire('../../../lib/builders/builders');
});

describe('getBuilder', () => {
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/check_reqs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
*/

var rewire = require('rewire');
var android_sdk = require('../../bin/templates/cordova/lib/android_sdk');
var android_sdk = require('../../lib/android_sdk');
var fs = require('fs-extra');
var path = require('path');
var events = require('cordova-common').events;
var which = require('which');

const {
SDK_VERSION: DEFAULT_TARGET_API
} = require('../../bin/templates/cordova/lib/gradle-config-defaults');
} = require('../../lib/gradle-config-defaults');

describe('check_reqs', function () {
let check_reqs;
beforeEach(() => {
check_reqs = rewire('../../bin/templates/cordova/lib/check_reqs');
check_reqs = rewire('../../lib/check_reqs');
});

var original_env;
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/config/GradlePropertiesParser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

const rewire = require('rewire');
const GradlePropertiesParser = rewire('../../../bin/templates/cordova/lib/config/GradlePropertiesParser');
const GradlePropertiesParser = rewire('../../../lib/config/GradlePropertiesParser');

describe('Gradle Builder', () => {
describe('_initializeEditor method', () => {
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/

var rewire = require('rewire');
var utils = require('../../bin/templates/cordova/lib/utils');
var create = rewire('../../bin/lib/create');
var check_reqs = require('../../bin/templates/cordova/lib/check_reqs');
var utils = require('../../lib/utils');
var create = rewire('../../lib/create');
var check_reqs = require('../../lib/check_reqs');
var fs = require('fs-extra');
var path = require('path');

Expand Down Expand Up @@ -117,7 +117,7 @@ describe('create', function () {
var revert_manifest_mock;
var project_path = path.join('some', 'path');
var app_path = path.join(project_path, 'app', 'src', 'main');
var default_templates = path.join(__dirname, '..', '..', 'bin', 'templates', 'project');
var default_templates = path.join(__dirname, '..', '..', 'templates', 'project');
var fake_android_target = 'android-1337';

beforeEach(function () {
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/emulator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('emulator', () => {
let emu;

beforeEach(() => {
emu = rewire('../../bin/templates/cordova/lib/emulator');
emu = rewire('../../lib/emulator');
});

describe('list_images_using_avdmanager', () => {
Expand Down Expand Up @@ -376,7 +376,7 @@ describe('emulator', () => {
// If we use Jasmine's fake clock, we need to re-require the target module,
// or else it will not work.
jasmine.clock().install();
emu = rewire('../../bin/templates/cordova/lib/emulator');
emu = rewire('../../lib/emulator');

AdbSpy = jasmine.createSpyObj('Adb', ['shell']);
emu.__set__('Adb', AdbSpy);
Expand Down

0 comments on commit 16ff6e1

Please sign in to comment.