Skip to content

Commit 16ff6e1

Browse files
authored
refactor!: do not copy JS lib to platform project (apache#1269)
1 parent f6d1dee commit 16ff6e1

File tree

105 files changed

+89
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+89
-75
lines changed

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
bin/templates/project/assets/www/cordova.js
1+
templates/project/assets/www/cordova.js
22
test/android/app
33
test/androidx/app

.ratignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
*.properties
2-
bin
2+
templates
33
gen
44
proguard-project.txt
55
spec
File renamed without changes.
File renamed without changes.
File renamed without changes.

bin/templates/cordova/Api.js lib/Api.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ const VERSION = '10.0.0-dev';
2828

2929
var path = require('path');
3030

31-
var AndroidProject = require('./lib/AndroidProject');
31+
var AndroidProject = require('./AndroidProject');
3232
var PluginManager = require('cordova-common').PluginManager;
3333

3434
var CordovaLogger = require('cordova-common').CordovaLogger;
3535
var selfEvents = require('cordova-common').events;
3636
var ConfigParser = require('cordova-common').ConfigParser;
37-
const prepare = require('./lib/prepare').prepare;
37+
const prepare = require('./prepare').prepare;
3838

3939
var PLATFORM = 'android';
4040

@@ -86,7 +86,7 @@ class Api {
8686
javaSrc: path.join(appMain, 'java')
8787
};
8888

89-
this._builder = require('./lib/builders/builders').getBuilder(this.root);
89+
this._builder = require('./builders/builders').getBuilder(this.root);
9090
}
9191

