-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9cee07
commit dc2aa7b
Showing
4 changed files
with
376 additions
and
367 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 |
---|---|---|
@@ -1,103 +1,103 @@ | ||
const templates = require(`../../../templates`); | ||
const path = require(`path`); | ||
const fs = require(`fs`); | ||
const chalk = require(`chalk`); | ||
const commandLineArgs = require('command-line-args'); | ||
const config = require(`../../../config`); | ||
|
||
const options = [ | ||
{ | ||
name: 'help', | ||
alias: 'h', | ||
description: 'Shows this help message.', | ||
type: Boolean | ||
}, | ||
{ | ||
name: 'name', | ||
alias: 'n', | ||
description: 'The name for the action.', | ||
defaultOption: true | ||
}, | ||
{ | ||
name: 'receiver', | ||
alias: 'r', | ||
description: 'Create a receiver instead of an action.', | ||
type: Boolean | ||
}, | ||
{ | ||
name: 'instance', | ||
alias: 'i', | ||
description: 'The path to the local Coattail Instance.', | ||
typeLabel: '{underline path}' | ||
} | ||
]; | ||
|
||
const printHelp = cli => cli.printHelp([ | ||
{ | ||
header: 'Coattail -- Create Action', | ||
content: 'Creates a new action on this Coattail instance.' | ||
}, | ||
{ | ||
header: 'Usage', | ||
content: [ | ||
`$ coattail action create [options]` | ||
] | ||
}, | ||
{ | ||
header: 'Options', | ||
optionList: options | ||
} | ||
]); | ||
|
||
module.exports = async cli => { | ||
const parameters = commandLineArgs(options, { | ||
argv: cli.argv, | ||
stopAtFirstUnknown: true | ||
}); | ||
|
||
if (parameters.help) { | ||
printHelp(cli); | ||
return; | ||
} | ||
|
||
if(!cli.validateRequired(parameters, ['name'])) { | ||
return; | ||
} | ||
|
||
try { | ||
config.load(parameters.instance); | ||
} catch (_) { | ||
cli.error(`Unable to locate 'config.yml' in '${parameters.instance || './'}'`); | ||
return; | ||
} | ||
|
||
if (!parameters.receiver) { | ||
const destination = path.join(config.get().paths.actions, `${parameters.name}.js`); | ||
|
||
if (fs.existsSync(destination)) { | ||
cli.error(`An action with that name already exists.`, `Found in ${chalk.hex('#4e88e6')(destination)}`); | ||
return; | ||
} | ||
|
||
try { | ||
templates.create('action', destination, 'js'); | ||
cli.success(`Action ${parameters.name}.js created! (${chalk.hex('#4e88e6')(destination)})`); | ||
} catch (err) { | ||
cli.error(`Failed to create action ${destination}.`, err.stack) | ||
} | ||
} else { | ||
const destination = path.join(config.get().paths.receivers, `${parameters.name}.js`); | ||
|
||
if (fs.existsSync(destination)) { | ||
cli.error(`A receiver with that name already exists.`, `Found in ${chalk.hex('#4e88e6')(destination)}`); | ||
return; | ||
} | ||
|
||
try { | ||
templates.create('receiver', destination, 'js'); | ||
cli.success(`Receiver ${parameters.name}.js created! (${chalk.hex('#4e88e6')(destination)})`); | ||
} catch (err) { | ||
cli.error(`Failed to create receiver ${destination}.`, err.stack) | ||
} | ||
} | ||
const templates = require(`../../../templates`); | ||
const path = require(`path`); | ||
const fs = require(`fs`); | ||
const chalk = require(`chalk`); | ||
const commandLineArgs = require('command-line-args'); | ||
const config = require(`../../../config`); | ||
|
||
const options = [ | ||
{ | ||
name: 'help', | ||
alias: 'h', | ||
description: 'Shows this help message.', | ||
type: Boolean | ||
}, | ||
{ | ||
name: 'name', | ||
alias: 'n', | ||
description: 'The name for the action.', | ||
defaultOption: true | ||
}, | ||
{ | ||
name: 'receiver', | ||
alias: 'r', | ||
description: 'Create a receiver instead of an action.', | ||
type: Boolean | ||
}, | ||
{ | ||
name: 'instance', | ||
alias: 'i', | ||
description: 'The path to the local Coattail Instance.', | ||
typeLabel: '{underline path}' | ||
} | ||
]; | ||
|
||
const printHelp = cli => cli.printHelp([ | ||
{ | ||
header: 'Coattail -- Create Action', | ||
content: 'Creates a new action on this Coattail instance.' | ||
}, | ||
{ | ||
header: 'Usage', | ||
content: [ | ||
`$ coattail action create [options]` | ||
] | ||
}, | ||
{ | ||
header: 'Options', | ||
optionList: options | ||
} | ||
]); | ||
|
||
module.exports = async cli => { | ||
const parameters = commandLineArgs(options, { | ||
argv: cli.argv, | ||
stopAtFirstUnknown: true | ||
}); | ||
|
||
if (parameters.help) { | ||
printHelp(cli); | ||
return; | ||
} | ||
|
||
if(!cli.validateRequired(parameters, ['name'])) { | ||
return; | ||
} | ||
|
||
try { | ||
config.load(parameters.instance); | ||
} catch (_) { | ||
cli.error(`Unable to locate 'config.yml' in '${parameters.instance || process.cwd()}'`); | ||
return; | ||
} | ||
|
||
if (!parameters.receiver) { | ||
const destination = path.join(config.get().paths.actions, `${parameters.name}.js`); | ||
|
||
if (fs.existsSync(destination)) { | ||
cli.error(`An action with that name already exists.`, `Found in ${chalk.hex('#4e88e6')(destination)}`); | ||
return; | ||
} | ||
|
||
try { | ||
templates.create('action', destination, 'js'); | ||
cli.success(`Action ${parameters.name}.js created! (${chalk.hex('#4e88e6')(destination)})`); | ||
} catch (err) { | ||
cli.error(`Failed to create action ${destination}.`, err.stack) | ||
} | ||
} else { | ||
const destination = path.join(config.get().paths.receivers, `${parameters.name}.js`); | ||
|
||
if (fs.existsSync(destination)) { | ||
cli.error(`A receiver with that name already exists.`, `Found in ${chalk.hex('#4e88e6')(destination)}`); | ||
return; | ||
} | ||
|
||
try { | ||
templates.create('receiver', destination, 'js'); | ||
cli.success(`Receiver ${parameters.name}.js created! (${chalk.hex('#4e88e6')(destination)})`); | ||
} catch (err) { | ||
cli.error(`Failed to create receiver ${destination}.`, err.stack) | ||
} | ||
} | ||
}; |
Oops, something went wrong.