Skip to content

Commit

Permalink
Merge pull request #775 from raphinesse/cpj-cleanup
Browse files Browse the repository at this point in the history
Cleanup plugman.createPackageJson
  • Loading branch information
raphinesse committed Apr 17, 2019
2 parents 3be2acb + 892d1f8 commit dbab1ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 41 deletions.
12 changes: 2 additions & 10 deletions src/plugman/createpackagejson.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
under the License.
*/

var fs = require('fs-extra');
var path = require('path');
var PluginInfo = require('cordova-common').PluginInfo;
var events = require('cordova-common').events;
const pify = require('pify');
Expand All @@ -35,18 +33,12 @@ function createPackageJson (plugin_path) {
license: pluginInfo.license,
keywords: pluginInfo.getKeywordsAndPlatforms(),
repository: pluginInfo.repo,
bugs: pluginInfo.issue,
engines: pluginInfo.getEngines(),
platforms: pluginInfo.getPlatformsArray()
};

return fs.writeFile(path.join(__dirname, 'defaults.json'), JSON.stringify(defaults), 'utf8')
.then(_ => {
events.emit('verbose', 'defaults.json created from plugin.xml');

var initFile = require.resolve('./init-defaults');
return initPkgJson(plugin_path, initFile, {});
})
var initFile = require.resolve('./init-defaults');
return initPkgJson(plugin_path, initFile, defaults)
.then(_ => {
events.emit('verbose', 'Package.json successfully created');
});
Expand Down
42 changes: 11 additions & 31 deletions src/plugman/init-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
under the License.
**/

/* global dirname */
/* global config */
/* global basename */
/* global yes */
/* global prompt */
/* global config, dirname, basename, yes, prompt */
// PromZard file that is used by createpackagejson and init-package-json module

// The PromZard context is also provided via this. Make use of this to avoid
Expand All @@ -30,9 +26,8 @@ const pkg = this.package;

var fs = require('fs-extra');
var path = require('path');
var defaults = require('./defaults.json');

function readDeps (test) {
function readDeps () {
return function (cb) {
fs.readdir('node_modules', function (er, dir) {
if (er) return cb();
Expand All @@ -47,7 +42,7 @@ function readDeps (test) {
if (er) return next();
try { p = JSON.parse(p); } catch (e) { return next(); }
if (!p.version) return next();
deps[d] = config.get('save-exact') ? p.version : config.get('save-prefix') + p.version;
deps[d] = undefined + p.version;
return next();
});
});
Expand All @@ -58,14 +53,13 @@ function readDeps (test) {
};
}

// The defaults read from plugin.xml
const defaults = config.toJSON();

var name = pkg.name || defaults.id || basename;
exports.name = yes ? name : prompt('name', name);

var version = pkg.version ||
defaults.version ||
config.get('init.version') ||
config.get('init-version') ||
'1.0.0';
var version = pkg.version || defaults.version || '1.0.0';
exports.version = yes ? version : prompt('version', version);

if (!pkg.description) {
Expand All @@ -87,11 +81,11 @@ if (!pkg.cordova) {
}

if (!pkg.dependencies) {
exports.dependencies = readDeps(false);
exports.dependencies = readDeps();
}

if (!pkg.devDependencies) {
exports.devDependencies = readDeps(true);
exports.devDependencies = readDeps();
}

if (!pkg.repository) {
Expand Down Expand Up @@ -139,22 +133,8 @@ if (!pkg.engines) {
}

if (!pkg.author) {
exports.author = (config.get('init.author.name') ||
config.get('init-author-name')) ?
{
'name': config.get('init.author.name') ||
config.get('init-author-name'),
'email': config.get('init.author.email') ||
config.get('init-author-email'),
'url': config.get('init.author.url') ||
config.get('init-author-url')
}
: prompt('author');
exports.author = prompt('author');
}
var license = pkg.license ||
defaults.license ||
config.get('init.license') ||
config.get('init-license') ||
'ISC';

const license = pkg.license || defaults.license || 'ISC';
exports.license = yes ? license : prompt('license', license);

0 comments on commit dbab1ac

Please sign in to comment.