-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:aliyun/fun
- Loading branch information
Showing
51 changed files
with
1,654 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,8 @@ examples/local/java8/target/* | |
|
||
output | ||
.oss_cfg | ||
|
||
*.pyc | ||
*.iml | ||
*.class | ||
*.class | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env node | ||
|
||
/* eslint-disable quotes */ | ||
|
||
'use strict'; | ||
|
||
const program = require('commander'); | ||
|
||
const examples = | ||
` | ||
Examples: | ||
$ fun init | ||
$ fun init helloworld-nodejs8 | ||
$ fun init foo/bar | ||
$ fun init gh:foo/bar | ||
$ fun init gl:foo/bar | ||
$ fun init bb:foo/bar | ||
$ fun init github:foo/bar | ||
$ fun init gitlab:foo/bar | ||
$ fun init bitbucket:foo/bar | ||
$ fun init git+ssh://[email protected]/foo/bar.git | ||
$ fun init hg+ssh://[email protected]/bar/foo | ||
$ fun init [email protected]:foo/bar.git | ||
$ fun init https://github.com/foo/bar.git | ||
$ fun init /path/foo/bar | ||
$ fun init -n fun-app -V foo=bar /path/foo/bar | ||
`; | ||
|
||
const parseVars = (val, vars) => { | ||
/* | ||
* Key-value pairs, separated by equal signs | ||
* keys can only contain letters, numbers, and underscores | ||
* values can be any character | ||
*/ | ||
const group = val.match(/(^[a-zA-Z_][a-zA-Z\d_]*)=(.*)/); | ||
vars = vars || {}; | ||
if (group) { | ||
vars[group[1]] = group[2]; | ||
} | ||
return vars; | ||
}; | ||
|
||
program | ||
.name('fun init') | ||
.usage('[options] [location]') | ||
.description('Initializes a new fun project.') | ||
.option('-o, --output-dir [path]', 'where to output the initialized app into', '.') | ||
.option('-n, --name [name]', 'name of your project to be generated as a folder', 'fun-app') | ||
.option('--no-input [noInput]', 'disable prompting and accept default values defined template config') | ||
.option('-V, --var [vars]', 'template variable', parseVars) | ||
.on('--help', () => { | ||
console.log(examples); | ||
}) | ||
.parse(process.argv); | ||
|
||
const context = { | ||
name: program.name, | ||
outputDir: program.outputDir, | ||
input: program.input, | ||
vars: program.var || {} | ||
}; | ||
|
||
if (program.args.length > 0) { | ||
context.location = program.args[0]; | ||
} | ||
|
||
require('../lib/commands/init')(context).catch(require('../lib/exception-handler')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ tmp/ | |
usr/ | ||
.env | ||
package-lock.json | ||
template.yml | ||
template.yml | ||
|
||
.funignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const { determineRepoDir, getOfficialTemplates } = require('../init/repository'); | ||
const { render } = require('../init/renderer'); | ||
const { sync } = require('rimraf'); | ||
const { buildContext } = require('../init/context'); | ||
const { promptForTemplate } = require('../init/prompt'); | ||
const debug = require('debug')('fun:init'); | ||
|
||
function cleanTemplate(repoDir) { | ||
debug('Cleaning Template: %', repoDir); | ||
sync(repoDir); | ||
} | ||
|
||
async function init(context) { | ||
debug('location is: %s', context.location); | ||
context.templates = getOfficialTemplates(); | ||
if (!context.location) { | ||
context.location = await promptForTemplate(Object.keys(context.templates)); | ||
} | ||
const {repoDir, clean} = await determineRepoDir(context); | ||
await buildContext(repoDir, context); | ||
render(context); | ||
if (clean) { | ||
cleanTemplate(repoDir); | ||
} | ||
|
||
} | ||
|
||
module.exports = init; |
Oops, something went wrong.