Skip to content
Permalink
Browse files
refactor!: do not copy JS lib to platform project (#1269)
  • Loading branch information
raphinesse committed Jul 13, 2021
1 parent f6d1dee commit 16ff6e1b2fe1d29b47fed3411299173a9eb85487
Showing 105 changed files with 89 additions and 75 deletions.
@@ -1,3 +1,3 @@
bin/templates/project/assets/www/cordova.js
templates/project/assets/www/cordova.js
test/android/app
test/androidx/app
@@ -1,5 +1,5 @@
*.properties
bin
templates
gen
proguard-project.txt
spec
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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';

@@ -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);
}

/**
@@ -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) {
@@ -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);
});
}

@@ -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);
});
}

@@ -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);
}

/**
@@ -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) {
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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;

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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
@@ -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');

@@ -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');
@@ -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
@@ -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'));
}

/**
@@ -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
@@ -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';
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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": [
@@ -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",
@@ -45,8 +45,7 @@
},
"nyc": {
"include": [
"bin/lib/**",
"bin/templates/cordova/**"
"lib"
],
"reporter": [
"lcov",
@@ -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');
@@ -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);
});
@@ -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);
});

@@ -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);
@@ -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;

@@ -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);
});
@@ -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);
@@ -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', () => {
@@ -18,20 +18,20 @@
*/

var rewire = require('rewire'