mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-24 18:12:54 +08:00
refactor: replace fs-extra with node:fs (#1772)
* spec: add devDependencies "tmp"
This commit is contained in:
parent
b623311efa
commit
e012478537
@ -17,7 +17,7 @@
|
||||
under the License.
|
||||
*/
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const execa = require('execa');
|
||||
const glob = require('fast-glob');
|
||||
@ -174,7 +174,7 @@ class ProjectBuilder {
|
||||
try {
|
||||
fs.accessSync(subProjectGradle, fs.F_OK);
|
||||
} catch (e) {
|
||||
fs.copySync(pluginBuildGradle, subProjectGradle);
|
||||
fs.cpSync(pluginBuildGradle, subProjectGradle);
|
||||
}
|
||||
};
|
||||
|
||||
@ -207,7 +207,7 @@ class ProjectBuilder {
|
||||
settingsGradlePaths.join(''));
|
||||
|
||||
// Touch empty cdv-gradle-name.gradle file if missing.
|
||||
if (!fs.pathExistsSync(path.join(this.root, 'cdv-gradle-name.gradle'))) {
|
||||
if (!fs.existsSync(path.join(this.root, 'cdv-gradle-name.gradle'))) {
|
||||
fs.writeFileSync(path.join(this.root, 'cdv-gradle-name.gradle'), '');
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ class ProjectBuilder {
|
||||
}).then(() => {
|
||||
const signingPropertiesPath = path.join(self.root, `${opts.buildType}${SIGNING_PROPERTIES}`);
|
||||
|
||||
if (fs.existsSync(signingPropertiesPath)) fs.removeSync(signingPropertiesPath);
|
||||
if (fs.existsSync(signingPropertiesPath)) fs.rmSync(signingPropertiesPath);
|
||||
if (opts.packageInfo) {
|
||||
fs.ensureFileSync(signingPropertiesPath);
|
||||
const signingProperties = createEditor(signingPropertiesPath);
|
||||
@ -309,7 +309,7 @@ class ProjectBuilder {
|
||||
* @returns The user defined configs
|
||||
*/
|
||||
_getCordovaConfig () {
|
||||
return fs.readJSONSync(path.join(this.root, 'cdv-gradle-config.json'));
|
||||
return JSON.parse(fs.readFileSync(path.join(this.root, 'cdv-gradle-config.json'), 'utf-8') || '{}');
|
||||
}
|
||||
|
||||
/*
|
||||
@ -342,7 +342,7 @@ class ProjectBuilder {
|
||||
const args = this.getArgs('clean', opts);
|
||||
return execa(wrapper, args, { stdio: 'inherit', cwd: path.resolve(this.root) })
|
||||
.then(() => {
|
||||
fs.removeSync(path.join(this.root, 'out'));
|
||||
fs.rmSync(path.join(this.root, 'out'), { recursive: true, force: true });
|
||||
|
||||
['debug', 'release'].map(config => path.join(this.root, `${config}${SIGNING_PROPERTIES}`))
|
||||
.forEach(file => {
|
||||
@ -350,7 +350,7 @@ class ProjectBuilder {
|
||||
const hasMarker = hasFile && fs.readFileSync(file, 'utf8')
|
||||
.includes(MARKER);
|
||||
|
||||
if (hasFile && hasMarker) fs.removeSync(file);
|
||||
if (hasFile && hasMarker) fs.rmSync(file);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
const execa = require('execa');
|
||||
const path = require('node:path');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const { forgivingWhichSync, isWindows, isDarwin } = require('./utils');
|
||||
const java = require('./env/java');
|
||||
const { CordovaError, ConfigParser, events } = require('cordova-common');
|
||||
|
@ -17,7 +17,7 @@
|
||||
under the License.
|
||||
*/
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const events = require('cordova-common').events;
|
||||
|
||||
@ -41,7 +41,7 @@ class CordovaGradleConfigParser {
|
||||
* @returns {Record<any, any>} The parsed JSON object representing the gradle config.
|
||||
*/
|
||||
_readConfig (configPath) {
|
||||
return fs.readJSONSync(configPath, 'utf-8');
|
||||
return JSON.parse(fs.readFileSync(configPath, 'utf-8') || '{}');
|
||||
}
|
||||
|
||||
setPackageName (packageName) {
|
||||
@ -64,7 +64,7 @@ class CordovaGradleConfigParser {
|
||||
*/
|
||||
write () {
|
||||
events.emit('verbose', '[Cordova Gradle Config] Saving File');
|
||||
fs.writeJSONSync(this._cdvGradleConfigFilePath, this._cdvGradleConfig, 'utf-8');
|
||||
fs.writeFileSync(this._cdvGradleConfigFilePath, JSON.stringify(this._cdvGradleConfig, null, 2), 'utf-8');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
const path = require('node:path');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const utils = require('./utils');
|
||||
const check_reqs = require('./check_reqs');
|
||||
const ROOT = path.join(__dirname, '..');
|
||||
@ -49,27 +49,27 @@ function copyJsAndLibrary (projectPath, shared, projectName, targetAPI) {
|
||||
const app_path = path.join(projectPath, 'app', 'src', 'main');
|
||||
const platform_www = path.join(projectPath, 'platform_www');
|
||||
|
||||
fs.copySync(srcCordovaJsPath, path.join(app_path, 'assets', 'www', 'cordova.js'));
|
||||
fs.cpSync(srcCordovaJsPath, path.join(app_path, 'assets', 'www', 'cordova.js'));
|
||||
|
||||
// Copy the cordova.js file to platforms/<platform>/platform_www/
|
||||
// The www dir is nuked on each prepare so we keep cordova.js in platform_www
|
||||
fs.ensureDirSync(platform_www);
|
||||
fs.copySync(srcCordovaJsPath, path.join(platform_www, 'cordova.js'));
|
||||
fs.copySync(path.join(ROOT, 'framework', 'cdv-gradle-config-defaults.json'), path.join(projectPath, 'cdv-gradle-config.json'));
|
||||
fs.mkdirSync(platform_www, { recursive: true });
|
||||
fs.cpSync(srcCordovaJsPath, path.join(platform_www, 'cordova.js'));
|
||||
fs.cpSync(path.join(ROOT, 'framework', 'cdv-gradle-config-defaults.json'), path.join(projectPath, 'cdv-gradle-config.json'));
|
||||
|
||||
if (shared) {
|
||||
const relativeFrameworkPath = path.relative(projectPath, getFrameworkDir(projectPath, true));
|
||||
fs.symlinkSync(relativeFrameworkPath, nestedCordovaLibPath, 'dir');
|
||||
} else {
|
||||
fs.ensureDirSync(nestedCordovaLibPath);
|
||||
fs.copySync(path.join(ROOT, 'framework', 'AndroidManifest.xml'), path.join(nestedCordovaLibPath, 'AndroidManifest.xml'));
|
||||
fs.mkdirSync(nestedCordovaLibPath, { recursive: true });
|
||||
fs.cpSync(path.join(ROOT, 'framework', 'AndroidManifest.xml'), path.join(nestedCordovaLibPath, 'AndroidManifest.xml'));
|
||||
const propertiesEditor = createEditor(path.join(ROOT, 'framework', 'project.properties'));
|
||||
propertiesEditor.set('target', targetAPI);
|
||||
propertiesEditor.save(path.join(nestedCordovaLibPath, 'project.properties'));
|
||||
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'));
|
||||
fs.copySync(path.join(ROOT, 'framework', 'repositories.gradle'), path.join(nestedCordovaLibPath, 'repositories.gradle'));
|
||||
fs.copySync(path.join(ROOT, 'framework', 'src'), path.join(nestedCordovaLibPath, 'src'));
|
||||
fs.cpSync(path.join(ROOT, 'framework', 'build.gradle'), path.join(nestedCordovaLibPath, 'build.gradle'));
|
||||
fs.cpSync(path.join(ROOT, 'framework', 'cordova.gradle'), path.join(nestedCordovaLibPath, 'cordova.gradle'));
|
||||
fs.cpSync(path.join(ROOT, 'framework', 'repositories.gradle'), path.join(nestedCordovaLibPath, 'repositories.gradle'));
|
||||
fs.cpSync(path.join(ROOT, 'framework', 'src'), path.join(nestedCordovaLibPath, 'src'), { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,10 +116,10 @@ function prepBuildFiles (projectPath) {
|
||||
function copyBuildRules (projectPath) {
|
||||
const srcDir = path.join(ROOT, 'templates', 'project');
|
||||
|
||||
fs.copySync(path.join(srcDir, 'build.gradle'), path.join(projectPath, 'build.gradle'));
|
||||
fs.copySync(path.join(srcDir, 'app', 'build.gradle'), path.join(projectPath, 'app', 'build.gradle'));
|
||||
fs.copySync(path.join(srcDir, 'app', 'repositories.gradle'), path.join(projectPath, 'app', 'repositories.gradle'));
|
||||
fs.copySync(path.join(srcDir, 'repositories.gradle'), path.join(projectPath, 'repositories.gradle'));
|
||||
fs.cpSync(path.join(srcDir, 'build.gradle'), path.join(projectPath, 'build.gradle'));
|
||||
fs.cpSync(path.join(srcDir, 'app', 'build.gradle'), path.join(projectPath, 'app', 'build.gradle'));
|
||||
fs.cpSync(path.join(srcDir, 'app', 'repositories.gradle'), path.join(projectPath, 'app', 'repositories.gradle'));
|
||||
fs.cpSync(path.join(srcDir, 'repositories.gradle'), path.join(projectPath, 'repositories.gradle'));
|
||||
|
||||
copyGradleTools(projectPath);
|
||||
}
|
||||
@ -128,9 +128,9 @@ function copyScripts (projectPath) {
|
||||
const srcScriptsDir = path.join(ROOT, 'templates', 'cordova');
|
||||
const destScriptsDir = path.join(projectPath, 'cordova');
|
||||
// Delete old scripts directory if this is an update.
|
||||
fs.removeSync(destScriptsDir);
|
||||
fs.rmSync(destScriptsDir, { recursive: true, force: true });
|
||||
// Copy in the new ones.
|
||||
fs.copySync(srcScriptsDir, destScriptsDir);
|
||||
fs.cpSync(srcScriptsDir, destScriptsDir, { recursive: true });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,7 +174,7 @@ function validateProjectName (project_name) {
|
||||
function copyGradleTools (projectPath) {
|
||||
const srcDir = path.join(ROOT, 'templates', 'project');
|
||||
|
||||
fs.copySync(path.resolve(srcDir, 'tools'), path.resolve(projectPath, 'tools'));
|
||||
fs.cpSync(path.resolve(srcDir, 'tools'), path.resolve(projectPath, 'tools'), { recursive: true });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,13 +232,13 @@ exports.create = function (project_path, config, options, events) {
|
||||
const app_path = path.join(project_path, 'app', 'src', 'main');
|
||||
|
||||
// copy project template
|
||||
fs.ensureDirSync(app_path);
|
||||
fs.copySync(path.join(project_template_dir, 'assets'), path.join(app_path, 'assets'));
|
||||
fs.copySync(path.join(project_template_dir, 'res'), path.join(app_path, 'res'));
|
||||
fs.copySync(path.join(project_template_dir, 'gitignore'), path.join(project_path, '.gitignore'));
|
||||
fs.mkdirSync(app_path, { recursive: true });
|
||||
fs.cpSync(path.join(project_template_dir, 'assets'), path.join(app_path, 'assets'), { recursive: true });
|
||||
fs.cpSync(path.join(project_template_dir, 'res'), path.join(app_path, 'res'), { recursive: true });
|
||||
fs.cpSync(path.join(project_template_dir, 'gitignore'), path.join(project_path, '.gitignore'));
|
||||
|
||||
// Manually create directories that would be empty within the template (since git doesn't track directories).
|
||||
fs.ensureDirSync(path.join(app_path, 'libs'));
|
||||
fs.mkdirSync(path.join(app_path, 'libs'), { recursive: true });
|
||||
|
||||
// copy cordova.js, cordova.jar
|
||||
exports.copyJsAndLibrary(project_path, options.link, safe_activity_name, target_api);
|
||||
@ -247,9 +247,9 @@ exports.create = function (project_path, config, options, events) {
|
||||
const java_path = path.join(app_path, 'java');
|
||||
const assets_path = path.join(app_path, 'assets');
|
||||
const resource_path = path.join(app_path, 'res');
|
||||
fs.ensureDirSync(java_path);
|
||||
fs.ensureDirSync(assets_path);
|
||||
fs.ensureDirSync(resource_path);
|
||||
fs.mkdirSync(java_path, { recursive: true });
|
||||
fs.mkdirSync(assets_path, { recursive: true });
|
||||
fs.mkdirSync(resource_path, { recursive: true });
|
||||
|
||||
// store package name in cdv-gradle-config
|
||||
const cdvGradleConfig = CordovaGradleConfigParserFactory.create(project_path);
|
||||
@ -261,8 +261,8 @@ exports.create = function (project_path, config, options, events) {
|
||||
const activity_dir = path.join(java_path, packagePath);
|
||||
const activity_path = path.join(activity_dir, safe_activity_name + '.java');
|
||||
|
||||
fs.ensureDirSync(activity_dir);
|
||||
fs.copySync(path.join(project_template_dir, 'Activity.java'), activity_path);
|
||||
fs.mkdirSync(activity_dir, { recursive: true });
|
||||
fs.cpSync(path.join(project_template_dir, 'Activity.java'), activity_path);
|
||||
utils.replaceFileContents(activity_path, /__ACTIVITY__/, safe_activity_name);
|
||||
utils.replaceFileContents(path.join(app_path, 'res', 'values', 'strings.xml'), /__NAME__/, utils.escape(project_name));
|
||||
utils.replaceFileContents(activity_path, /__ID__/, package_name);
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
const execa = require('execa');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const android_versions = require('android-versions');
|
||||
const path = require('node:path');
|
||||
const Adb = require('./Adb');
|
||||
|
2
lib/env/java.js
vendored
2
lib/env/java.js
vendored
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
const execa = require('execa');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const glob = require('fast-glob');
|
||||
const { CordovaError, events } = require('cordova-common');
|
||||
|
@ -14,7 +14,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const isPathInside = require('is-path-inside');
|
||||
const events = require('cordova-common').events;
|
||||
@ -166,13 +166,13 @@ const handlers = {
|
||||
scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) {\n' + scriptContent + '\n});\n';
|
||||
|
||||
const wwwDest = path.resolve(project.www, 'plugins', plugin.id, obj.src);
|
||||
fs.ensureDirSync(path.dirname(wwwDest));
|
||||
fs.mkdirSync(path.dirname(wwwDest), { recursive: true });
|
||||
fs.writeFileSync(wwwDest, scriptContent, 'utf-8');
|
||||
|
||||
if (options && options.usePlatformWww) {
|
||||
// CB-11022 copy file to both directories if usePlatformWww is specified
|
||||
const platformWwwDest = path.resolve(project.platformWww, 'plugins', plugin.id, obj.src);
|
||||
fs.ensureDirSync(path.dirname(platformWwwDest));
|
||||
fs.mkdirSync(path.dirname(platformWwwDest), { recursive: true });
|
||||
fs.writeFileSync(platformWwwDest, scriptContent, 'utf-8');
|
||||
}
|
||||
},
|
||||
@ -217,11 +217,11 @@ function copyFile (plugin_dir, src, project_dir, dest, link) {
|
||||
// check that dest path is located in project directory
|
||||
if (!isPathInside(dest, project_dir)) { throw new CordovaError('Destination "' + dest + '" for source file "' + src + '" is located outside the project'); }
|
||||
|
||||
fs.ensureDirSync(path.dirname(dest));
|
||||
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
||||
if (link) {
|
||||
symlinkFileOrDirTree(src, dest);
|
||||
} else {
|
||||
fs.copySync(src, dest);
|
||||
fs.cpSync(src, dest, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,11 +235,11 @@ function copyNewFile (plugin_dir, src, project_dir, dest, link) {
|
||||
|
||||
function symlinkFileOrDirTree (src, dest) {
|
||||
if (fs.existsSync(dest)) {
|
||||
fs.removeSync(dest);
|
||||
fs.rmSync(dest, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
if (fs.statSync(src).isDirectory()) {
|
||||
fs.ensureDirSync(path.dirname(dest));
|
||||
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
||||
fs.readdirSync(src).forEach(function (entry) {
|
||||
symlinkFileOrDirTree(path.join(src, entry), path.join(dest, entry));
|
||||
});
|
||||
@ -249,7 +249,7 @@ function symlinkFileOrDirTree (src, dest) {
|
||||
}
|
||||
|
||||
function removeFile (file) {
|
||||
fs.removeSync(file);
|
||||
fs.rmSync(file);
|
||||
}
|
||||
|
||||
// Sometimes we want to remove some java, and prune any unnecessary empty directories
|
||||
|
@ -17,7 +17,7 @@
|
||||
under the License.
|
||||
*/
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const nopt = require('nopt');
|
||||
const glob = require('fast-glob');
|
||||
@ -93,7 +93,7 @@ function updateUserProjectGradleConfig (project) {
|
||||
|
||||
// Write out changes
|
||||
const projectGradleConfigPath = path.join(project.root, 'cdv-gradle-config.json');
|
||||
fs.writeJSONSync(projectGradleConfigPath, projectGradleConfig, { spaces: 2 });
|
||||
fs.writeFileSync(projectGradleConfigPath, JSON.stringify(projectGradleConfig, null, 2), 'utf-8');
|
||||
}
|
||||
|
||||
function getUserGradleConfig (configXml) {
|
||||
@ -198,7 +198,7 @@ function updateConfigFilesFrom (sourceConfig, configMunger, locations) {
|
||||
|
||||
// First cleanup current config and merge project's one into own
|
||||
// Overwrite platform config.xml with defaults.xml.
|
||||
fs.copySync(locations.defaultConfigXml, locations.configXml);
|
||||
fs.cpSync(locations.defaultConfigXml, locations.configXml);
|
||||
|
||||
// Then apply config changes from global munge to all config files
|
||||
// in project (including project's config)
|
||||
@ -316,14 +316,14 @@ function updateProjectAccordingTo (platformConfig, locations) {
|
||||
const newDestFile = path.join(locations.root, 'app', 'src', 'main', 'java', androidPkgName.replace(/\./g, '/'), path.basename(destFile));
|
||||
if (newDestFile.toLowerCase() !== destFile.toLowerCase()) {
|
||||
// If package was name changed we need to create new java with main activity in path matching new package name
|
||||
fs.ensureDirSync(path.dirname(newDestFile));
|
||||
fs.mkdirSync(path.dirname(newDestFile), { recursive: true });
|
||||
events.emit('verbose', `copy ${destFile} to ${newDestFile}`);
|
||||
fs.copySync(destFile, newDestFile);
|
||||
fs.cpSync(destFile, newDestFile);
|
||||
utils.replaceFileContents(newDestFile, /package [\w.]*;/, 'package ' + androidPkgName + ';');
|
||||
events.emit('verbose', 'Wrote out Android package name "' + androidPkgName + '" to ' + newDestFile);
|
||||
// If package was name changed we need to remove old java with main activity
|
||||
events.emit('verbose', `remove ${destFile}`);
|
||||
fs.removeSync(destFile);
|
||||
fs.rmSync(destFile);
|
||||
// remove any empty directories
|
||||
let currentDir = path.dirname(destFile);
|
||||
const sourcesRoot = path.resolve(locations.root, 'src');
|
||||
@ -536,16 +536,16 @@ function updateProjectSplashScreenIconBackgroundColor (splashIconBackgroundColor
|
||||
|
||||
function cleanupAndSetProjectSplashScreenImage (srcFile, destFilePath, possiblePreviousDestFilePath, cleanupOnly = false) {
|
||||
if (fs.existsSync(possiblePreviousDestFilePath)) {
|
||||
fs.removeSync(possiblePreviousDestFilePath);
|
||||
fs.rmSync(possiblePreviousDestFilePath);
|
||||
}
|
||||
|
||||
if (cleanupOnly && fs.existsSync(destFilePath)) {
|
||||
// Also remove dest file path for cleanup even if previous was not use.
|
||||
fs.removeSync(destFilePath);
|
||||
fs.rmSync(destFilePath);
|
||||
}
|
||||
|
||||
if (!cleanupOnly && srcFile && fs.existsSync(srcFile)) {
|
||||
fs.copySync(srcFile, destFilePath);
|
||||
fs.cpSync(srcFile, destFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
// TODO: Perhaps this should live in cordova-common?
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const which = require('which');
|
||||
const os = require('node:os');
|
||||
|
||||
|
14
package-lock.json
generated
14
package-lock.json
generated
@ -14,7 +14,6 @@
|
||||
"dedent": "^1.5.3",
|
||||
"execa": "^5.1.1",
|
||||
"fast-glob": "^3.3.2",
|
||||
"fs-extra": "^11.2.0",
|
||||
"is-path-inside": "^3.0.3",
|
||||
"nopt": "^7.2.1",
|
||||
"properties-parser": "^0.6.0",
|
||||
@ -30,7 +29,8 @@
|
||||
"jasmine": "^5.1.0",
|
||||
"jasmine-spec-reporter": "^7.0.0",
|
||||
"nyc": "^15.1.0",
|
||||
"rewire": "^7.0.0"
|
||||
"rewire": "^7.0.0",
|
||||
"tmp": "^0.2.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.13.0"
|
||||
@ -4806,6 +4806,16 @@
|
||||
"integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/tmp": {
|
||||
"version": "0.2.3",
|
||||
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz",
|
||||
"integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=14.14"
|
||||
}
|
||||
},
|
||||
"node_modules/to-fast-properties": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
|
||||
|
@ -29,7 +29,6 @@
|
||||
"dedent": "^1.5.3",
|
||||
"execa": "^5.1.1",
|
||||
"fast-glob": "^3.3.2",
|
||||
"fs-extra": "^11.2.0",
|
||||
"is-path-inside": "^3.0.3",
|
||||
"nopt": "^7.2.1",
|
||||
"properties-parser": "^0.6.0",
|
||||
@ -45,7 +44,8 @@
|
||||
"jasmine": "^5.1.0",
|
||||
"jasmine-spec-reporter": "^7.0.0",
|
||||
"nyc": "^15.1.0",
|
||||
"rewire": "^7.0.0"
|
||||
"rewire": "^7.0.0",
|
||||
"tmp": "^0.2.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.13.0"
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
const os = require('node:os');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { EventEmitter } = require('events');
|
||||
const { ConfigParser, PluginInfoProvider } = require('cordova-common');
|
||||
@ -49,14 +49,15 @@ describe('E2E', function () {
|
||||
api = await makeProject(projectPath);
|
||||
});
|
||||
afterEach(() => {
|
||||
fs.removeSync(tmpDir);
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('loads the API from a project directory', async () => {
|
||||
// Allow test project to find the `cordova-android` module
|
||||
fs.ensureSymlinkSync(
|
||||
path.join(__dirname, '../..'),
|
||||
path.join(tmpDir, 'node_modules/cordova-android'),
|
||||
fs.mkdirSync(path.join(tmpDir, 'node_modules'), { recursive: true });
|
||||
fs.symlinkSync(
|
||||
path.join(__dirname, '..', '..'),
|
||||
path.join(tmpDir, 'node_modules', 'cordova-android'),
|
||||
'junction'
|
||||
);
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
under the License.
|
||||
*/
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const rewire = require('rewire');
|
||||
const { isWindows } = require('../../../lib/utils');
|
||||
@ -220,7 +220,7 @@ describe('ProjectBuilder', () => {
|
||||
beforeEach(() => {
|
||||
const marker = ProjectBuilder.__get__('MARKER');
|
||||
spyOn(fs, 'readFileSync').and.returnValue(`Some Header Here: ${marker}`);
|
||||
spyOn(fs, 'removeSync');
|
||||
spyOn(fs, 'rmSync');
|
||||
spyOn(builder, 'getArgs');
|
||||
execaSpy.and.returnValue(Promise.resolve());
|
||||
});
|
||||
@ -250,7 +250,7 @@ describe('ProjectBuilder', () => {
|
||||
|
||||
it('should remove "out" folder', () => {
|
||||
return builder.clean({}).then(() => {
|
||||
expect(fs.removeSync).toHaveBeenCalledWith(path.join(rootDir, 'out'));
|
||||
expect(fs.rmSync).toHaveBeenCalledWith(path.join(rootDir, 'out'), { recursive: true, force: true });
|
||||
});
|
||||
});
|
||||
|
||||
@ -261,8 +261,8 @@ describe('ProjectBuilder', () => {
|
||||
spyOn(fs, 'existsSync').and.returnValue(true);
|
||||
|
||||
return builder.clean({}).then(() => {
|
||||
expect(fs.removeSync).toHaveBeenCalledWith(debugSigningFile);
|
||||
expect(fs.removeSync).toHaveBeenCalledWith(releaseSigningFile);
|
||||
expect(fs.rmSync).toHaveBeenCalledWith(debugSigningFile);
|
||||
expect(fs.rmSync).toHaveBeenCalledWith(releaseSigningFile);
|
||||
});
|
||||
});
|
||||
|
||||
@ -273,8 +273,8 @@ describe('ProjectBuilder', () => {
|
||||
spyOn(fs, 'existsSync').and.returnValue(false);
|
||||
|
||||
return builder.clean({}).then(() => {
|
||||
expect(fs.removeSync).not.toHaveBeenCalledWith(debugSigningFile);
|
||||
expect(fs.removeSync).not.toHaveBeenCalledWith(releaseSigningFile);
|
||||
expect(fs.rmSync).not.toHaveBeenCalledWith(debugSigningFile);
|
||||
expect(fs.rmSync).not.toHaveBeenCalledWith(releaseSigningFile);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
const rewire = require('rewire');
|
||||
const android_sdk = require('../../lib/android_sdk');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const events = require('cordova-common').events;
|
||||
const which = require('which');
|
||||
|
@ -21,7 +21,7 @@ const rewire = require('rewire');
|
||||
const utils = require('../../lib/utils');
|
||||
const create = rewire('../../lib/create');
|
||||
const check_reqs = require('../../lib/check_reqs');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const MockCordovaGradleConfigParser = require('./mocks/config/MockCordovaGradleConfigParser');
|
||||
const CordovaGradleConfigParserFactory = require('../../lib/config/CordovaGradleConfigParserFactory');
|
||||
@ -142,8 +142,8 @@ describe('create', function () {
|
||||
spyOn(create, 'prepBuildFiles');
|
||||
revert_manifest_mock = create.__set__('AndroidManifest', Manifest_mock);
|
||||
spyOn(fs, 'existsSync').and.returnValue(false);
|
||||
spyOn(fs, 'copySync');
|
||||
spyOn(fs, 'ensureDirSync');
|
||||
spyOn(fs, 'cpSync');
|
||||
spyOn(fs, 'mkdirSync');
|
||||
spyOn(utils, 'replaceFileContents');
|
||||
config_mock = jasmine.createSpyObj('ConfigParser mock instance', ['packageName', 'android_packageName', 'name', 'android_activityName']);
|
||||
events_mock = jasmine.createSpyObj('EventEmitter mock instance', ['emit']);
|
||||
@ -238,17 +238,17 @@ describe('create', function () {
|
||||
describe('happy path', function () {
|
||||
it('should copy project templates from a specified custom template', () => {
|
||||
return create.create(project_path, config_mock, { customTemplate: '/template/path' }, events_mock).then(() => {
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join('/template/path', 'assets'), path.join(app_path, 'assets'));
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join('/template/path', 'res'), path.join(app_path, 'res'));
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join('/template/path', 'gitignore'), path.join(project_path, '.gitignore'));
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join('/template/path', 'assets'), path.join(app_path, 'assets'), { recursive: true });
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join('/template/path', 'res'), path.join(app_path, 'res'), { recursive: true });
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join('/template/path', 'gitignore'), path.join(project_path, '.gitignore'));
|
||||
});
|
||||
});
|
||||
|
||||
it('should copy project templates from the default templates location if no custom template is provided', () => {
|
||||
return create.create(project_path, config_mock, {}, events_mock).then(() => {
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join(default_templates, 'assets'), path.join(app_path, 'assets'));
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join(default_templates, 'res'), path.join(app_path, 'res'));
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join(default_templates, 'gitignore'), path.join(project_path, '.gitignore'));
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join(default_templates, 'assets'), path.join(app_path, 'assets'), { recursive: true });
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join(default_templates, 'res'), path.join(app_path, 'res'), { recursive: true });
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join(default_templates, 'gitignore'), path.join(project_path, '.gitignore'));
|
||||
});
|
||||
});
|
||||
|
||||
@ -261,7 +261,7 @@ describe('create', function () {
|
||||
it('should create a java src directory based on the provided project package name', () => {
|
||||
config_mock.packageName.and.returnValue('org.apache.cordova');
|
||||
return create.create(project_path, config_mock, {}, events_mock).then(() => {
|
||||
expect(fs.ensureDirSync).toHaveBeenCalledWith(path.join(app_path, 'java', 'org', 'apache', 'cordova'));
|
||||
expect(fs.mkdirSync).toHaveBeenCalledWith(path.join(app_path, 'java', 'org', 'apache', 'cordova'), { recursive: true });
|
||||
});
|
||||
});
|
||||
|
||||
@ -270,7 +270,7 @@ describe('create', function () {
|
||||
config_mock.android_activityName.and.returnValue('CEEDEEVEE');
|
||||
const activity_path = path.join(app_path, 'java', 'org', 'apache', 'cordova', 'CEEDEEVEE.java');
|
||||
return create.create(project_path, config_mock, {}, events_mock).then(() => {
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join(default_templates, 'Activity.java'), activity_path);
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join(default_templates, 'Activity.java'), activity_path);
|
||||
expect(utils.replaceFileContents).toHaveBeenCalledWith(activity_path, /__ACTIVITY__/, 'CEEDEEVEE');
|
||||
expect(utils.replaceFileContents).toHaveBeenCalledWith(activity_path, /__ID__/, 'org.apache.cordova');
|
||||
});
|
||||
|
@ -17,7 +17,7 @@
|
||||
under the License.
|
||||
*/
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const rewire = require('rewire');
|
||||
const which = require('which');
|
||||
|
@ -19,26 +19,40 @@
|
||||
const rewire = require('rewire');
|
||||
const common = rewire('../../../lib/pluginHandlers');
|
||||
const path = require('node:path');
|
||||
const fs = require('fs-extra');
|
||||
const osenv = require('node:os');
|
||||
const fs = require('node:fs');
|
||||
const tmp = require('tmp');
|
||||
|
||||
const test_dir = path.join(osenv.tmpdir(), 'test_plugman');
|
||||
tmp.setGracefulCleanup();
|
||||
|
||||
const tempdir = tmp.dirSync({ unsafeCleanup: true });
|
||||
const test_dir = path.join(tempdir.name, 'test_plugman');
|
||||
const project_dir = path.join(test_dir, 'project');
|
||||
const src = path.join(project_dir, 'src');
|
||||
const dest = path.join(project_dir, 'dest');
|
||||
const java_dir = path.join(src, 'one', 'two', 'three');
|
||||
const java_file = path.join(java_dir, 'test.java');
|
||||
const symlink_file = path.join(java_dir, 'symlink');
|
||||
const non_plugin_file = path.join(osenv.tmpdir(), 'non_plugin_file');
|
||||
const non_plugin_file = path.join(tempdir.name, 'non_plugin_file');
|
||||
|
||||
const copyFile = common.__get__('copyFile');
|
||||
const deleteJava = common.__get__('deleteJava');
|
||||
const copyNewFile = common.__get__('copyNewFile');
|
||||
|
||||
function outputFileSync (file, content) {
|
||||
const dir = path.dirname(file);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
fs.writeFileSync(file, content, 'utf-8');
|
||||
}
|
||||
|
||||
describe('common platform handler', function () {
|
||||
afterAll(() => {
|
||||
// Remove tempdir after all specs complete
|
||||
fs.rmSync(tempdir.name, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.removeSync(test_dir);
|
||||
fs.removeSync(non_plugin_file);
|
||||
fs.rmSync(test_dir, { recursive: true, force: true });
|
||||
fs.rmSync(non_plugin_file, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe('copyFile', function () {
|
||||
@ -48,15 +62,15 @@ describe('common platform handler', function () {
|
||||
});
|
||||
|
||||
it('Test#002 : should throw if src not in plugin directory', function () {
|
||||
fs.ensureDirSync(project_dir);
|
||||
fs.outputFileSync(non_plugin_file, 'contents');
|
||||
fs.mkdirSync(project_dir, { recursive: true });
|
||||
outputFileSync(non_plugin_file, 'contents');
|
||||
const outside_file = '../non_plugin_file';
|
||||
expect(function () { copyFile(test_dir, outside_file, project_dir, dest); })
|
||||
.toThrow(new Error('File "' + path.resolve(test_dir, outside_file) + '" is located outside the plugin directory "' + test_dir + '"'));
|
||||
});
|
||||
|
||||
it('Test#003 : should allow symlink src, if inside plugin', function () {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
outputFileSync(java_file, 'contents');
|
||||
|
||||
// This will fail on windows if not admin - ignore the error in that case.
|
||||
if (ignoreEPERMonWin32(java_file, symlink_file)) {
|
||||
@ -67,8 +81,8 @@ describe('common platform handler', function () {
|
||||
});
|
||||
|
||||
it('Test#004 : should throw if symlink is linked to a file outside the plugin', function () {
|
||||
fs.ensureDirSync(java_dir);
|
||||
fs.outputFileSync(non_plugin_file, 'contents');
|
||||
fs.mkdirSync(java_dir, { recursive: true });
|
||||
outputFileSync(non_plugin_file, 'contents');
|
||||
|
||||
// This will fail on windows if not admin - ignore the error in that case.
|
||||
if (ignoreEPERMonWin32(non_plugin_file, symlink_file)) {
|
||||
@ -80,37 +94,37 @@ describe('common platform handler', function () {
|
||||
});
|
||||
|
||||
it('Test#005 : should throw if dest is outside the project directory', function () {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
outputFileSync(java_file, 'contents');
|
||||
expect(function () { copyFile(test_dir, java_file, project_dir, non_plugin_file); })
|
||||
.toThrow(new Error('Destination "' + path.resolve(project_dir, non_plugin_file) + '" for source file "' + path.resolve(test_dir, java_file) + '" is located outside the project'));
|
||||
});
|
||||
|
||||
it('Test#006 : should call mkdir -p on target path', function () {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
it('Test#006 : should call mkdirSync target path', function () {
|
||||
outputFileSync(java_file, 'contents');
|
||||
|
||||
const s = spyOn(fs, 'ensureDirSync').and.callThrough();
|
||||
const s = spyOn(fs, 'mkdirSync').and.callThrough();
|
||||
const resolvedDest = path.resolve(project_dir, dest);
|
||||
|
||||
copyFile(test_dir, java_file, project_dir, dest);
|
||||
|
||||
expect(s).toHaveBeenCalled();
|
||||
expect(s).toHaveBeenCalledWith(path.dirname(resolvedDest));
|
||||
expect(s).toHaveBeenCalledWith(path.dirname(resolvedDest), { recursive: true });
|
||||
});
|
||||
|
||||
it('Test#007 : should call cp source/dest paths', function () {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
outputFileSync(java_file, 'contents');
|
||||
|
||||
const s = spyOn(fs, 'copySync').and.callThrough();
|
||||
const s = spyOn(fs, 'cpSync').and.callThrough();
|
||||
const resolvedDest = path.resolve(project_dir, dest);
|
||||
|
||||
copyFile(test_dir, java_file, project_dir, dest);
|
||||
|
||||
expect(s).toHaveBeenCalled();
|
||||
expect(s).toHaveBeenCalledWith(java_file, resolvedDest);
|
||||
expect(s).toHaveBeenCalledWith(java_file, resolvedDest, { recursive: true });
|
||||
});
|
||||
|
||||
it('should handle relative paths when checking for sub paths', () => {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
outputFileSync(java_file, 'contents');
|
||||
const relativeProjectPath = path.relative(process.cwd(), project_dir);
|
||||
|
||||
expect(() => {
|
||||
@ -121,7 +135,7 @@ describe('common platform handler', function () {
|
||||
|
||||
describe('copyNewFile', function () {
|
||||
it('Test#008 : should throw if target path exists', function () {
|
||||
fs.ensureDirSync(dest);
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
expect(function () { copyNewFile(test_dir, src, project_dir, dest); })
|
||||
.toThrow(new Error('"' + dest + '" already exists!'));
|
||||
});
|
||||
@ -129,11 +143,11 @@ describe('common platform handler', function () {
|
||||
|
||||
describe('deleteJava', function () {
|
||||
beforeEach(function () {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
outputFileSync(java_file, 'contents');
|
||||
});
|
||||
|
||||
it('Test#009 : should call fs.unlinkSync on the provided paths', function () {
|
||||
const s = spyOn(fs, 'removeSync').and.callThrough();
|
||||
const s = spyOn(fs, 'rmSync').and.callThrough();
|
||||
deleteJava(project_dir, java_file);
|
||||
expect(s).toHaveBeenCalled();
|
||||
expect(s).toHaveBeenCalledWith(path.resolve(project_dir, java_file));
|
||||
|
@ -21,7 +21,7 @@ const rewire = require('rewire');
|
||||
const common = rewire('../../../lib/pluginHandlers');
|
||||
const android = common.__get__('handlers');
|
||||
const path = require('node:path');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const temp = path.join(os.tmpdir(), 'plugman');
|
||||
const plugins_dir = path.join(temp, 'cordova/plugins');
|
||||
@ -56,14 +56,14 @@ describe('android project handler', function () {
|
||||
let dummyProject;
|
||||
|
||||
beforeEach(function () {
|
||||
fs.ensureDirSync(temp);
|
||||
fs.mkdirSync(temp, { recursive: true });
|
||||
dummyProject = AndroidProject.getProjectFile(temp);
|
||||
copyFileSpy.calls.reset();
|
||||
common.__set__('copyFile', copyFileSpy);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
fs.removeSync(temp);
|
||||
fs.rmSync(temp, { recursive: true, force: true });
|
||||
common.__set__('copyFile', copyFileOrig);
|
||||
});
|
||||
|
||||
@ -83,7 +83,7 @@ describe('android project handler', function () {
|
||||
|
||||
describe('of <source-file> elements', function () {
|
||||
beforeEach(function () {
|
||||
fs.copySync(android_studio_project, temp);
|
||||
fs.cpSync(android_studio_project, temp, { recursive: true });
|
||||
});
|
||||
|
||||
it('Test#003 : should copy stuff from one location to another by calling common.copyFile', function () {
|
||||
@ -102,7 +102,7 @@ describe('android project handler', function () {
|
||||
it('Test#006 : should throw if target file already exists', function () {
|
||||
// write out a file
|
||||
let target = path.resolve(temp, 'app', 'src', 'main', 'java', 'com', 'phonegap', 'plugins', 'dummyplugin');
|
||||
fs.ensureDirSync(target);
|
||||
fs.mkdirSync(target, { recursive: true });
|
||||
target = path.join(target, 'DummyPlugin.java');
|
||||
fs.writeFileSync(target, 'some bs', 'utf-8');
|
||||
|
||||
@ -192,7 +192,7 @@ describe('android project handler', function () {
|
||||
const copyNewFileSpy = jasmine.createSpy('copyNewFile');
|
||||
|
||||
beforeEach(function () {
|
||||
fs.copySync(android_studio_project, temp);
|
||||
fs.cpSync(android_studio_project, temp, { recursive: true });
|
||||
|
||||
spyOn(dummyProject, 'addSystemLibrary');
|
||||
spyOn(dummyProject, 'addSubProject');
|
||||
@ -222,7 +222,7 @@ describe('android project handler', function () {
|
||||
|
||||
it('Test#010 : should not copy anything if "custom" attribute is not set', function () {
|
||||
const framework = { src: 'plugin-lib' };
|
||||
const cpSpy = spyOn(fs, 'copySync');
|
||||
const cpSpy = spyOn(fs, 'cpSync');
|
||||
android.framework.install(framework, dummyPluginInfo, dummyProject);
|
||||
expect(dummyProject.addSystemLibrary).toHaveBeenCalledWith(someString, framework.src);
|
||||
expect(cpSpy).not.toHaveBeenCalled();
|
||||
@ -289,23 +289,23 @@ describe('android project handler', function () {
|
||||
|
||||
describe('uninstallation', function () {
|
||||
const deleteJavaOrig = common.__get__('deleteJava');
|
||||
const originalRemoveSync = fs.removeSync;
|
||||
const originalRmSync = fs.rmSync;
|
||||
const deleteJavaSpy = jasmine.createSpy('deleteJava');
|
||||
let dummyProject;
|
||||
let removeSyncSpy;
|
||||
let rmSyncSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
fs.ensureDirSync(temp);
|
||||
fs.ensureDirSync(plugins_dir);
|
||||
fs.copySync(android_studio_project, temp);
|
||||
fs.mkdirSync(temp, { recursive: true });
|
||||
fs.mkdirSync(plugins_dir, { recursive: true });
|
||||
fs.cpSync(android_studio_project, temp, { recursive: true });
|
||||
AndroidProject.purgeCache();
|
||||
dummyProject = AndroidProject.getProjectFile(temp);
|
||||
removeSyncSpy = spyOn(fs, 'removeSync');
|
||||
rmSyncSpy = spyOn(fs, 'rmSync');
|
||||
common.__set__('deleteJava', deleteJavaSpy);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
originalRemoveSync.call(fs, temp);
|
||||
originalRmSync.call(fs, temp, { recursive: true });
|
||||
common.__set__('deleteJava', deleteJavaOrig);
|
||||
});
|
||||
|
||||
@ -313,7 +313,7 @@ describe('android project handler', function () {
|
||||
it('Test#017 : should remove jar files for Android Studio projects', function () {
|
||||
android['lib-file'].install(valid_libs[0], dummyPluginInfo, dummyProject);
|
||||
android['lib-file'].uninstall(valid_libs[0], dummyPluginInfo, dummyProject);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestLib.jar'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestLib.jar'));
|
||||
});
|
||||
});
|
||||
|
||||
@ -321,7 +321,7 @@ describe('android project handler', function () {
|
||||
it('Test#018 : should remove files for Android Studio projects', function () {
|
||||
android['resource-file'].install(valid_resources[0], dummyPluginInfo, dummyProject);
|
||||
android['resource-file'].uninstall(valid_resources[0], dummyPluginInfo, dummyProject);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app', 'src', 'main', 'res', 'xml', 'dummy.xml'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app', 'src', 'main', 'res', 'xml', 'dummy.xml'));
|
||||
});
|
||||
});
|
||||
|
||||
@ -341,49 +341,49 @@ describe('android project handler', function () {
|
||||
it('Test#019b : should remove stuff by calling common.removeFile for Android Studio projects, of jar with new app target-dir scheme', function () {
|
||||
android['source-file'].install(valid_source[2], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[2], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestLib.jar'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestLib.jar'));
|
||||
});
|
||||
|
||||
it('Test#019c : should remove stuff by calling common.removeFile for Android Studio projects, of aar with new app target-dir scheme', function () {
|
||||
android['source-file'].install(valid_source[3], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[3], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestAar.aar'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestAar.aar'));
|
||||
});
|
||||
|
||||
it('Test#019d : should remove stuff by calling common.removeFile for Android Studio projects, of xml with old target-dir scheme', function () {
|
||||
android['source-file'].install(valid_source[4], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[4], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/res/xml/mysettings.xml'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/res/xml/mysettings.xml'));
|
||||
});
|
||||
|
||||
it('Test#019e : should remove stuff by calling common.removeFile for Android Studio projects, of file with other extension with old target-dir scheme', function () {
|
||||
android['source-file'].install(valid_source[5], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[5], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/res/values/other.extension'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/res/values/other.extension'));
|
||||
});
|
||||
|
||||
it('Test#019f : should remove stuff by calling common.removeFile for Android Studio projects, of aidl with old target-dir scheme (GH-547)', function () {
|
||||
android['source-file'].install(valid_source[6], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[6], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/aidl/com/mytest/myapi.aidl'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/aidl/com/mytest/myapi.aidl'));
|
||||
});
|
||||
|
||||
it('Test#019g : should remove stuff by calling common.removeFile for Android Studio projects, of aar with old target-dir scheme (GH-547)', function () {
|
||||
android['source-file'].install(valid_source[7], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[7], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/testaar2.aar'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/testaar2.aar'));
|
||||
});
|
||||
|
||||
it('Test#019h : should remove stuff by calling common.removeFile for Android Studio projects, of jar with old target-dir scheme (GH-547)', function () {
|
||||
android['source-file'].install(valid_source[8], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[8], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/testjar2.jar'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/testjar2.jar'));
|
||||
});
|
||||
|
||||
it('Test#019i : should remove stuff by calling common.removeFile for Android Studio projects, of .so lib file with old target-dir scheme (GH-547)', function () {
|
||||
android['source-file'].install(valid_source[9], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[9], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/jniLibs/x86/libnative.so'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/jniLibs/x86/libnative.so'));
|
||||
});
|
||||
|
||||
it('Test#019j : should remove stuff by calling common.deleteJava for Android Studio projects, with target-dir that includes "app"', function () {
|
||||
@ -397,7 +397,7 @@ describe('android project handler', function () {
|
||||
const someString = jasmine.any(String);
|
||||
|
||||
beforeEach(function () {
|
||||
fs.ensureDirSync(path.join(dummyProject.projectDir, dummyPluginInfo.id));
|
||||
fs.mkdirSync(path.join(dummyProject.projectDir, dummyPluginInfo.id), { recursive: true });
|
||||
|
||||
spyOn(dummyProject, 'removeSystemLibrary');
|
||||
spyOn(dummyProject, 'removeSubProject');
|
||||
@ -424,13 +424,13 @@ describe('android project handler', function () {
|
||||
const framework = { src: 'plugin-lib', custom: true };
|
||||
android.framework.uninstall(framework, dummyPluginInfo, dummyProject);
|
||||
expect(dummyProject.removeSubProject).toHaveBeenCalledWith(dummyProject.projectDir, someString);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(someString);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(someString);
|
||||
});
|
||||
|
||||
it('Test#24 : should install gradleReference using project.removeGradleReference', function () {
|
||||
const framework = { src: 'plugin-lib', custom: true, type: 'gradleReference' };
|
||||
android.framework.uninstall(framework, dummyPluginInfo, dummyProject);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(someString);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(someString);
|
||||
expect(dummyProject.removeGradleReference).toHaveBeenCalledWith(dummyProject.projectDir, someString);
|
||||
});
|
||||
});
|
||||
@ -453,14 +453,14 @@ describe('android project handler', function () {
|
||||
|
||||
it('Test#025 : should put module to both www and platform_www when options.usePlatformWww flag is specified', function () {
|
||||
android['js-module'].uninstall(jsModule, dummyPluginInfo, dummyProject, { usePlatformWww: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(platformWwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(platformWwwDest);
|
||||
});
|
||||
|
||||
it('Test#026 : should put module to www only when options.usePlatformWww flag is not specified', function () {
|
||||
android['js-module'].uninstall(jsModule, dummyPluginInfo, dummyProject);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(removeSyncSpy).not.toHaveBeenCalledWith(platformWwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(rmSyncSpy).not.toHaveBeenCalledWith(platformWwwDest);
|
||||
});
|
||||
});
|
||||
|
||||
@ -481,14 +481,14 @@ describe('android project handler', function () {
|
||||
|
||||
it('Test#027 : should put module to both www and platform_www when options.usePlatformWww flag is specified', function () {
|
||||
android.asset.uninstall(asset, dummyPluginInfo, dummyProject, { usePlatformWww: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(platformWwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(platformWwwDest);
|
||||
});
|
||||
|
||||
it('Test#028 : should put module to www only when options.usePlatformWww flag is not specified', function () {
|
||||
android.asset.uninstall(asset, dummyPluginInfo, dummyProject);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(removeSyncSpy).not.toHaveBeenCalledWith(platformWwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(rmSyncSpy).not.toHaveBeenCalledWith(platformWwwDest);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -899,9 +899,9 @@ describe('prepare', () => {
|
||||
|
||||
// Spies
|
||||
let replaceFileContents;
|
||||
let ensureDirSyncSpy;
|
||||
let copySyncSpy;
|
||||
let removeSyncSpy;
|
||||
let mkdirSyncSpy;
|
||||
let cpSyncSpy;
|
||||
let rmSyncSpy;
|
||||
|
||||
// Mock Data
|
||||
let cordovaProject;
|
||||
@ -1001,16 +1001,15 @@ describe('prepare', () => {
|
||||
`))
|
||||
});
|
||||
|
||||
ensureDirSyncSpy = jasmine.createSpy('ensureDirSync');
|
||||
copySyncSpy = jasmine.createSpy('copySync');
|
||||
removeSyncSpy = jasmine.createSpy('removeSync');
|
||||
mkdirSyncSpy = jasmine.createSpy('mkdirSync');
|
||||
cpSyncSpy = jasmine.createSpy('cpSync');
|
||||
rmSyncSpy = jasmine.createSpy('rmSync');
|
||||
|
||||
prepare.__set__('fs', {
|
||||
writeFileSync: jasmine.createSpy('writeFileSync'),
|
||||
writeJSONSync: jasmine.createSpy('writeJSONSync'),
|
||||
ensureDirSync: ensureDirSyncSpy,
|
||||
copySync: copySyncSpy,
|
||||
removeSync: removeSyncSpy,
|
||||
mkdirSync: mkdirSyncSpy,
|
||||
cpSync: cpSyncSpy,
|
||||
rmSync: rmSyncSpy,
|
||||
existsSync: jasmine.createSpy('existsSync')
|
||||
});
|
||||
});
|
||||
@ -1022,9 +1021,9 @@ describe('prepare', () => {
|
||||
|
||||
await api.prepare(cordovaProject, options).then(() => {
|
||||
expect(replaceFileContents).toHaveBeenCalledWith(renamedJavaActivityPath, /package [\w.]*;/, 'package ' + packageName + ';');
|
||||
expect(ensureDirSyncSpy).toHaveBeenCalledWith(renamedPath);
|
||||
expect(copySyncSpy).toHaveBeenCalledWith(initialJavaActivityPath, renamedJavaActivityPath);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(initialJavaActivityPath);
|
||||
expect(mkdirSyncSpy).toHaveBeenCalledWith(renamedPath, { recursive: true });
|
||||
expect(cpSyncSpy).toHaveBeenCalledWith(initialJavaActivityPath, renamedJavaActivityPath);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(initialJavaActivityPath);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1033,9 +1032,9 @@ describe('prepare', () => {
|
||||
|
||||
await api.prepare(cordovaProject, options).then(() => {
|
||||
expect(replaceFileContents).toHaveBeenCalledTimes(0);
|
||||
expect(ensureDirSyncSpy).toHaveBeenCalledTimes(0);
|
||||
expect(copySyncSpy).toHaveBeenCalledTimes(0);
|
||||
expect(removeSyncSpy).toHaveBeenCalledTimes(0);
|
||||
expect(mkdirSyncSpy).toHaveBeenCalledTimes(0);
|
||||
expect(cpSyncSpy).toHaveBeenCalledTimes(0);
|
||||
expect(rmSyncSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
const path = require('node:path');
|
||||
const execa = require('execa');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const ProjectBuilder = require('../lib/builders/ProjectBuilder');
|
||||
|
||||
class AndroidTestRunner {
|
||||
@ -62,7 +62,7 @@ class AndroidTestRunner {
|
||||
.then(_ => {
|
||||
// TODO we should probably not only copy these files, but instead create a new project from scratch
|
||||
fs.copyFileSync(path.resolve(this.projectDir, '../../framework/cdv-gradle-config-defaults.json'), path.resolve(this.projectDir, 'cdv-gradle-config.json'));
|
||||
fs.copySync(path.resolve(this.projectDir, '../../templates/project/tools'), path.resolve(this.projectDir, 'tools'));
|
||||
fs.cpSync(path.resolve(this.projectDir, '../../templates/project/tools'), path.resolve(this.projectDir, 'tools'), { recursive: true });
|
||||
fs.copyFileSync(
|
||||
path.join(__dirname, '../templates/project/assets/www/cordova.js'),
|
||||
path.join(this.projectDir, 'app/src/main/assets/www/cordova.js')
|
||||
|
Loading…
Reference in New Issue
Block a user