You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by au...@apache.org on 2017/07/14 22:42:44 UTC
cordova-create git commit: CB-12895 : setup eslint and remove jshint
Repository: cordova-create
Updated Branches:
refs/heads/master 637e657e0 -> b5877e51c
CB-12895 : setup eslint and remove jshint
Project: http://git-wip-us.apache.org/repos/asf/cordova-create/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-create/commit/b5877e51
Tree: http://git-wip-us.apache.org/repos/asf/cordova-create/tree/b5877e51
Diff: http://git-wip-us.apache.org/repos/asf/cordova-create/diff/b5877e51
Branch: refs/heads/master
Commit: b5877e51c160f5df5518151a806a6a0481137902
Parents: 637e657
Author: Audrey So <au...@apache.org>
Authored: Fri Jun 9 14:15:32 2017 -0700
Committer: Audrey So <au...@apache.org>
Committed: Fri Jul 14 15:34:36 2017 -0700
----------------------------------------------------------------------
.eslintrc.yml | 10 +
index.js | 392 ++++++-------
package.json | 12 +-
spec/.eslintrc.yml | 2 +
spec/create.spec.js | 582 +++++++++----------
spec/helpers.js | 19 +-
spec/templates/withsubdirectory/index.js | 4 +-
.../withsubdirectory_package_json/index.js | 4 +-
8 files changed, 512 insertions(+), 513 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-create/blob/b5877e51/.eslintrc.yml
----------------------------------------------------------------------
diff --git a/.eslintrc.yml b/.eslintrc.yml
new file mode 100644
index 0000000..f6aae32
--- /dev/null
+++ b/.eslintrc.yml
@@ -0,0 +1,10 @@
+root: true
+extends: semistandard
+rules:
+ indent:
+ - error
+ - 4
+ camelcase: off
+ padded-blocks: off
+ operator-linebreak: off
+ no-throw-literal: off
http://git-wip-us.apache.org/repos/asf/cordova-create/blob/b5877e51/index.js
----------------------------------------------------------------------
diff --git a/index.js b/index.js
index 827f158..9981d8c 100644
--- a/index.js
+++ b/index.js
@@ -17,22 +17,22 @@
under the License.
*/
-var path = require('path'),
- fs = require('fs'),
- shell = require('shelljs'),
- events = require('cordova-common').events,
- Q = require('q'),
- CordovaError = require('cordova-common').CordovaError,
- ConfigParser = require('cordova-common').ConfigParser,
- fetch = require('cordova-fetch'),
- url = require('url'),
- validateIdentifier = require('valid-identifier'),
- CordovaLogger = require('cordova-common').CordovaLogger.get();
+var path = require('path');
+var fs = require('fs');
+var shell = require('shelljs');
+var events = require('cordova-common').events;
+var Q = require('q');
+var CordovaError = require('cordova-common').CordovaError;
+var ConfigParser = require('cordova-common').ConfigParser;
+var fetch = require('cordova-fetch');
+var url = require('url');
+var validateIdentifier = require('valid-identifier');
+var CordovaLogger = require('cordova-common').CordovaLogger.get();
// Global configuration paths
var global_config_path = process.env.CORDOVA_HOME;
if (!global_config_path) {
- var HOME = process.env[(process.platform.slice(0, 3) == 'win') ? 'USERPROFILE' : 'HOME'];
+ var HOME = process.env[(process.platform.slice(0, 3) === 'win') ? 'USERPROFILE' : 'HOME'];
global_config_path = path.join(HOME, '.cordova');
}
/**
@@ -40,16 +40,15 @@ if (!global_config_path) {
* This will make the create internal events visible outside
* @param {EventEmitter} externalEventEmitter An EventEmitter instance that will be used for
* logging purposes. If no EventEmitter provided, all events will be logged to console
- * @return {EventEmitter}
- */
-function setupEvents(externalEventEmitter) {
+ * @return {EventEmitter}
+ */
+function setupEvents (externalEventEmitter) {
if (externalEventEmitter) {
// This will make the platform internal events visible outside
events.forwardEventsTo(externalEventEmitter);
- }
// There is no logger if external emitter is not present,
// so attach a console logger
- else {
+ } else {
CordovaLogger.subscribe(events);
}
return events;
@@ -59,14 +58,13 @@ function setupEvents(externalEventEmitter) {
* Usage:
* @dir - directory where the project will be created. Required.
* @optionalId - app id. Required (but be "undefined")
- * @optionalName - app name. Required (but can be "undefined").
+ * @optionalName - app name. Required (but can be "undefined").
* @cfg - extra config to be saved in .cordova/config.json Required (but can be "{}").
- * @extEvents - An EventEmitter instance that will be used for logging purposes. Required (but can be "undefined").
+ * @extEvents - An EventEmitter instance that will be used for logging purposes. Required (but can be "undefined").
**/
// Returns a promise.
-module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
- var argumentCount = arguments.length;
- return Q.fcall(function() {
+module.exports = function (dir, optionalId, optionalName, cfg, extEvents) {
+ return Q.fcall(function () {
events = setupEvents(extEvents);
events.emit('verbose', 'Using detached cordova-create');
@@ -74,18 +72,18 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
throw new CordovaError('Directory not specified. See `cordova help`.');
}
- //read projects .cordova/config.json file for project settings
+ // read projects .cordova/config.json file for project settings
var configFile = dotCordovaConfig(dir);
- //if data exists in the configFile, lets combine it with cfg
- //cfg values take priority over config file
- if(configFile) {
+ // if data exists in the configFile, lets combine it with cfg
+ // cfg values take priority over config file
+ if (configFile) {
var finalConfig = {};
- for(var key1 in configFile) {
+ for (var key1 in configFile) {
finalConfig[key1] = configFile[key1];
}
- for(var key2 in cfg) {
+ for (var key2 in cfg) {
finalConfig[key2] = cfg[key2];
}
@@ -94,7 +92,7 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
if (!cfg) {
throw new CordovaError('Must provide a project configuration.');
- } else if (typeof cfg == 'string') {
+ } else if (typeof cfg === 'string') {
cfg = JSON.parse(cfg);
}
@@ -109,8 +107,8 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
var contents = fs.readdirSync(d);
if (contents.length === 0) {
return true;
- } else if (contents.length == 1) {
- if (contents[0] == '.cordova') {
+ } else if (contents.length === 1) {
+ if (contents[0] === '.cordova') {
return true;
}
}
@@ -125,7 +123,6 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
throw new CordovaError('App id contains a reserved word, or is not a valid identifier.');
}
-
// This was changed from "uri" to "url", but checking uri for backwards compatibility.
cfg.lib = cfg.lib || {};
cfg.lib.www = cfg.lib.www || {};
@@ -152,9 +149,9 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
// must start by going up at least one directory or with a drive
// letter for Windows.
var rel_path = path.relative(cfg.lib.www.url, dir);
- var goes_up = rel_path.split(path.sep)[0] == '..';
+ var goes_up = rel_path.split(path.sep)[0] === '..';
- if (!(goes_up || rel_path[1] == ':')) {
+ if (!(goes_up || rel_path[1] === ':')) {
throw new CordovaError(
'Project dir "' + dir +
'" must not be created at/inside the template used to create the project "' +
@@ -162,172 +159,164 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
);
}
})
- .then(function() {
- // Finally, Ready to start!
- events.emit('log', 'Creating a new cordova project.');
+ .then(function () {
+ // Finally, Ready to start!
+ events.emit('log', 'Creating a new cordova project.');
- // Strip link and url from cfg to avoid them being persisted to disk via .cordova/config.json.
- // TODO: apparently underscore has no deep clone. Replace with lodash or something. For now, abuse JSON.
- var cfgToPersistToDisk = JSON.parse(JSON.stringify(cfg));
+ // Strip link and url from cfg to avoid them being persisted to disk via .cordova/config.json.
+ // TODO: apparently underscore has no deep clone. Replace with lodash or something. For now, abuse JSON.
+ var cfgToPersistToDisk = JSON.parse(JSON.stringify(cfg));
- delete cfgToPersistToDisk.lib.www;
- if (Object.keys(cfgToPersistToDisk.lib).length === 0) {
- delete cfgToPersistToDisk.lib;
- }
+ delete cfgToPersistToDisk.lib.www;
+ if (Object.keys(cfgToPersistToDisk.lib).length === 0) {
+ delete cfgToPersistToDisk.lib;
+ }
- // Update cached version of config.json
- writeToConfigJson(dir, cfgToPersistToDisk, false);
- })
- .then(function() {
- var gitURL;
- var branch;
- var parseArr;
- var packageName;
- var packageVersion;
- var isGit;
- var isNPM;
-
- //If symlink, don't fetch
- if (!!cfg.lib.www.link) {
- events.emit('verbose', 'Symlinking assets.');
- return Q(cfg.lib.www.url);
- }
+ // Update cached version of config.json
+ writeToConfigJson(dir, cfgToPersistToDisk, false);
+ })
+ .then(function () {
+ var isGit;
+ var isNPM;
+ var options;
+
+ // If symlink, don't fetch
+ if (cfg.lib.www.link) {
+ events.emit('verbose', 'Symlinking assets.');
+ return Q(cfg.lib.www.url);
+ }
- events.emit('verbose', 'Copying assets."');
- isGit = cfg.lib.www.template && isUrl(cfg.lib.www.url);
- isNPM = cfg.lib.www.template && (cfg.lib.www.url.indexOf('@') > -1 || !fs.existsSync(path.resolve(cfg.lib.www.url))) && !isGit;
- //Always use cordova fetch to obtain the npm or git template
- if (isGit || isNPM) {
- //Saved to .Cordova folder (ToDo: Delete installed template after using)
- //ToDo: @carynbear properly label errors from fetch as such
- var tempDest = global_config_path;
- var target = cfg.lib.www.url;
- //add latest to npm module if no version is specified
- //this prevents create using an older cached version of the template
- if(isNPM && target.indexOf('@') === -1) {
- target = cfg.lib.www.url + '@latest';
+ events.emit('verbose', 'Copying assets."');
+ isGit = cfg.lib.www.template && isUrl(cfg.lib.www.url);
+ isNPM = cfg.lib.www.template && (cfg.lib.www.url.indexOf('@') > -1 || !fs.existsSync(path.resolve(cfg.lib.www.url))) && !isGit;
+ // Always use cordova fetch to obtain the npm or git template
+ if (isGit || isNPM) {
+ // Saved to .Cordova folder (ToDo: Delete installed template after using)
+ // ToDo: @carynbear properly label errors from fetch as such
+ var tempDest = global_config_path;
+ var target = cfg.lib.www.url;
+ // add latest to npm module if no version is specified
+ // this prevents create using an older cached version of the template
+ if (isNPM && target.indexOf('@') === -1) {
+ target = cfg.lib.www.url + '@latest';
+ }
+ events.emit('verbose', 'Using cordova-fetch for ' + target);
+ return fetch(target, tempDest, {})
+ .fail(function (err) {
+ events.emit('error', '\x1B[1m \x1B[31m Error from Cordova Fetch: ' + err.message);
+ if (options.verbose) {
+ console.trace();
+ }
+ throw err;
+ });
+ // If assets are not online, resolve as a relative path on local computer
+ } else {
+ cfg.lib.www.url = path.resolve(cfg.lib.www.url);
+ return Q(cfg.lib.www.url);
}
- events.emit('verbose', 'Using cordova-fetch for '+ target);
- return fetch(target, tempDest, {})
- .fail(function(err){
- events.emit('error', '\033[1m \033[31m Error from Cordova Fetch: ' + err.message);
- if (options.verbose) {
- console.trace();
+ }).then(function (input_directory) {
+ var import_from_path = input_directory;
+
+ // handle when input wants to specify sub-directory (specified in index.js as "dirname" export);
+ var isSubDir = false;
+ try {
+ // Delete cached require incase one exists
+ delete require.cache[require.resolve(input_directory)];
+ var templatePkg = require(input_directory);
+ if (templatePkg && templatePkg.dirname) {
+ import_from_path = templatePkg.dirname;
+ isSubDir = true;
}
- throw err;
- });
- //If assets are not online, resolve as a relative path on local computer
- } else {
- cfg.lib.www.url = path.resolve(cfg.lib.www.url);
- return Q(cfg.lib.www.url);
- }
- }).then(function(input_directory) {
- var import_from_path = input_directory;
-
- //handle when input wants to specify sub-directory (specified in index.js as "dirname" export);
- var isSubDir = false;
- try {
- // Delete cached require incase one exists
- delete require.cache[require.resolve(input_directory)];
- var templatePkg = require(input_directory);
- if (templatePkg && templatePkg.dirname) {
- import_from_path = templatePkg.dirname;
- isSubDir = true;
+ } catch (e) {
+ events.emit('verbose', 'index.js does not specify valid sub-directory: ' + input_directory);
+ isSubDir = false;
}
- } catch (e) {
- events.emit('verbose', 'index.js does not specify valid sub-directory: ' + input_directory);
- isSubDir = false;
- }
- if (!fs.existsSync(import_from_path)) {
- throw new CordovaError('Could not find directory: ' +
- import_from_path);
- }
+ if (!fs.existsSync(import_from_path)) {
+ throw new CordovaError('Could not find directory: ' +
+ import_from_path);
+ }
- var paths = {};
+ var paths = {};
- // get stock config.xml, used if template does not contain config.xml
- paths.configXml = path.join(require('cordova-app-hello-world').dirname, 'config.xml');
+ // get stock config.xml, used if template does not contain config.xml
+ paths.configXml = path.join(require('cordova-app-hello-world').dirname, 'config.xml');
- // get stock www; used if template does not contain www
- paths.www = path.join(require('cordova-app-hello-world').dirname, 'www');
+ // get stock www; used if template does not contain www
+ paths.www = path.join(require('cordova-app-hello-world').dirname, 'www');
- // get stock hooks; used if template does not contain hooks
- paths.hooks = path.join(require('cordova-app-hello-world').dirname, 'hooks');
-
- // ToDo: get stock package.json if template does not contain package.json;
- var dirAlreadyExisted = fs.existsSync(dir);
- if (!dirAlreadyExisted) {
- fs.mkdirSync(dir);
- }
+ // get stock hooks; used if template does not contain hooks
+ paths.hooks = path.join(require('cordova-app-hello-world').dirname, 'hooks');
+
+ // ToDo: get stock package.json if template does not contain package.json;
+ var dirAlreadyExisted = fs.existsSync(dir);
+ if (!dirAlreadyExisted) {
+ fs.mkdirSync(dir);
+ }
- try {
+ try {
- // Copy files from template to project
- if (cfg.lib.www.template)
- copyTemplateFiles(import_from_path, dir, isSubDir);
+ // Copy files from template to project
+ if (cfg.lib.www.template) { copyTemplateFiles(import_from_path, dir, isSubDir); }
- // If --link, link merges, hooks, www, and config.xml (and/or copy to root)
- if (!!cfg.lib.www.link)
- linkFromTemplate(import_from_path, dir);
+ // If --link, link merges, hooks, www, and config.xml (and/or copy to root)
+ if (cfg.lib.www.link) { linkFromTemplate(import_from_path, dir); }
- // If following were not copied/linked from template, copy from stock app hello world
- copyIfNotExists(paths.www, path.join(dir, 'www'));
- copyIfNotExists(paths.hooks, path.join(dir, 'hooks'));
- var configXmlExists = projectConfig(dir); //moves config to root if in www
- if (paths.configXml && !configXmlExists) {
- shell.cp(paths.configXml, path.join(dir, 'config.xml'));
- }
- } catch (e) {
- if (!dirAlreadyExisted) {
- shell.rm('-rf', dir);
- }
- if (process.platform.slice(0, 3) == 'win' && e.code == 'EPERM') {
- throw new CordovaError('Symlinks on Windows require Administrator privileges');
+ // If following were not copied/linked from template, copy from stock app hello world
+ copyIfNotExists(paths.www, path.join(dir, 'www'));
+ copyIfNotExists(paths.hooks, path.join(dir, 'hooks'));
+ var configXmlExists = projectConfig(dir); // moves config to root if in www
+ if (paths.configXml && !configXmlExists) {
+ shell.cp(paths.configXml, path.join(dir, 'config.xml'));
+ }
+ } catch (e) {
+ if (!dirAlreadyExisted) {
+ shell.rm('-rf', dir);
+ }
+ if (process.platform.slice(0, 3) === 'win' && e.code === 'EPERM') {
+ throw new CordovaError('Symlinks on Windows require Administrator privileges');
+ }
+ throw e;
}
- throw e;
- }
- var pkgjsonPath = path.join(dir, 'package.json');
- // Update package.json name and version fields
- if (fs.existsSync(pkgjsonPath)) {
- delete require.cache[require.resolve(pkgjsonPath)];
- var pkgjson = require(pkgjsonPath);
+ var pkgjsonPath = path.join(dir, 'package.json');
+ // Update package.json name and version fields
+ if (fs.existsSync(pkgjsonPath)) {
+ delete require.cache[require.resolve(pkgjsonPath)];
+ var pkgjson = require(pkgjsonPath);
- // Pkjson.displayName should equal config's name.
- if (cfg.name) {
- pkgjson.displayName = cfg.name;
- }
- // Pkjson.name should equal config's id.
- if(cfg.id) {
- pkgjson.name = cfg.id.toLowerCase();
- } else if(!cfg.id) {
- // Use default name.
- pkgjson.name = 'helloworld';
+ // Pkjson.displayName should equal config's name.
+ if (cfg.name) {
+ pkgjson.displayName = cfg.name;
+ }
+ // Pkjson.name should equal config's id.
+ if (cfg.id) {
+ pkgjson.name = cfg.id.toLowerCase();
+ } else if (!cfg.id) {
+ // Use default name.
+ pkgjson.name = 'helloworld';
+ }
+
+ pkgjson.version = '1.0.0';
+ fs.writeFileSync(pkgjsonPath, JSON.stringify(pkgjson, null, 4), 'utf8');
}
- pkgjson.version = '1.0.0';
- fs.writeFileSync(pkgjsonPath, JSON.stringify(pkgjson, null, 4), 'utf8');
- }
+ // Create basic project structure.
+ if (!fs.existsSync(path.join(dir, 'platforms'))) { shell.mkdir(path.join(dir, 'platforms')); }
- // Create basic project structure.
- if (!fs.existsSync(path.join(dir, 'platforms')))
- shell.mkdir(path.join(dir, 'platforms'));
-
- if (!fs.existsSync(path.join(dir, 'plugins')))
- shell.mkdir(path.join(dir, 'plugins'));
-
- var configPath = path.join(dir, 'config.xml');
- // only update config.xml if not a symlink
- if(!fs.lstatSync(configPath).isSymbolicLink()) {
- // Write out id and name to config.xml; set version to 1.0.0 (to match package.json default version)
- var conf = new ConfigParser(configPath);
- if (cfg.id) conf.setPackageName(cfg.id);
- if (cfg.name) conf.setName(cfg.name);
- conf.setVersion('1.0.0');
- conf.write();
- }
- });
+ if (!fs.existsSync(path.join(dir, 'plugins'))) { shell.mkdir(path.join(dir, 'plugins')); }
+
+ var configPath = path.join(dir, 'config.xml');
+ // only update config.xml if not a symlink
+ if (!fs.lstatSync(configPath).isSymbolicLink()) {
+ // Write out id and name to config.xml; set version to 1.0.0 (to match package.json default version)
+ var conf = new ConfigParser(configPath);
+ if (cfg.id) conf.setPackageName(cfg.id);
+ if (cfg.name) conf.setName(cfg.name);
+ conf.setVersion('1.0.0');
+ conf.write();
+ }
+ });
};
/**
@@ -336,7 +325,7 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
* @param {string} dst for copying
* @return No return value
*/
-function copyIfNotExists(src, dst) {
+function copyIfNotExists (src, dst) {
if (!fs.existsSync(dst) && src) {
shell.mkdir(dst);
shell.cp('-R', path.join(src, '*'), dst);
@@ -353,35 +342,35 @@ function copyIfNotExists(src, dst) {
* projectDir - Project directory
* isSubDir - boolean is true if template has subdirectory structure (see code around line 229)
*/
-function copyTemplateFiles(templateDir, projectDir, isSubDir) {
+function copyTemplateFiles (templateDir, projectDir, isSubDir) {
var copyPath;
// if template is a www dir
if (path.basename(templateDir) === 'www') {
copyPath = path.resolve(templateDir);
shell.cp('-R', copyPath, projectDir);
} else {
- var templateFiles; // Current file
+ var templateFiles; // Current file
templateFiles = fs.readdirSync(templateDir);
// Remove directories, and files that are unwanted
if (!isSubDir) {
- var excludes = ['package.json', 'RELEASENOTES.md' , '.git', 'NOTICE', 'LICENSE', 'COPYRIGHT', '.npmignore'];
- templateFiles = templateFiles.filter( function (value) {
- return excludes.indexOf(value) < 0;
- });
+ var excludes = ['package.json', 'RELEASENOTES.md', '.git', 'NOTICE', 'LICENSE', 'COPYRIGHT', '.npmignore'];
+ templateFiles = templateFiles.filter(function (value) {
+ return excludes.indexOf(value) < 0;
+ });
}
// Copy each template file after filter
for (var i = 0; i < templateFiles.length; i++) {
copyPath = path.resolve(templateDir, templateFiles[i]);
shell.cp('-R', copyPath, projectDir);
}
- }
+ }
}
/**
* @param {String} value
* @return {Boolean} is the input value a url?
*/
-function isUrl(value) {
+function isUrl (value) {
var u = value && url.parse(value);
return !!(u && u.protocol && u.protocol.length > 2); // Account for windows c:/ paths
}
@@ -392,7 +381,7 @@ function isUrl(value) {
* @param {String} project directory to be searched
* @return {String or False} location of config file; if none exists, returns false
*/
-function projectConfig(projectDir) {
+function projectConfig (projectDir) {
var rootPath = path.join(projectDir, 'config.xml');
var wwwPath = path.join(projectDir, 'www', 'config.xml');
if (fs.existsSync(rootPath)) {
@@ -406,12 +395,13 @@ function projectConfig(projectDir) {
/**
* Retrieve and read the .cordova/config file of a cordova project
- *
+ *
* @param {String} project directory
- * @return {JSON data} config file's contents
+ * @return {JSON data} config file's contents
*/
-function dotCordovaConfig(project_root) {
+function dotCordovaConfig (project_root) {
var configPath = path.join(project_root, '.cordova', 'config.json');
+ var data;
if (!fs.existsSync(configPath)) {
data = '{}';
} else {
@@ -422,13 +412,13 @@ function dotCordovaConfig(project_root) {
/**
* Write opts to .cordova/config.json
- *
+ *
* @param {String} project directory
* @param {Object} opts containing the additions to config.json
* @param {Boolean} autopersist option
* @return {JSON Data}
*/
-function writeToConfigJson(project_root, opts, autoPersist) {
+function writeToConfigJson (project_root, opts, autoPersist) {
var json = dotCordovaConfig(project_root);
for (var p in opts) {
json[p] = opts[p];
@@ -437,25 +427,25 @@ function writeToConfigJson(project_root, opts, autoPersist) {
var configPath = path.join(project_root, '.cordova', 'config.json');
var contents = JSON.stringify(json, null, 4);
// Don't write the file for an empty config.
- if (contents != '{}' || fs.existsSync(configPath)) {
+ if (contents !== '{}' || fs.existsSync(configPath)) {
shell.mkdir('-p', path.join(project_root, '.cordova'));
fs.writeFileSync(configPath, contents, 'utf-8');
}
return json;
} else {
- return json;
- }
+ return json;
+ }
}
/**
* Removes existing files and symlinks them if they exist.
- * Symlinks folders: www, merges, hooks
+ * Symlinks folders: www, merges, hooks
* Symlinks file: config.xml (but only if it exists outside of the www folder)
* If config.xml exists inside of template/www, COPY (not link) it to project/
* */
- function linkFromTemplate(templateDir, projectDir) {
+function linkFromTemplate (templateDir, projectDir) {
var linkSrc, linkDst, linkFolders, copySrc, copyDst;
- function rmlinkSync(src, dst, type) {
+ function rmlinkSync (src, dst, type) {
if (src && dst) {
if (fs.existsSync(dst)) {
shell.rm('-rf', dst);
@@ -464,7 +454,7 @@ function writeToConfigJson(project_root, opts, autoPersist) {
fs.symlinkSync(src, dst, type);
}
}
- }
+ }
// if template is a www dir
if (path.basename(templateDir) === 'www') {
linkSrc = path.resolve(templateDir);
@@ -489,4 +479,4 @@ function writeToConfigJson(project_root, opts, autoPersist) {
if (!fs.existsSync(copyDst) && fs.existsSync(copySrc)) {
shell.cp(copySrc, projectDir);
}
- }
+}
http://git-wip-us.apache.org/repos/asf/cordova-create/blob/b5877e51/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 9414210..58f18c4 100644
--- a/package.json
+++ b/package.json
@@ -33,13 +33,19 @@
"valid-identifier": "0.0.1"
},
"devDependencies": {
+ "eslint": "^4.2.0",
+ "eslint-config-semistandard": "^11.0.0",
+ "eslint-config-standard": "^10.2.1",
+ "eslint-plugin-import": "^2.3.0",
+ "eslint-plugin-node": "^5.0.0",
+ "eslint-plugin-promise": "^3.5.0",
+ "eslint-plugin-standard": "^3.0.1",
"jasmine": "^2.4.1",
- "jshint": "2.5.8",
"semver": "^5.3.0"
},
"scripts": {
- "test": "npm run jshint && npm run jasmine",
- "jshint": "jshint index.js spec/create.spec.js",
+ "test": "npm run eslint && npm run jasmine",
+ "eslint": "eslint index.js spec/create.spec.js",
"jasmine": "jasmine spec/create.spec.js"
},
"contributors": [
http://git-wip-us.apache.org/repos/asf/cordova-create/blob/b5877e51/spec/.eslintrc.yml
----------------------------------------------------------------------
diff --git a/spec/.eslintrc.yml b/spec/.eslintrc.yml
new file mode 100644
index 0000000..6afba65
--- /dev/null
+++ b/spec/.eslintrc.yml
@@ -0,0 +1,2 @@
+env:
+ jasmine: true
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-create/blob/b5877e51/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/create.spec.js b/spec/create.spec.js
index f8db27e..1a79a81 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -17,16 +17,14 @@
under the License.
*/
-var helpers = require('./helpers'),
- path = require('path'),
- shell = require('shelljs'),
- events = require('cordova-common').events,
- ConfigParser = require('cordova-common').ConfigParser,
- create = require('../index'),
- fs = require('fs'),
- semver = require('semver'),
- CordovaLogger = require('cordova-common').CordovaLogger.get().setLevel('error');
-
+var helpers = require('./helpers');
+var path = require('path');
+var shell = require('shelljs');
+var events = require('cordova-common').events;
+var ConfigParser = require('cordova-common').ConfigParser;
+var create = require('../index');
+var fs = require('fs');
+var semver = require('semver');
var tmpDir = helpers.tmpDir('create_test');
var appName = 'TestBase';
var appId = 'org.testing';
@@ -35,7 +33,7 @@ var project = path.join(tmpDir, appName);
// Global configuration paths
var global_config_path = process.env.CORDOVA_HOME;
if (!global_config_path) {
- var HOME = process.env[(process.platform.slice(0, 3) == 'win') ? 'USERPROFILE' : 'HOME'];
+ var HOME = process.env[(process.platform.slice(0, 3) === 'win') ? 'USERPROFILE' : 'HOME'];
global_config_path = path.join(HOME, '.cordova');
}
@@ -89,42 +87,40 @@ var configNPM = {
}
};
-describe('cordova create checks for valid-identifier', function() {
- it('should reject reserved words from start of id', function(done) {
+describe('cordova create checks for valid-identifier', function () {
+ it('should reject reserved words from start of id', function (done) {
create('projectPath', 'int.bob', 'appName', {}, events)
- .fail(function(err) {
- expect(err.message).toBe('App id contains a reserved word, or is not a valid identifier.');
- })
- .fin(done);
+ .fail(function (err) {
+ expect(err.message).toBe('App id contains a reserved word, or is not a valid identifier.');
+ })
+ .fin(done);
}, 60000);
-
- it('should reject reserved words from end of id', function(done) {
+
+ it('should reject reserved words from end of id', function (done) {
create('projectPath', 'bob.class', 'appName', {}, events)
- .fail(function(err) {
- expect(err.message).toBe('App id contains a reserved word, or is not a valid identifier.');
- })
- .fin(done);
+ .fail(function (err) {
+ expect(err.message).toBe('App id contains a reserved word, or is not a valid identifier.');
+ })
+ .fin(done);
}, 60000);
});
+describe('create end-to-end', function () {
-describe('create end-to-end', function() {
-
- beforeEach(function() {
+ beforeEach(function () {
shell.rm('-rf', project);
shell.mkdir('-p', tmpDir);
});
-
- afterEach(function() {
- process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
+ afterEach(function () {
+ process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
shell.rm('-rf', tmpDir);
});
- function checkProject() {
+ function checkProject () {
// Check if top level dirs exist.
var dirs = ['hooks', 'platforms', 'plugins', 'www'];
- dirs.forEach(function(d) {
+ dirs.forEach(function (d) {
expect(path.join(project, d)).toExist();
});
@@ -141,15 +137,15 @@ describe('create end-to-end', function() {
// expect(configXml.name()).toEqual('TestBase');
}
- function checkConfigXml() {
+ function checkConfigXml () {
// Check if top level dirs exist.
var dirs = ['hooks', 'platforms', 'plugins', 'www'];
- dirs.forEach(function(d) {
+ dirs.forEach(function (d) {
expect(path.join(project, d)).toExist();
});
expect(path.join(project, 'hooks', 'README.md')).toExist();
-
- //index.js and template subdir folder should not exist (inner files should be copied to the project folder)
+
+ // index.js and template subdir folder should not exist (inner files should be copied to the project folder)
expect(path.join(project, 'index.js')).not.toExist();
expect(path.join(project, 'template')).not.toExist();
@@ -169,15 +165,15 @@ describe('create end-to-end', function() {
expect(configXml.description()).toEqual('this is the correct config.xml');
}
- function checkSubDir() {
+ function checkSubDir () {
// Check if top level dirs exist.
var dirs = ['hooks', 'platforms', 'plugins', 'www'];
- dirs.forEach(function(d) {
+ dirs.forEach(function (d) {
expect(path.join(project, d)).toExist();
});
expect(path.join(project, 'hooks', 'README.md')).toExist();
-
- //index.js and template subdir folder should not exist (inner files should be copied to the project folder)
+
+ // index.js and template subdir folder should not exist (inner files should be copied to the project folder)
expect(path.join(project, 'index.js')).not.toExist();
expect(path.join(project, 'template')).not.toExist();
@@ -199,62 +195,59 @@ describe('create end-to-end', function() {
expect(configXml.description()).toEqual('this is the correct config.xml');
}
- var results;
- events.on('results', function(res) { results = res; });
-
- it('should successfully run without template and use default hello-world app', function(done) {
+ it('should successfully run without template and use default hello-world app', function (done) {
// Create a real project with no template
// use default cordova-app-hello-world app
return create(project, appId, appName, {}, events)
- .then(checkProject)
- .then(function() {
- delete require.cache[require.resolve(path.join(project, 'package.json'))];
- var pkgJson = require(path.join(project, 'package.json'));
- //confirm default hello world app copies over package.json and it matched appId
- expect(pkgJson.name).toEqual(appId);
- }).fail(function(err) {
- console.log(err && err.stack);
- expect(err).toBeUndefined();
- })
- .fin(done);
+ .then(checkProject)
+ .then(function () {
+ delete require.cache[require.resolve(path.join(project, 'package.json'))];
+ var pkgJson = require(path.join(project, 'package.json'));
+ // confirm default hello world app copies over package.json and it matched appId
+ expect(pkgJson.name).toEqual(appId);
+ }).fail(function (err) {
+ console.log(err && err.stack);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
}, 60000);
- it('should successfully run with Git URL', function(done) {
+ it('should successfully run with Git URL', function (done) {
// Create a real project with gitURL as template
return create(project, appId, appName, configGit, events)
- .then(checkProject)
- .fail(function(err) {
- console.log(err && err.stack);
- expect(err).toBeUndefined();
- })
- .fin(done);
+ .then(checkProject)
+ .fail(function (err) {
+ console.log(err && err.stack);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
}, 60000);
- it('should successfully run with NPM package and not use old cache of template on second create', function(done) {
+ it('should successfully run with NPM package and not use old cache of template on second create', function (done) {
var templatePkgJsonPath = path.join(global_config_path, 'node_modules', 'phonegap-template-vue-f7-tabs', 'package.json');
// Create a real project with npm module as template
// tests cache clearing of npm template
// uses phonegap-template-vue-f7-tabs
return create(project, appId, appName, configNPMold)
- .then(checkProject)
- .then(function() {
- shell.rm('-rf', project);
- delete require.cache[require.resolve(templatePkgJsonPath)];
- var pkgJson = require(templatePkgJsonPath);
- expect(pkgJson.version).toBe('1.0.0');
- return create(project, appId, appName, configNPM);
- }).then(function() {
- delete require.cache[require.resolve(templatePkgJsonPath)];
- var pkgJson = require(templatePkgJsonPath);
- expect(semver.gt(pkgJson.version, '1.0.0')).toBeTruthy();
- }).fail(function(err) {
- console.log(err && err.stack);
- expect(err).toBeUndefined();
- })
- .fin(done);
+ .then(checkProject)
+ .then(function () {
+ shell.rm('-rf', project);
+ delete require.cache[require.resolve(templatePkgJsonPath)];
+ var pkgJson = require(templatePkgJsonPath);
+ expect(pkgJson.version).toBe('1.0.0');
+ return create(project, appId, appName, configNPM);
+ }).then(function () {
+ delete require.cache[require.resolve(templatePkgJsonPath)];
+ var pkgJson = require(templatePkgJsonPath);
+ expect(semver.gt(pkgJson.version, '1.0.0')).toBeTruthy();
+ }).fail(function (err) {
+ console.log(err && err.stack);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
}, 60000);
-
- it('should successfully run with template not having a package.json at toplevel', function(done) {
+
+ it('should successfully run with template not having a package.json at toplevel', function (done) {
// Call cordova create with no args, should return help.
var config = {
lib: {
@@ -267,20 +260,20 @@ describe('create end-to-end', function() {
};
// Create a real project
return create(project, appId, appName, config, events)
- .then(checkProject)
- .then(function(){
- // Check that we got the right config.xml
- var configXml = new ConfigParser(path.join(project, 'config.xml'));
- expect(configXml.description()).toEqual('this is the very correct config.xml');
- })
- .fail(function(err) {
- console.log(err && err.stack);
- expect(err).toBeUndefined();
- })
- .fin(done);
+ .then(checkProject)
+ .then(function () {
+ // Check that we got the right config.xml
+ var configXml = new ConfigParser(path.join(project, 'config.xml'));
+ expect(configXml.description()).toEqual('this is the very correct config.xml');
+ })
+ .fail(function (err) {
+ console.log(err && err.stack);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
}, 60000);
-
- it('should successfully run with template having package.json and no sub directory', function(done) {
+
+ it('should successfully run with template having package.json and no sub directory', function (done) {
// Call cordova create with no args, should return help.
var config = {
lib: {
@@ -293,15 +286,15 @@ describe('create end-to-end', function() {
};
// Create a real project
return create(project, appId, appName, config, events)
- .then(checkProject)
- .fail(function(err) {
- console.log(err && err.stack);
- expect(err).toBeUndefined();
- })
- .fin(done);
+ .then(checkProject)
+ .fail(function (err) {
+ console.log(err && err.stack);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
}, 60000);
-
- it('should successfully run with template having package.json, and subdirectory, and no package.json in subdirectory', function(done) {
+
+ it('should successfully run with template having package.json, and subdirectory, and no package.json in subdirectory', function (done) {
// Call cordova create with no args, should return help.
var config = {
lib: {
@@ -315,41 +308,40 @@ describe('create end-to-end', function() {
// Create a real project
return create(project, appId, appName, config, events)
- .then(checkProject)
- .fail(function(err) {
- console.log(err && err.stack);
- expect(err).toBeUndefined();
- })
- .fin(done);
+ .then(checkProject)
+ .fail(function (err) {
+ console.log(err && err.stack);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
}, 60000);
-
- it('should successfully run with template having package.json, and subdirectory, and package.json in subdirectory', function(done) {
+ it('should successfully run with template having package.json, and subdirectory, and package.json in subdirectory', function (done) {
// Call cordova create with no args, should return help.
var config = configSubDirPkgJson;
return create(project, appId, appName, config, events)
- .then(checkSubDir)
- .fail(function(err) {
- console.log(err && err.stack);
- expect(err).toBeUndefined();
- })
- .fin(done);
+ .then(checkSubDir)
+ .fail(function (err) {
+ console.log(err && err.stack);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
}, 60000);
- it('should successfully run config.xml in the www folder and move it outside', function(done) {
+ it('should successfully run config.xml in the www folder and move it outside', function (done) {
// Call cordova create with no args, should return help.
var config = configConfigInWww;
// Create a real project
return create(project, appId, appName, config, events)
- .then(checkConfigXml)
- .fail(function(err) {
- console.log(err && err.stack);
- expect(err).toBeUndefined();
- })
- .fin(done);
+ .then(checkConfigXml)
+ .fail(function (err) {
+ console.log(err && err.stack);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
}, 60000);
- it('should successfully run with www folder as the template', function(done) {
+ it('should successfully run with www folder as the template', function (done) {
var config = {
lib: {
www: {
@@ -360,188 +352,188 @@ describe('create end-to-end', function() {
}
};
return create(project, appId, appName, config, events)
- .then(checkConfigXml)
- .fail(function(err) {
- console.log(err && err.stack);
- expect(err).toBeUndefined();
- })
- .fin(done);
+ .then(checkConfigXml)
+ .fail(function (err) {
+ console.log(err && err.stack);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
}, 60000);
- describe('when --link-to is provided', function() {
- it('when passed www folder should not move www/config.xml, only copy and update', function(done) {
- function checkSymWWW() {
- // Check if top level dirs exist.
- var dirs = ['hooks', 'platforms', 'plugins', 'www'];
- dirs.forEach(function(d) {
- expect(path.join(project, d)).toExist();
- });
- expect(path.join(project, 'hooks', 'README.md')).toExist();
-
- // Check if www files exist.
- expect(path.join(project, 'www', 'index.html')).toExist();
-
- // Check www/config exists
- expect(path.join(project, 'www', 'config.xml')).toExist();
- // Check www/config.xml was not updated.
- var configXml = new ConfigParser(path.join(project, 'www', 'config.xml'));
- expect(configXml.packageName()).toEqual('io.cordova.hellocordova');
- expect(configXml.version()).toEqual('0.0.1');
- expect(configXml.description()).toEqual('this is the correct config.xml');
-
- // Check that config.xml was copied to project/config.xml
- expect(path.join(project, 'config.xml')).toExist();
- configXml = new ConfigParser(path.join(project, 'config.xml'));
- expect(configXml.description()).toEqual('this is the correct config.xml');
- // Check project/config.xml was updated.
- expect(configXml.packageName()).toEqual(appId);
- expect(configXml.version()).toEqual('1.0.0');
-
- // Check that we got no package.json
- expect(path.join(project, 'package.json')).not.toExist();
-
- // Check that www is really a symlink,
- // and project/config.xml , hooks and merges are not
- expect(fs.lstatSync(path.join(project, 'www')).isSymbolicLink()).toBe(true);
- expect(fs.lstatSync(path.join(project, 'hooks')).isSymbolicLink()).not.toBe(true);
- expect(fs.lstatSync(path.join(project, 'config.xml')).isSymbolicLink()).not.toBe(true);
+ describe('when --link-to is provided', function () {
+ it('when passed www folder should not move www/config.xml, only copy and update', function (done) {
+ function checkSymWWW () {
+ // Check if top level dirs exist.
+ var dirs = ['hooks', 'platforms', 'plugins', 'www'];
+ dirs.forEach(function (d) {
+ expect(path.join(project, d)).toExist();
+ });
+ expect(path.join(project, 'hooks', 'README.md')).toExist();
+
+ // Check if www files exist.
+ expect(path.join(project, 'www', 'index.html')).toExist();
+
+ // Check www/config exists
+ expect(path.join(project, 'www', 'config.xml')).toExist();
+ // Check www/config.xml was not updated.
+ var configXml = new ConfigParser(path.join(project, 'www', 'config.xml'));
+ expect(configXml.packageName()).toEqual('io.cordova.hellocordova');
+ expect(configXml.version()).toEqual('0.0.1');
+ expect(configXml.description()).toEqual('this is the correct config.xml');
+
+ // Check that config.xml was copied to project/config.xml
+ expect(path.join(project, 'config.xml')).toExist();
+ configXml = new ConfigParser(path.join(project, 'config.xml'));
+ expect(configXml.description()).toEqual('this is the correct config.xml');
+ // Check project/config.xml was updated.
+ expect(configXml.packageName()).toEqual(appId);
+ expect(configXml.version()).toEqual('1.0.0');
+
+ // Check that we got no package.json
+ expect(path.join(project, 'package.json')).not.toExist();
+
+ // Check that www is really a symlink,
+ // and project/config.xml , hooks and merges are not
+ expect(fs.lstatSync(path.join(project, 'www')).isSymbolicLink()).toBe(true);
+ expect(fs.lstatSync(path.join(project, 'hooks')).isSymbolicLink()).not.toBe(true);
+ expect(fs.lstatSync(path.join(project, 'config.xml')).isSymbolicLink()).not.toBe(true);
+ }
+ var config = {
+ lib: {
+ www: {
+ template: true,
+ url: path.join(__dirname, 'templates', 'config_in_www', 'www'),
+ version: '',
+ link: true
+ }
}
- var config = {
- lib: {
- www: {
- template: true,
- url: path.join(__dirname, 'templates', 'config_in_www', 'www'),
- version: '',
- link: true
+ };
+ return create(project, appId, appName, config, events)
+ .then(checkSymWWW)
+ .fail(function (err) {
+ if (process.platform.slice(0, 3) === 'win') {
+ // Allow symlink error if not in admin mode
+ expect(err.message).toBe('Symlinks on Windows require Administrator privileges');
+ } else {
+ if (err) {
+ console.log(err.stack);
}
+ expect(err).toBeUndefined();
+ }
+ })
+ .fin(done);
+ }, 60000);
+
+ it('with subdirectory should not update symlinked project/config.xml', function (done) {
+ function checkSymSubDir () {
+ // Check if top level dirs exist.
+ var dirs = ['hooks', 'platforms', 'plugins', 'www'];
+ dirs.forEach(function (d) {
+ expect(path.join(project, d)).toExist();
+ });
+ expect(path.join(project, 'hooks', 'README.md')).toExist();
+
+ // index.js and template subdir folder should not exist (inner files should be copied to the project folder)
+ expect(path.join(project, 'index.js')).not.toExist();
+ expect(path.join(project, 'template')).not.toExist();
+
+ // Check if www files exist.
+ expect(path.join(project, 'www', 'index.html')).toExist();
+
+ // Check that www, and config.xml is really a symlink
+ expect(fs.lstatSync(path.join(project, 'www')).isSymbolicLink()).toBe(true);
+ expect(fs.lstatSync(path.join(project, 'config.xml')).isSymbolicLink()).toBe(true);
+
+ // Check that config.xml was not updated. (symlinked config does not get updated!)
+ var configXml = new ConfigParser(path.join(project, 'config.xml'));
+ expect(configXml.packageName()).toEqual('io.cordova.hellocordova');
+ expect(configXml.version()).toEqual('0.0.1');
+
+ // Check that we got the right config.xml
+ expect(configXml.description()).toEqual('this is the correct config.xml');
+
+ delete require.cache[require.resolve(path.join(project, 'package.json'))];
+ // Check that we got package.json (the correct one) and it was changed
+ var pkjson = require(path.join(project, 'package.json'));
+ // Pkjson.name should equal config's id.
+ expect(pkjson.name).toEqual(appId.toLowerCase());
+ expect(pkjson.valid).toEqual('true');
+ }
+ var config = {
+ lib: {
+ www: {
+ template: true,
+ url: path.join(__dirname, 'templates', 'withsubdirectory_package_json'),
+ version: '',
+ link: true
}
- };
- return create(project, appId, appName, config, events)
- .then(checkSymWWW)
- .fail(function(err) {
- if(process.platform.slice(0, 3) == 'win') {
- // Allow symlink error if not in admin mode
- expect(err.message).toBe('Symlinks on Windows require Administrator privileges');
- } else {
- if (err) {
- console.log(err.stack);
- }
- expect(err).toBeUndefined();
- }
- })
- .fin(done);
- }, 60000);
-
- it('with subdirectory should not update symlinked project/config.xml', function(done) {
- function checkSymSubDir() {
- // Check if top level dirs exist.
- var dirs = ['hooks', 'platforms', 'plugins', 'www'];
- dirs.forEach(function(d) {
- expect(path.join(project, d)).toExist();
- });
- expect(path.join(project, 'hooks', 'README.md')).toExist();
-
- //index.js and template subdir folder should not exist (inner files should be copied to the project folder)
- expect(path.join(project, 'index.js')).not.toExist();
- expect(path.join(project, 'template')).not.toExist();
-
- // Check if www files exist.
- expect(path.join(project, 'www', 'index.html')).toExist();
-
- // Check that www, and config.xml is really a symlink
- expect(fs.lstatSync(path.join(project, 'www')).isSymbolicLink()).toBe(true);
- expect(fs.lstatSync(path.join(project, 'config.xml')).isSymbolicLink()).toBe(true);
-
- // Check that config.xml was not updated. (symlinked config does not get updated!)
- var configXml = new ConfigParser(path.join(project, 'config.xml'));
- expect(configXml.packageName()).toEqual('io.cordova.hellocordova');
- expect(configXml.version()).toEqual('0.0.1');
-
- // Check that we got the right config.xml
- expect(configXml.description()).toEqual('this is the correct config.xml');
-
- delete require.cache[require.resolve(path.join(project, 'package.json'))];
- // Check that we got package.json (the correct one) and it was changed
- var pkjson = require(path.join(project, 'package.json'));
- // Pkjson.name should equal config's id.
- expect(pkjson.name).toEqual(appId.toLowerCase());
- expect(pkjson.valid).toEqual('true');
}
- var config = {
- lib: {
- www: {
- template: true,
- url: path.join(__dirname, 'templates', 'withsubdirectory_package_json'),
- version: '',
- link: true
+ };
+ return create(project, appId, appName, config, events)
+ .then(checkSymSubDir)
+ .fail(function (err) {
+ if (process.platform.slice(0, 3) === 'win') {
+ // Allow symlink error if not in admin mode
+ expect(err.message).toBe('Symlinks on Windows require Administrator privileges');
+ } else {
+ if (err) {
+ console.log(err.stack);
}
+ expect(err).toBeUndefined();
}
- };
- return create(project, appId, appName, config, events)
- .then(checkSymSubDir)
- .fail(function(err) {
- if(process.platform.slice(0, 3) == 'win') {
- // Allow symlink error if not in admin mode
- expect(err.message).toBe('Symlinks on Windows require Administrator privileges');
- } else {
- if (err) {
- console.log(err.stack);
- }
- expect(err).toBeUndefined();
- }
- })
- .fin(done);
- }, 60000);
-
- it('with no config should create one and update it', function(done) {
- function checkSymNoConfig() {
- // Check if top level dirs exist.
- var dirs = ['hooks', 'platforms', 'plugins', 'www'];
- dirs.forEach(function(d) {
- expect(path.join(project, d)).toExist();
- });
- expect(path.join(project, 'hooks', 'hooks.file')).toExist();
- expect(path.join(project, 'merges', 'merges.file')).toExist();
-
- // Check if www files exist.
- expect(path.join(project, 'www', 'index.html')).toExist();
-
- // Check that config.xml was updated.
- var configXml = new ConfigParser(path.join(project, 'config.xml'));
- expect(configXml.packageName()).toEqual(appId);
-
- // Check that www, hooks, merges are really a symlink; config is not
- expect(fs.lstatSync(path.join(project, 'www')).isSymbolicLink()).toBe(true);
- expect(fs.lstatSync(path.join(project, 'hooks')).isSymbolicLink()).toBe(true);
- expect(fs.lstatSync(path.join(project, 'merges')).isSymbolicLink()).toBe(true);
- expect(fs.lstatSync(path.join(project, 'config.xml')).isSymbolicLink()).not.toBe(true);
- }
+ })
+ .fin(done);
+ }, 60000);
+
+ it('with no config should create one and update it', function (done) {
+ function checkSymNoConfig () {
+ // Check if top level dirs exist.
+ var dirs = ['hooks', 'platforms', 'plugins', 'www'];
+ dirs.forEach(function (d) {
+ expect(path.join(project, d)).toExist();
+ });
+ expect(path.join(project, 'hooks', 'hooks.file')).toExist();
+ expect(path.join(project, 'merges', 'merges.file')).toExist();
+
+ // Check if www files exist.
+ expect(path.join(project, 'www', 'index.html')).toExist();
+
+ // Check that config.xml was updated.
+ var configXml = new ConfigParser(path.join(project, 'config.xml'));
+ expect(configXml.packageName()).toEqual(appId);
+
+ // Check that www, hooks, merges are really a symlink; config is not
+ expect(fs.lstatSync(path.join(project, 'www')).isSymbolicLink()).toBe(true);
+ expect(fs.lstatSync(path.join(project, 'hooks')).isSymbolicLink()).toBe(true);
+ expect(fs.lstatSync(path.join(project, 'merges')).isSymbolicLink()).toBe(true);
+ expect(fs.lstatSync(path.join(project, 'config.xml')).isSymbolicLink()).not.toBe(true);
+ }
- var config = {
- lib: {
- www: {
- template: true,
- url: path.join(__dirname, 'templates', 'noconfig'),
- version: '',
- link: true
- }
+ var config = {
+ lib: {
+ www: {
+ template: true,
+ url: path.join(__dirname, 'templates', 'noconfig'),
+ version: '',
+ link: true
}
- };
- return create(project, appId, appName, config, events)
- .then(checkSymNoConfig)
- .fail(function(err) {
- if(process.platform.slice(0, 3) == 'win') {
- // Allow symlink error if not in admin mode
- expect(err.message).toBe('Symlinks on Windows require Administrator privileges');
- } else {
- if (err) {
- console.log(err.stack);
- }
- expect(err).toBeUndefined();
+ }
+ };
+ return create(project, appId, appName, config, events)
+ .then(checkSymNoConfig)
+ .fail(function (err) {
+ if (process.platform.slice(0, 3) === 'win') {
+ // Allow symlink error if not in admin mode
+ expect(err.message).toBe('Symlinks on Windows require Administrator privileges');
+ } else {
+ if (err) {
+ console.log(err.stack);
}
- })
- .fin(done);
- }, 60000);
+ expect(err).toBeUndefined();
+ }
+ })
+ .fin(done);
+ }, 60000);
- });
+ });
});
http://git-wip-us.apache.org/repos/asf/cordova-create/blob/b5877e51/spec/helpers.js
----------------------------------------------------------------------
diff --git a/spec/helpers.js b/spec/helpers.js
index a5f5d54..174a7ae 100644
--- a/spec/helpers.js
+++ b/spec/helpers.js
@@ -17,16 +17,16 @@
under the License.
*/
-var path = require('path'),
- fs = require('fs'),
- shell = require('shelljs'),
- os = require('os'),
+var path = require('path'),
+ fs = require('fs'),
+ shell = require('shelljs'),
+ os = require('os'),
ConfigParser = require('cordova-common').ConfigParser;
// Just use Android everywhere; we're mocking out any calls to the `android` binary.
module.exports.testPlatform = 'android';
-function getConfigPath(dir) {
+function getConfigPath (dir) {
// if path ends with 'config.xml', return it
if (dir.indexOf('config.xml') == dir.length - 10) {
return dir;
@@ -40,7 +40,7 @@ module.exports.tmpDir = function (subdir) {
if (subdir) {
dir = path.join(dir, subdir);
}
- if(fs.existsSync(dir)) {
+ if (fs.existsSync(dir)) {
shell.rm('-rf', dir);
}
shell.mkdir('-p', dir);
@@ -156,17 +156,16 @@ beforeEach(function () {
var result = {};
result.pass = fs.existsSync(testPath);
- if(result.pass) {
+ if (result.pass) {
result.message = 'Expected file ' + testPath + ' to exist.';
} else {
result.message = 'Expected file ' + testPath + ' to not exist.';
}
- return result
+ return result;
}
- }
+ };
}
});
});
-
http://git-wip-us.apache.org/repos/asf/cordova-create/blob/b5877e51/spec/templates/withsubdirectory/index.js
----------------------------------------------------------------------
diff --git a/spec/templates/withsubdirectory/index.js b/spec/templates/withsubdirectory/index.js
index 4cb425b..c56ae49 100644
--- a/spec/templates/withsubdirectory/index.js
+++ b/spec/templates/withsubdirectory/index.js
@@ -1,4 +1,4 @@
var path = require('path');
module.exports = {
- "dirname": path.join(__dirname, 'template')
-};
\ No newline at end of file
+ 'dirname': path.join(__dirname, 'template')
+};
http://git-wip-us.apache.org/repos/asf/cordova-create/blob/b5877e51/spec/templates/withsubdirectory_package_json/index.js
----------------------------------------------------------------------
diff --git a/spec/templates/withsubdirectory_package_json/index.js b/spec/templates/withsubdirectory_package_json/index.js
index 4cb425b..c56ae49 100644
--- a/spec/templates/withsubdirectory_package_json/index.js
+++ b/spec/templates/withsubdirectory_package_json/index.js
@@ -1,4 +1,4 @@
var path = require('path');
module.exports = {
- "dirname": path.join(__dirname, 'template')
-};
\ No newline at end of file
+ 'dirname': path.join(__dirname, 'template')
+};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org