Github user stevengill commented on a diff in the pull request:
https://github.com/apache/cordova-lib/pull/456#discussion_r67084182
--- Diff: cordova-lib/src/cordova/create.js ---
@@ -252,133 +249,116 @@ function create(dir, optionalId, optionalName, cfg,
fetchOpt) {
www: import_from_path
};
- // Keep going into child "www" folder if exists in stock app
package.
+ // Keep going into child "www" folder if exists in stock app
package; used to find config.xml
while (fs.existsSync(path.join(paths.www, 'www'))) {
paths.root = paths.www;
paths.www = path.join(paths.root, 'www');
}
- // find config.xml
+ // find config.xml OR get stock config.xml, used if template does
not contain config.xml
if (fs.existsSync(path.join(paths.root, 'config.xml'))) {
paths.configXml = path.join(paths.root, 'config.xml');
- paths.configXmlLinkable = true;
} else {
- try {
- paths.configXml =
- path.join(require('cordova-app-hello-world').dirname,
- 'config.xml');
- } catch (e) {
- // Falling back on npm@2 path hierarchy
- // TODO: Remove fallback after cordova-app-hello-world
release
- paths.configXml =
- path.join(__dirname, '..', '..', 'node_modules',
- 'cordova-app-hello-world', 'config.xml');
- }
- }
- if (fs.existsSync(path.join(paths.root, 'merges'))) {
- paths.merges = path.join(paths.root, 'merges');
- } else {
- // No merges by default
- }
- if (fs.existsSync(path.join(paths.root, 'hooks'))) {
- paths.hooks = path.join(paths.root, 'hooks');
- paths.hooksLinkable = true;
- } else {
- try {
- paths.hooks =
- path.join(require('cordova-app-hello-world').dirname,
- 'hooks');
- } catch (e) {
- // Falling back on npm@2 path hierarchy
- // TODO: Remove fallback after cordova-app-hello-world
release
- paths.hooks =
- path.join(__dirname, '..', '..', 'node_modules',
- 'cordova-app-hello-world', 'hooks');
- }
+ 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 hooks; used if template does not contain hooks
+ paths.hooks =
path.join(require('cordova-app-hello-world').dirname, 'hooks');
+
+
var dirAlreadyExisted = fs.existsSync(dir);
if (!dirAlreadyExisted) {
fs.mkdirSync(dir);
}
-
- var tryToLink = !!cfg.lib.www.link;
- function copyOrLink(src, dst, linkable) {
- if (src) {
- if (tryToLink && linkable) {
- fs.symlinkSync(src, dst, 'dir');
- } else {
- shell.mkdir(dst);
- shell.cp('-R', path.join(src, '*'), dst);
- }
- }
- }
-
- /*
- Copies template files, and directories into a Cordova project
directory.
- Files, and directories not copied include: www, mergers,platforms,
- plugins, hooks, and config.xml. A template directory, and platform
- directory must be passed.
-
- templateDir - Template directory
- projectDir - Project directory
- */
- function copyTemplateFiles(templateDir, projectDir) {
- var templateFiles; // Current file
-
- templateFiles = fs.readdirSync(templateDir);
-
- // Remove directories, and files that are automatically copied
- templateFiles = templateFiles.filter(
- function (value) {
- return !(value === 'www' || value === 'mergers' ||
- value === 'config.xml' || value === 'hooks');
- }
- );
-
- // Copy each template file
- for (var i = 0; i < templateFiles.length; i++)
- shell.cp('-R', path.resolve(templateDir,
templateFiles[i]), projectDir);
- }
-
try {
- copyOrLink(paths.www, path.join(dir, 'www'), true);
- copyOrLink(paths.merges, path.join(dir, 'merges'), true);
- copyOrLink(paths.hooks, path.join(dir, 'hooks'),
- paths.hooksLinkable);
-
+ // Copy files from template to project
if (cfg.lib.www.template)
- copyTemplateFiles(import_from_path, dir);
+ copyTemplateFiles(import_from_path, dir, isSubDir);
- if (paths.configXml) {
- if (tryToLink && paths.configXmlLinkable) {
- fs.symlinkSync(paths.configXml, path.join(dir,
'config.xml'));
- } else {
- shell.cp(paths.configXml, path.join(dir,
'config.xml'));
- }
+ // If following were not copied from template, copy from stock
app hello world
+ ifNotCopied(paths.www, path.join(dir, 'www'));
+ ifNotCopied(paths.hooks, path.join(dir, 'hooks'));
+ if (!fs.existsSync(path.join(dir, 'config.xml')) &&
paths.configXml) {
+ 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;
}
+
+ // Update package.json name and version fields.
+ if (fs.existsSync(path.join(dir, 'package.json'))) {
+ var pkgjson = require(path.resolve(dir, 'package.json'));
+ if (cfg.name) {
+ pkgjson.name = cfg.name.toLowerCase();
+ }
+ pkgjson.version = '1.0.0';
+ fs.writeFile(path.join(dir, 'package.json'),
JSON.stringify(pkgjson), function (err) {
--- End diff --
Lets maybe do the write operation as Sync and lets add spaces to the new
package.json file. See
https://github.com/apache/cordova-lib/blob/9f630271d9c02824c0031ea4cdc0e4955b53d9e2/cordova-lib/src/plugman/registry/manifest.js#L101
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]