Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions bin/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
under the License.
*/

const fs = require('fs');
const shell = require('shelljs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const ROOT = path.join(__dirname, '..', '..');
const events = require('cordova-common').events;
const check_reqs = require('./check_reqs');
Expand Down Expand Up @@ -53,29 +52,37 @@ module.exports.createProject = function (project_path, package_name, project_nam
events.emit('error', 'Please make sure you meet the software requirements in order to build a browser cordova project');
}

// copy template/cordova directory ( recursive )
shell.cp('-r', path.join(ROOT, 'bin/template/cordova'), project_path);

// copy template/www directory ( recursive )
shell.cp('-r', path.join(ROOT, 'bin/template/www'), project_path);
// copy template/* to project_path directory ( recursive )
fs.cpSync(path.join(ROOT, 'bin/template'), project_path, { recursive: true });

// TODO: stop copying cordova-browser logic into platforms/browser/
// recreate our node_modules structure in the new project
const nodeModulesDir = path.join(ROOT, 'node_modules');
if (fs.existsSync(nodeModulesDir)) shell.cp('-r', nodeModulesDir, path.join(project_path, 'cordova'));
if (fs.existsSync(nodeModulesDir)) {
fs.cpSync(nodeModulesDir, path.join(project_path, 'cordova/node_modules'), { recursive: true });
}

// copy check_reqs file
shell.cp(path.join(ROOT, 'bin/lib/check_reqs.js'),
path.join(project_path, 'cordova/lib'));
fs.cpSync(
path.join(ROOT, 'bin/lib/check_reqs.js'),
path.join(project_path, 'cordova/lib/check_reqs.js')
);

// create platform_www dir if it does not exist yet
const platform_www = path.join(project_path, 'platform_www');
shell.mkdir('-p', platform_www);
fs.mkdirSync(platform_www, { recursive: true });

// copy cordova js file to platform_www
shell.cp(path.join(ROOT, 'bin/template/www/cordova.js'), platform_www);
fs.cpSync(
path.join(ROOT, 'bin/template/www/cordova.js'),
path.join(platform_www, 'cordova.js')
);

// copy favicon file to platform_www
shell.cp(path.join(ROOT, 'bin/template/www/favicon.ico'), platform_www);
fs.cpSync(
path.join(ROOT, 'bin/template/www/favicon.ico'),
path.join(platform_www, 'favicon.ico')
);

// load manifest to write name/shortname
const manifest = require(path.join(ROOT, 'bin/template/www', 'manifest.json'));
Expand Down
17 changes: 2 additions & 15 deletions bin/lib/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/

const create = require('./create');
const fs = require('fs');
const shell = require('shelljs');
const fs = require('node:fs');
const { CordovaError } = require('cordova-common');

module.exports.help = function () {
Expand All @@ -39,20 +38,8 @@ module.exports.run = function (argv) {
}

console.log('Removing existing browser platform.');
shellfatal(shell.rm, '-rf', projectPath);
fs.rmSync(projectPath, { recursive: true, force: true });

// Create Project returns a resolved promise.
return create.createProject(projectPath);
};

function shellfatal (shellFunc) {
const slicedArgs = Array.prototype.slice.call(arguments, 1);
let returnVal = null;
try {
shell.config.fatal = true;
returnVal = shellFunc.apply(shell, slicedArgs);
} finally {
shell.config.fatal = false;
}
return returnVal;
}
22 changes: 0 additions & 22 deletions bin/template/config.xml

This file was deleted.

26 changes: 16 additions & 10 deletions bin/template/cordova/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
'cordova platform add PATH' where path is this repo.
*/

const shell = require('shelljs');
const path = require('path');
const fs = require('fs');
const path = require('node:path');
const fs = require('node:fs');

const cdvcmn = require('cordova-common');
const CordovaLogger = cdvcmn.CordovaLogger;
Expand Down Expand Up @@ -153,13 +152,13 @@ Api.prototype.prepare = async function (cordovaProject, options) {
// restored or copy project config into platform if none exists.
if (fs.existsSync(defaultConfigPath)) {
this.events.emit('verbose', 'Generating config.xml from defaults for platform "' + this.platform + '"');
shell.cp('-f', defaultConfigPath, ownConfigPath);
fs.cpSync(defaultConfigPath, ownConfigPath, { force: true });
} else if (fs.existsSync(ownConfigPath)) {
this.events.emit('verbose', 'Generating defaults.xml from own config.xml for platform "' + this.platform + '"');
shell.cp('-f', ownConfigPath, defaultConfigPath);
fs.cpSync(ownConfigPath, defaultConfigPath, { force: true });
} else {
this.events.emit('verbose', 'case 3"' + this.platform + '"');
shell.cp('-f', sourceCfg.path, ownConfigPath);
fs.cpSync(sourceCfg.path, ownConfigPath, { force: true });
}

// merge our configs
Expand All @@ -181,7 +180,7 @@ Api.prototype.prepare = async function (cordovaProject, options) {
// just blindly copy it to our output/www
// todo: validate it? ensure all properties we expect exist?
this.events.emit('verbose', 'copying ' + srcManifestPath + ' => ' + manifestPath);
shell.cp('-f', srcManifestPath, manifestPath);
fs.cpSync(srcManifestPath, manifestPath, { force: true });
} else {
const manifestJson = {
background_color: '#FFF',
Expand Down Expand Up @@ -269,7 +268,11 @@ Api.prototype.prepare = async function (cordovaProject, options) {
}

// Copy munged config.xml to platform www dir
shell.cp('-rf', this.locations.configXml, this.locations.www);
fs.cpSync(
this.locations.configXml,
path.join(this.locations.www, 'config.xml'),
{ force: true, recursive: true }
);
};

// Replace the www dir with contents of platform_www and app www.
Expand Down Expand Up @@ -391,7 +394,10 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
self._removeModulesInfo(plugin, targetDir);
// Remove stale plugin directory
// TODO: this should be done by plugin files uninstaller
shell.rm('-rf', path.resolve(self.root, 'Plugins', plugin.id));
fs.rmSync(
path.resolve(self.root, 'Plugins', plugin.id),
{ force: true, recursive: true }
);
});
};

