Skip to content

Commit

Permalink
breaking: Removed TempateFile class
Browse files Browse the repository at this point in the history
Replaced the one and only usage of it with the properties-parser editor.
Breaking change because we are converting a method into an asynchronous
method.
  • Loading branch information
breautek committed Apr 25, 2021
1 parent e7d8cd9 commit feeee5d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 48 deletions.
17 changes: 11 additions & 6 deletions bin/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var fs = require('fs-extra');
var utils = require('../templates/cordova/lib/utils');
var constants = require('../../framework/defaults.json');
var ROOT = path.join(__dirname, '..', '..');
const TemplateFile = require('../templates/cordova/lib/TemplateFile');
const { createEditor } = require('properties-parser');

var CordovaError = require('cordova-common').CordovaError;
var AndroidManifest = require('../templates/cordova/lib/AndroidManifest');
Expand All @@ -43,7 +43,7 @@ function getFrameworkDir (projectPath, shared) {
return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 'CordovaLib');
}

function copyJsAndLibrary (projectPath, shared, projectName, targetAPI) {
async function copyJsAndLibrary (projectPath, shared, projectName, targetAPI) {
var nestedCordovaLibPath = getFrameworkDir(projectPath, false);
var srcCordovaJsPath = path.join(ROOT, 'bin', 'templates', 'project', 'assets', 'www', 'cordova.js');
var app_path = path.join(projectPath, 'app', 'src', 'main');
Expand All @@ -66,8 +66,13 @@ function copyJsAndLibrary (projectPath, shared, projectName, targetAPI) {
} else {
fs.ensureDirSync(nestedCordovaLibPath);
fs.copySync(path.join(ROOT, 'framework', 'AndroidManifest.xml'), path.join(nestedCordovaLibPath, 'AndroidManifest.xml'));
TemplateFile.render(path.join(ROOT, 'framework', 'project.properties'), path.join(nestedCordovaLibPath, 'project.properties'), {
SDK_VERSION: targetAPI || constants.SDK_VERSION
await new Promise((resolve) => {
const propertiesEditor = createEditor(path.join(ROOT, 'framework', 'project.properties'));

// properties-editor will silently fail (write empty string) if value is not a string.
propertiesEditor.set('target', (targetAPI || constants.SDK_VERSION).toString());

propertiesEditor.save(path.join(nestedCordovaLibPath, 'project.properties'), resolve);
});
fs.copySync(path.join(ROOT, 'framework', 'build.gradle'), path.join(nestedCordovaLibPath, 'build.gradle'));
fs.copySync(path.join(ROOT, 'framework', 'cordova.gradle'), path.join(nestedCordovaLibPath, 'cordova.gradle'));
Expand Down Expand Up @@ -256,7 +261,7 @@ exports.create = function (project_path, config, options, events) {
return exports.validatePackageName(package_name)
.then(function () {
return exports.validateProjectName(project_name);
}).then(function () {
}).then(async function () {
// Log the given values for the project
events.emit('log', 'Creating Cordova project for the Android platform:');
events.emit('log', '\tPath: ' + project_path);
Expand All @@ -280,7 +285,7 @@ exports.create = function (project_path, config, options, events) {
fs.ensureDirSync(path.join(app_path, 'libs'));

// copy cordova.js, cordova.jar
exports.copyJsAndLibrary(project_path, options.link, safe_activity_name, target_api);
await exports.copyJsAndLibrary(project_path, options.link, safe_activity_name, target_api);

// Set up ther Android Studio paths
var java_path = path.join(app_path, 'java');
Expand Down
41 changes: 0 additions & 41 deletions bin/templates/cordova/lib/TemplateFile.js

This file was deleted.

3 changes: 2 additions & 1 deletion framework/project.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# GENERATED FILE! DO NOT EDIT!

# This file was originally created by the Android Tools, but is now
# used by cordova-android to manage the project configuration.

# Indicates whether an apk should be generated for each density.
split.density=false

# Project target.
target=android-{{SDK_VERSION}}
apk-configurations=
renderscript.opt.level=O0
android.library=true

0 comments on commit feeee5d

Please sign in to comment.