cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-11412) Update template implementation in cordova create --template
Date Wed, 15 Jun 2016 00:59:30 GMT

    [ https://issues.apache.org/jira/browse/CB-11412?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15330961#comment-15330961
] 

ASF GitHub Bot commented on CB-11412:
-------------------------------------

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


> Update template implementation in cordova create --template
> -----------------------------------------------------------
>
>                 Key: CB-11412
>                 URL: https://issues.apache.org/jira/browse/CB-11412
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: CordovaLib
>            Reporter: Caryn Tran
>            Assignee: Caryn Tran
>
> https://github.com/cordova/cordova-discuss/pull/49
> Sometimes we do want a `package.json` copied over. `package.json` could have build scripts
that are essential for the template to work. To handle this use case, template authors are
suggested to put template files in a subdirectory and point to that subdirectory in index.js.
All files in the subdirectory are copied over.
> Update the current template implementation to ignore the list of files above that shouldn't
be copied over when using `--template`. If a subdirectory is used, copy the entire contents
of the subdirectory.
> If a `package.json` exists in the subdirectory, we should update its fields like we do
to `config.xml`. https://github.com/apache/cordova-lib/blob/master/cordova-lib/src/cordova/create.js#L378-L382.
Only field to update in `package.json` should be `package.name`. `package.name` should be
updated to use `config.name` lowercased (npm package names have to be lowercase). `config.name`
is the optional third argument `cordova create` takes.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message