Expand Down Expand Up @@ -505,7 +511,7 @@ Api.prototype._writePluginModules = function (targetDir) {
final_contents += '// BOTTOM OF METADATA\n';
final_contents += '});'; // Close cordova.define.

shell.mkdir('-p', targetDir);
fs.mkdirSync(targetDir, { recursive: true });
fs.writeFileSync(path.join(targetDir, 'cordova_plugins.js'), final_contents, 'utf-8');
};

Expand Down
17 changes: 8 additions & 9 deletions bin/template/cordova/browser_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
under the License.
*/

const path = require('path');
const fs = require('fs');
const shell = require('shelljs');
const path = require('node:path');
const fs = require('node:fs');
const events = require('cordova-common').events;

module.exports = {
Expand Down Expand Up @@ -59,7 +58,7 @@ module.exports = {
scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) { ' + scriptContent + '\n});\n';

const moduleDestination = path.resolve(www_dir, 'plugins', plugin_id, jsModule.src);
shell.mkdir('-p', path.dirname(moduleDestination));
fs.mkdirSync(path.dirname(moduleDestination), { recursive: true });
fs.writeFileSync(moduleDestination, scriptContent, 'utf-8');
},
uninstall: function (jsModule, www_dir, plugin_id) {
Expand Down Expand Up @@ -118,18 +117,18 @@ module.exports = {
const dest = path.join(wwwDest, asset.target);
const destDir = path.parse(dest).dir;
if (destDir !== '' && !fs.existsSync(destDir)) {
shell.mkdir('-p', destDir);
fs.mkdirSync(destDir, { recursive: true });
}

if (fs.statSync(src).isDirectory()) {
shell.cp('-Rf', src + '/*', dest);
fs.cpSync(src, dest, { recursive: true, force: true });
} else {
shell.cp('-f', src, dest);
fs.cpSync(src, dest, { force: true });
}
},
uninstall: function (asset, wwwDest, plugin_id) {
shell.rm('-rf', path.join(wwwDest, asset.target));
shell.rm('-rf', path.join(wwwDest, 'plugins', plugin_id));
fs.rmSync(path.join(wwwDest, asset.target), { recursive: true, force: true });
fs.rmSync(path.join(wwwDest, 'plugins', plugin_id), { recursive: true, force: true });
}
}
};
7 changes: 3 additions & 4 deletions bin/template/cordova/browser_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
under the License.
*/

const fs = require('fs');
const path = require('path');
const shell = require('shelljs');
const fs = require('node:fs');
const path = require('node:path');
const CordovaError = require('cordova-common').CordovaError;
const events = require('cordova-common').events;
const FileUpdater = require('cordova-common').FileUpdater;
Expand Down Expand Up @@ -78,5 +77,5 @@ browser_parser.prototype.config_xml = function () {

browser_parser.prototype.update_project = async function (cfg) {
// Copy munged config.xml to platform www dir
shell.cp('-rf', this.config_xml(), this.www_dir());
fs.cpSync(this.config_xml(), this.www_dir(), { recursive: true, force: true });
};
2 changes: 1 addition & 1 deletion bin/template/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
under the License.
*/

const path = require('path');
const path = require('node:path');
const check_reqs = require('./check_reqs');

/**
Expand Down
7 changes: 3 additions & 4 deletions bin/template/cordova/lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
under the License.
*/

const fs = require('fs');
const shell = require('shelljs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const check_reqs = require('./check_reqs');
const platformBuildDir = path.join('platforms', 'browser', 'www');

Expand All @@ -35,7 +34,7 @@ const run = function () {

try {
if (fs.existsSync(platformBuildDir)) {
shell.rm('-r', platformBuildDir);
fs.rmSync(platformBuildDir, { recursive: true });
}
} catch (err) {
console.log('could not remove ' + platformBuildDir + ' : ' + err.message);
Expand Down
6 changes: 3 additions & 3 deletions bin/template/cordova/lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
under the License.
*/

const fs = require('fs');
const path = require('path');
const url = require('url');
const fs = require('node:fs');
const path = require('node:path');
const url = require('node:url');
const cordovaServe = require('cordova-serve');

module.exports.run = function (args) {
Expand Down
Loading
Loading