You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Carlos Santana (JIRA)" <ji...@apache.org> on 2016/03/08 16:40:41 UTC

[jira] [Updated] (CB-10808) cordova template should have api to specify directory name with template content

     [ https://issues.apache.org/jira/browse/CB-10808?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Carlos Santana updated CB-10808:
--------------------------------
    Description: 
When creating an app using a template from npm like:

cordova create myapp --template my-cool-cdv-template

App is created with content of root of the npm pacakge.

By doing this all files are copied from the template.

In some cases some files are not desire to end up in the new app, files that are related to testing, packaging, source control, etc..
Some files are:
package.json
And some time you want the new app to have a package.json provided by the template but not the template's pacakge.json

We should implement same way we do cordova-app-hello-world npm package
main module exports an object with a property dirname

Example:
Content of package.tgz from npm
package.json
lib/
.gitignore
template_content/
template_content/package.json
template_content/www
template_content/config.xml
index.js

Content of package.json
{
"name": "my-cool-cdv-template",
"main": "./index.js"
}

Content of template.js:
path=require('path');
exports = {
   "dirname": path.join(__dirname,'template_content');
}

proposed changes:
https://github.com/apache/cordova-lib/blob/master/cordova-lib/src/cordova/create.js#L308
{code}
function copyTemplateFiles(templateDir, projectDir) {
            var templateFiles;		// Current file
            var templatePkg;
            var templateDir;
            templatePkg = require(projectDir);
            if(templatePkg && templatePkg.dirname){
              templateDir = templatePkg.dirname;
            } else {
              templateDir = projectDir;
            }
            templateFiles = fs.readdirSync(templateDir);
//...
}
{code}


  was:
When creating an app using a template from npm like:

cordova create myapp --template my-cool-cdv-template

App is created with content of root of the npm pacakge.

By doing this all files are copied from the template.

In some cases some files are not desire to end up in the new app, files that are related to testing, packaging, source control
Some files are:
package.json
And some time you want the new app to have a package.json provided by the template but not the template's pacakge.json

We should implement same way we do cordova-app-hello-world npm package
main module exports an object with a property dirname

Example:
Content of package.tgz from npm
package.json
lib/
.gitignore
template_content/
template_content/package.json
template_content/www
template_content/config.xml
index.js

Content of package.json
{
"name": "my-cool-cdv-template",
"main": "./index.js"
}

Content of template.js:
path=require('path');
exports = {
   "dirname": path.join(__dirname,'template_content');
}

proposed changes:
https://github.com/apache/cordova-lib/blob/master/cordova-lib/src/cordova/create.js#L308
{code}
function copyTemplateFiles(templateDir, projectDir) {
            var templateFiles;		// Current file
            var templatePkg;
            var templateDir;
            templatePkg = require(projectDir);
            if(templatePkg && templatePkg.dirname){
              templateDir = templatePkg.dirname;
            } else {
              templateDir = projectDir;
            }
            templateFiles = fs.readdirSync(templateDir);
//...
}
{code}



> cordova template should have api to specify directory name with template content
> --------------------------------------------------------------------------------
>
>                 Key: CB-10808
>                 URL: https://issues.apache.org/jira/browse/CB-10808
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: CLI
>            Reporter: Carlos Santana
>            Assignee: Carlos Santana
>
> When creating an app using a template from npm like:
> cordova create myapp --template my-cool-cdv-template
> App is created with content of root of the npm pacakge.
> By doing this all files are copied from the template.
> In some cases some files are not desire to end up in the new app, files that are related to testing, packaging, source control, etc..
> Some files are:
> package.json
> And some time you want the new app to have a package.json provided by the template but not the template's pacakge.json
> We should implement same way we do cordova-app-hello-world npm package
> main module exports an object with a property dirname
> Example:
> Content of package.tgz from npm
> package.json
> lib/
> .gitignore
> template_content/
> template_content/package.json
> template_content/www
> template_content/config.xml
> index.js
> Content of package.json
> {
> "name": "my-cool-cdv-template",
> "main": "./index.js"
> }
> Content of template.js:
> path=require('path');
> exports = {
>    "dirname": path.join(__dirname,'template_content');
> }
> proposed changes:
> https://github.com/apache/cordova-lib/blob/master/cordova-lib/src/cordova/create.js#L308
> {code}
> function copyTemplateFiles(templateDir, projectDir) {
>             var templateFiles;		// Current file
>             var templatePkg;
>             var templateDir;
>             templatePkg = require(projectDir);
>             if(templatePkg && templatePkg.dirname){
>               templateDir = templatePkg.dirname;
>             } else {
>               templateDir = projectDir;
>             }
>             templateFiles = fs.readdirSync(templateDir);
> //...
> }
> {code}



--
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