Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26920] Add ability to create new app from a template

GitHub Issuen/a
TypeNew Feature
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelscb-tooling, engTriage
ReporterBrenton House
AssigneeAbir Mukherjee
Created2019-03-22T15:12:50.000+0000
Updated2020-11-23T17:53:16.000+0000

Description

I think there have been similar tickets in the past but this feature is focused on the ability to create a new Titanium mobile app (using Alloy or another framework) from any source. - Local directory - Tarball (url) - npm package - Git repo (GitHub, Bitbucket, GitLab, etc) This would significantly expand the options for developers that are creating new apps and allow Axway (and others) to provide templates for many different kinds of apps (with variations). One way to achieve this is to take advantage of npm and the power it has to do almost all this already. The Titanium CLI can simply spawn npm to install from any of these sources and then template the newly installed app based on parameters from CLI or config. It could also provide the option for installing from local directory where no package.json file exists by just copying the files locally.

Comments

  1. Christopher Williams 2019-03-22

    So, some thoughts: - We have this general idea in Studio where you have sample projects/templates and here it's more outwardly exposed to the user as they have to select one at project creation - We have project templates in alloy and classic apps, but it's just sort of baked in. I agree, we should move this to a behavior that's easier to consume via npm packages so that we can use it in Atom/VSCode/CLI. As for how it occurs, that'd be something we'd need to try out - do we pass a special arg to ti create/appc new? Do we have users run something like npx my-awesome-template in the root of a project and it just modifies the project in-place?
  2. Chris Barber 2019-03-22

    Titanium CLI already supports creating new apps using a built-in template by name, a local path to a directory containing a template project, a local path to a zip file, or a URL to a zip file to download. We could easily add support to https://github.com/appcelerator/titanium_mobile/blob/master/cli/lib/creator.js for installing a template from npm or a git repo. To be clear, this functionality goes in the Titanium SDK today, but eventually in titaniumlib.
  3. Ewan Harris 2019-03-22

    I think we should prefer git repos over publishing to npm here, it seems unnatural to publish templates to npm to me (I'm not aware of any project that does this today). It is super simple to fetch archives (zips or tarballs) from git hosting services, I built [targit](https://github.com/ewanharris/targit) to achieve this with amplify pm, it definitely supports GitHub, and should be fine with Bitbucket and GitLab (assuming I can read their docs just fine), I've had it on the backburner for a while to improve the testing there. You can reference by tags or branches for these services so you even get versioning for free! One thing in addition here that I think would be crucial to have is ti create --type template, that chucks all the needed stuff in a directory rather than leaving people blind as to what's needed, that could even take an existing project and then convert it to a template if we're feeling super adventurous.
  4. Chris Barber 2019-03-22

    It also might not be a bad idea to consider supporting installing templates via the AMPLIFY CLI Package Manager since that front-ends the marketplace (in addition to GitHub and npm).
  5. Brenton House 2019-03-22

    Here is a link to a simple tool I created that does something like this: https://www.npmjs.com/package/@geek/mobile#mobile-appcreate-name-template I think templating variable in the template would be important but optional for the developer. A template could be just an existing app and it could just reset the GUID, ID, and name on it. Installing a template from npm, as well as GitHub, will then easily support versioning of templates. If a developer wants to use a specific version of a template (for one reason or another), they can do that. Using post-install scripts with npm could also be very handy for doing any template-specific transformations necessary for the new mobile app.
  6. Chris Barber 2019-03-22

    [~bhouse] I fail to understand why you created yet another CLI instead of just helping us improve our own products. You have great ideas and the team is open to your input and help. How about spending the time coming up with a spec that takes into account what other project are doing, handles downloading from various sources, file placement, file renaming, variable replacing, file generation, etc. What is the template install lifecycle? Why would we spawn npm instead of just using libnpm? Should we be responsible for installing npm dependencies or the app developer? How are we going to handle conflicts? There are several scenarios and details to be worked out. Once we know what it is we want to build, then we can add it the Titanium CLI and all of our users can benefit.
  7. Brenton House 2019-03-22

    [~cbarber] Sorry! I wrote the tool as a temporary solution to an existing need I had and I didn't mean to create a problem. I was going to keep it to myself but thought it might be good to share with community as well. This tool just took a couple of hours to write so there is not much invested in it. By taking advantage of pre-existing libraries, there was actually very little code I had to write. This was intended to be more along the lines of open-source projects like https://github.com/jasonkneen/tn, https://github.com/jasonkneen/TiTh, https://github.com/jasonkneen/TiCons-CLI, https://github.com/propelics/tiapp-updater, https://github.com/jasonkneen/RESTe, and other tools that enhance the developer experience of working with Titanium. I will reach out to you and others offline to see what I can do to help with creating a spec and helping to get these features into the Titanium CLI. - on npmlib: I don't think libnpm supports installing but we could probably just spawn npm to do it. - on npm dependencies: Not sure what we want for Titanium CLI but the tool is running npm install to install dependencies right after creation of project. - on conflicts: I am not exactly sure which conflicts we need to handle but I agree, we should work out details and rules.
  8. Ewan Harris 2019-03-25

    libnpm is the pieces that you can put together to make npm install, so for example you'd fetch the tarball via this and then call the extract function if you'd want (or just use a custom one). This would avoid having to do things like * shelling out to the npm cli where you'd be taking a hit on performance and having to code around handling their error codes * running npm install <template> then digging into the node_modules to pull the template out, you'd just grab the tarball and extract it where you want it. This should be fairly easy to implement I believe. We probably just need to build on the code [here](https://github.com/appcelerator/titanium_mobile/blob/c81b3e12c42909c1211f8bf2125c710d5eed74e5/cli/lib/creator.js#L551-L596), it may just need some bikeshedding to determine how we want to differentiate between the template locations, do we do name prefixes like git:appcelerator/my-awesome-template/npm:my-awesome-template

JSON Source