9292
/**
@@ -249,8 +249,8 @@ class Api {
249249
build (buildOptions) {
250250
var self = this;
251251

252-
return require('./lib/check_reqs').run().then(function () {
253-
return require('./lib/build').run.call(self, buildOptions);
252+
return require('./check_reqs').run().then(function () {
253+
return require('./build').run.call(self, buildOptions);
254254
}).then(function (buildResults) {
255255
// Cast build result to array of build artifacts
256256
return buildResults.paths.map(function (apkPath) {
@@ -278,8 +278,8 @@ class Api {
278278
*/
279279
run (runOptions) {
280280
var self = this;
281-
return require('./lib/check_reqs').run().then(function () {
282-
return require('./lib/run').run.call(self, runOptions);
281+
return require('./check_reqs').run().then(function () {
282+
return require('./run').run.call(self, runOptions);
283283
});
284284
}
285285

@@ -297,10 +297,10 @@ class Api {
297297
cleanOptions = {};
298298
}
299299

300-
return require('./lib/check_reqs').run().then(function () {
301-
return require('./lib/build').runClean.call(self, cleanOptions);
300+
return require('./check_reqs').run().then(function () {
301+
return require('./build').runClean.call(self, cleanOptions);
302302
}).then(function () {
303-
return require('./lib/prepare').clean.call(self, cleanOptions);
303+
return require('./prepare').clean.call(self, cleanOptions);
304304
});
305305
}
306306

@@ -313,7 +313,7 @@ class Api {
313313
* objects for current platform.
314314
*/
315315
requirements () {
316-
return require('./lib/check_reqs').check_all(this.root);
316+
return require('./check_reqs').check_all(this.root);
317317
}
318318

319319
/**
@@ -338,7 +338,7 @@ class Api {
338338
events = setupEvents(events);
339339
var result;
340340
try {
341-
result = require('../../lib/create').create(destination, config, options, events).then(function (destination) {
341+
result = require('./create').create(destination, config, options, events).then(function (destination) {
342342
return new Api(PLATFORM, destination, events);
343343
});
344344
} catch (e) {
File renamed without changes.
File renamed without changes.
File renamed without changes.

bin/templates/cordova/lib/builders/ProjectBuilder.js lib/builders/ProjectBuilder.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class ProjectBuilder {
160160
// Makes the project buildable, minus the gradle wrapper.
161161
prepBuildFiles () {
162162
// Update the version of build.gradle in each dependent library.
163-
var pluginBuildGradle = path.join(this.root, 'cordova', 'lib', 'plugin-build.gradle');
163+
var pluginBuildGradle = path.join(__dirname, 'plugin-build.gradle');
164164
var propertiesObj = this.readProjectProperties();
165165
var subProjects = propertiesObj.libs;
166166

File renamed without changes.
File renamed without changes.
File renamed without changes.

bin/lib/create.js lib/create.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
var path = require('path');
2121
var fs = require('fs-extra');
22-
var utils = require('../templates/cordova/lib/utils');
23-
var check_reqs = require('./../templates/cordova/lib/check_reqs');
24-
var ROOT = path.join(__dirname, '..', '..');
22+
var utils = require('./utils');
23+
var check_reqs = require('./check_reqs');
24+
var ROOT = path.join(__dirname, '..');
2525
const { createEditor } = require('properties-parser');
2626

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

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

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

@@ -89,7 +89,7 @@ function extractSubProjectPaths (data) {
8989

9090
function writeProjectProperties (projectPath, target_api) {
9191
var dstPath = path.join(projectPath, 'project.properties');
92-
var templatePath = path.join(ROOT, 'bin', 'templates', 'project', 'project.properties');
92+
var templatePath = path.join(ROOT, 'templates', 'project', 'project.properties');
9393
var srcPath = fs.existsSync(dstPath) ? dstPath : templatePath;
9494

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

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

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

123123
if (isLegacy) {
124124
// 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) {
134134
}
135135

136136
function copyScripts (projectPath) {
137-
var bin = path.join(ROOT, 'bin');
138-
var srcScriptsDir = path.join(bin, 'templates', 'cordova');
137+
var srcScriptsDir = path.join(ROOT, 'templates', 'cordova');
139138
var destScriptsDir = path.join(projectPath, 'cordova');
140139
// Delete old scripts directory if this is an update.
141140
fs.removeSync(destScriptsDir);
142141
// Copy in the new ones.
143142
fs.copySync(srcScriptsDir, destScriptsDir);
144-
145-
const nodeModulesDir = path.join(ROOT, 'node_modules');
146-
if (fs.existsSync(nodeModulesDir)) fs.copySync(nodeModulesDir, path.join(destScriptsDir, 'node_modules'));
147143
}
148144

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

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

250-
var project_template_dir = options.customTemplate || path.join(ROOT, 'bin', 'templates', 'project');
246+
var project_template_dir = options.customTemplate || path.join(ROOT, 'templates', 'project');
251247
var app_path = path.join(project_path, 'app', 'src', 'main');
252248

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

302298
function generateDoneMessage (type, link) {
303-
var pkg = require('../../package');
299+
var pkg = require('../package');
304300
var msg = 'Android project ' + (type === 'update' ? 'updated ' : 'created ') + 'with ' + pkg.name + '@' + pkg.version;
305301
if (link) {
306302
msg += ' and has a linked CordovaLib';
File renamed without changes.
File renamed without changes.
File renamed without changes.

bin/templates/cordova/lib/gradle-config-defaults.js lib/gradle-config-defaults.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ const ABS_MODULE_PATH = '/framework/cdv-gradle-config-defaults.json';
2121

2222
try {
2323
// Try relative require first, …
24-
const REPO_ROOT = '../../../..';
25-
module.exports = require(REPO_ROOT + ABS_MODULE_PATH);
24+
module.exports = require('..' + ABS_MODULE_PATH);
2625
} catch (error) {
2726
// … then fall back to installed-package require
2827
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.

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cordova-android",
33
"version": "10.0.0-dev",
44
"description": "cordova-android release",
5-
"main": "bin/templates/cordova/Api.js",
5+
"main": "lib/Api.js",
66
"repository": "github:apache/cordova-android",
77
"bugs": "https://github.com/apache/cordova-android/issues",
88
"keywords": [
@@ -12,7 +12,7 @@
1212
],
1313
"scripts": {
1414
"test": "npm run lint && npm run cover && npm run java-unit-tests",
15-
"lint": "eslint . \"bin/**/!(*.*|gitignore)\"",
15+
"lint": "eslint lib spec test \"templates/cordova/**/!(*.*)\"",
1616
"unit-tests": "jasmine --config=spec/unit/jasmine.json",
1717
"cover": "nyc jasmine --config=spec/coverage.json",
1818
"e2e-tests": "jasmine --config=spec/e2e/jasmine.json",
@@ -45,8 +45,7 @@
4545
},
4646
"nyc": {
4747
"include": [
48-
"bin/lib/**",
49-
"bin/templates/cordova/**"
48+
"lib"
5049
],
5150
"reporter": [
5251
"lcov",

spec/e2e/e2e.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ const fs = require('fs-extra');
2222
const path = require('path');
2323
const { EventEmitter } = require('events');
2424
const { ConfigParser, PluginInfoProvider } = require('cordova-common');
25-
const Api = require('../../bin/templates/cordova/Api');
25+
const Api = require('../../lib/Api');
2626

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

3232
async function makeProject (projectPath) {
33-
const configXmlPath = path.join(__dirname, '../../bin/templates/project/res/xml/config.xml');
33+
const configXmlPath = path.join(__dirname, '../../templates/project/res/xml/config.xml');
3434
const config = new ConfigParser(configXmlPath);
3535
config.setPackageName('io.cordova.testapp');
3636
config.setName('TestApp');

spec/unit/Adb.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('Adb', () => {
3838
let execaSpy;
3939

4040
beforeEach(() => {
41-
Adb = rewire('../../bin/templates/cordova/lib/Adb');
41+
Adb = rewire('../../lib/Adb');
4242
execaSpy = jasmine.createSpy('execa');
4343
Adb.__set__('execa', execaSpy);
4444
});

spec/unit/AndroidManifest.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('AndroidManifest', () => {
6666
beforeEach(() => {
6767
createTempManifestFile(DEFAULT_MANIFEST);
6868

69-
AndroidManifest = rewire('../../bin/templates/cordova/lib/AndroidManifest');
69+
AndroidManifest = rewire('../../lib/AndroidManifest');
7070
manifest = new AndroidManifest(manifestPath);
7171
});
7272

spec/unit/AndroidProject.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('AndroidProject', () => {
2626
let AndroidStudioSpy;
2727

2828
beforeEach(() => {
29-
AndroidProject = rewire('../../bin/templates/cordova/lib/AndroidProject');
29+
AndroidProject = rewire('../../lib/AndroidProject');
3030

3131
AndroidStudioSpy = jasmine.createSpyObj('AndroidStudio', ['isAndroidStudioProject']);
3232
AndroidProject.__set__('AndroidStudio', AndroidStudioSpy);

spec/unit/Api.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ var path = require('path');
2222
var common = require('cordova-common');
2323
const EventEmitter = require('events');
2424

25-
var Api = require('../../bin/templates/cordova/Api');
26-
var AndroidProject = require('../../bin/templates/cordova/lib/AndroidProject');
25+
var Api = require('../../lib/Api');
26+
var AndroidProject = require('../../lib/AndroidProject');
2727

2828
var PluginInfo = common.PluginInfo;
2929

spec/unit/android_sdk.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('android_sdk', () => {
2626
let execaSpy;
2727

2828
beforeEach(() => {
29-
android_sdk = rewire('../../bin/templates/cordova/lib/android_sdk');
29+
android_sdk = rewire('../../lib/android_sdk');
3030
execaSpy = jasmine.createSpy('execa');
3131
android_sdk.__set__('execa', execaSpy);
3232
});

spec/unit/builders/ProjectBuilder.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('ProjectBuilder', () => {
3232

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

3838
builder = new ProjectBuilder(rootDir);

spec/unit/builders/builders.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
const rewire = require('rewire');
2121

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

2525
describe('builders', () => {
2626
let builders;
2727

2828
beforeEach(() => {
29-
builders = rewire('../../../bin/templates/cordova/lib/builders/builders');
29+
builders = rewire('../../../lib/builders/builders');
3030
});
3131

3232
describe('getBuilder', () => {

spec/unit/check_reqs.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
*/
1919

2020
var rewire = require('rewire');
21-
var android_sdk = require('../../bin/templates/cordova/lib/android_sdk');
21+
var android_sdk = require('../../lib/android_sdk');
2222
var fs = require('fs-extra');
2323
var path = require('path');
2424
var events = require('cordova-common').events;
2525
var which = require('which');
2626

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

3131
describe('check_reqs', function () {
3232
let check_reqs;
3333
beforeEach(() => {
34-
check_reqs = rewire('../../bin/templates/cordova/lib/check_reqs');
34+
check_reqs = rewire('../../lib/check_reqs');
3535
});
3636

3737
var original_env;

spec/unit/config/GradlePropertiesParser.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
const rewire = require('rewire');
21-
const GradlePropertiesParser = rewire('../../../bin/templates/cordova/lib/config/GradlePropertiesParser');
21+
const GradlePropertiesParser = rewire('../../../lib/config/GradlePropertiesParser');
2222

2323
describe('Gradle Builder', () => {
2424
describe('_initializeEditor method', () => {

spec/unit/create.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
*/
1919

2020
var rewire = require('rewire');
21-
var utils = require('../../bin/templates/cordova/lib/utils');
22-
var create = rewire('../../bin/lib/create');
23-
var check_reqs = require('../../bin/templates/cordova/lib/check_reqs');
21+
var utils = require('../../lib/utils');
22+
var create = rewire('../../lib/create');
23+
var check_reqs = require('../../lib/check_reqs');
2424
var fs = require('fs-extra');
2525
var path = require('path');
2626

@@ -117,7 +117,7 @@ describe('create', function () {
117117
var revert_manifest_mock;
118118
var project_path = path.join('some', 'path');
119119
var app_path = path.join(project_path, 'app', 'src', 'main');
120-
var default_templates = path.join(__dirname, '..', '..', 'bin', 'templates', 'project');
120+
var default_templates = path.join(__dirname, '..', '..', 'templates', 'project');
121121
var fake_android_target = 'android-1337';
122122

123123
beforeEach(function () {

spec/unit/emulator.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('emulator', () => {
2828
let emu;
2929

3030
beforeEach(() => {
31-
emu = rewire('../../bin/templates/cordova/lib/emulator');
31+
emu = rewire('../../lib/emulator');
3232
});
3333

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

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

0 commit comments

Comments
 (0)