Merge branch 'feature/create-portal-app' of github.com:datopian/portal.js into feature/create-portal-app
This commit is contained in:
commit
cadc4c8bf8
91
packages/create-portal-app/index.js
Normal file → Executable file
91
packages/create-portal-app/index.js
Normal file → Executable file
@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { program } = require('commander')
|
||||
const chalk = require('chalk')
|
||||
const prompts = require('prompts')
|
||||
const package = require('./package.json')
|
||||
|
||||
// Output path to create new portal app
|
||||
let path = ''
|
||||
|
||||
|
||||
// Commander parameters to specify CLI behavior
|
||||
program.name(package.name)
|
||||
.version(package.version)
|
||||
.arguments('[dir]')
|
||||
.usage(`${chalk.yellow('[dir]')}`)
|
||||
.description({
|
||||
dir: 'Directory to be used on install Portal.js'
|
||||
})
|
||||
.action(name => path = name)
|
||||
.allowUnknownOption()
|
||||
.parse(process.argv)
|
||||
|
||||
|
||||
/**
|
||||
* Method to ask a custon name if was not passed as parameter
|
||||
* returns the value passed from terminal input
|
||||
*/
|
||||
async function promptPath(){
|
||||
return prompts({
|
||||
type: 'text',
|
||||
name: 'path',
|
||||
message: 'Choose a name to your project',
|
||||
initial: '',
|
||||
validate: name => {
|
||||
//TODO Method to validate valid path name
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method to start CLI and validate inputs
|
||||
*/
|
||||
async function run(){
|
||||
if(typeof path === 'string'){
|
||||
path = path.trim()
|
||||
}
|
||||
if(!path){
|
||||
const response = await promptPath()
|
||||
if(typeof response.path === 'string'){
|
||||
path = response.path.trim()
|
||||
}
|
||||
}
|
||||
if(!path){
|
||||
console.log()
|
||||
console.log('Please choose a name to your project:')
|
||||
console.log()
|
||||
console.log('Example:')
|
||||
console.log(`${chalk.cyan(program.name())} ${chalk.yellow('ny-portal-app')}`)
|
||||
console.log()
|
||||
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Include workflow to create and manage the files and options
|
||||
*
|
||||
* Example:
|
||||
* createApp()
|
||||
* .then(installDependencies)
|
||||
* .then(renameFiles)
|
||||
* .then(accessFolder)
|
||||
* .then(checkUpdated)
|
||||
*/
|
||||
}
|
||||
|
||||
//Main CLI execution workflow
|
||||
run()
|
||||
.then(`${chalk.greenBright('Project Installed Sucess')}`)
|
||||
.catch(error => {
|
||||
if(error.command){
|
||||
console.log(`${chalk.cyan('Error on Create App')}`)
|
||||
}else{
|
||||
console.log(`${chalk.red('Unexpected Erro. Please report it as a bug')}`)
|
||||
console.log(error)
|
||||
}
|
||||
console.log()
|
||||
process.exit(1)
|
||||
})
|
||||
17
packages/create-portal-app/package-lock.json
generated
17
packages/create-portal-app/package-lock.json
generated
@ -895,6 +895,10 @@
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
|
||||
"integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw=="
|
||||
"kleur": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz",
|
||||
"integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w=="
|
||||
},
|
||||
"log-symbols": {
|
||||
"version": "4.0.0",
|
||||
@ -1207,6 +1211,15 @@
|
||||
"resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz",
|
||||
"integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs="
|
||||
},
|
||||
"prompts": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.0.tgz",
|
||||
"integrity": "sha512-awZAKrk3vN6CroQukBL+R9051a4R3zCZBlJm/HBfrSZ8iTpYix3VX1vU4mveiLpiwmOJT4wokTF9m6HUk4KqWQ==",
|
||||
"requires": {
|
||||
"kleur": "^3.0.3",
|
||||
"sisteransi": "^1.0.5"
|
||||
}
|
||||
},
|
||||
"pump": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
||||
@ -1456,6 +1469,10 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
"sisteransi": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",
|
||||
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg=="
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
|
||||
@ -14,7 +14,8 @@
|
||||
"cpy": "^8.1.1",
|
||||
"cross-spawn": "^7.0.3",
|
||||
"execa": "^4.1.0",
|
||||
"ora": "^5.1.0"
|
||||
"ora": "^5.1.0",
|
||||
"prompts": "^2.4.0"
|
||||
},
|
||||
"files": [
|
||||
"bin"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user