emerald-templates
Version:
Intelligent Template Generation & Project Management
34 lines (31 loc) • 1.13 kB
JavaScript
const getConfiguration = require('../functions/getConfiguration')
const saveGlobalConfig = require('../functions/saveGlobalConfig')
const resolvePath = require('../functions/resolvePath')
const directoryExists = require('directory-exists')
const chalk = require('chalk')
async function addRoot(root) {
// if (!root)
// root = (
// await askQuestion('Please enter the path to your root templates storage folder\n> ')
// ).trim()
const rootFolder = resolvePath(root, process.cwd())
if (!(await directoryExists(rootFolder)))
throw new Error(`The folder "${rootFolder}" does not exist`)
let config = getConfiguration()
//config.rootFolders = config.rootFolders
if (config.rootFolders.includes(rootFolder)) throw new Error('That folder has already been added')
config.rootFolders = config.rootFolders.concat([rootFolder])
saveGlobalConfig(config)
console.log(chalk.green('Done!'))
}
module.exports = {
handler: addRoot,
args: {
root: {
argsPosition: 0,
format: String,
prompt: 'Please enter the path to the root you would like to add',
required: true
}
}
}