/**
 * Failed to minify the file using Terser v5.39.0. Serving the original version.
 * Original file: /npm/project-node@0.1.5/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
#!/usr/bin/env node
'use strict'

require('shelljs/global')
const path = require('path')
const project = require('./lib/projects')

const argv = require('yargs')
    .option('s', {
        alias: 'singleWebApp',
        default: '',
        describe: project.list[0].description,
        type: 'string'
    })
    .option('m', {
        alias: 'mvc',
        default: '',
        describe: project.list[1].description,
        type: 'string'
    })
    .option('r', {
        alias: 'react',
        default: '',
        describe: project.list[2].description,
        type: 'string'
    })
    .option('v', {
        alias: 'vuejs',
        default: '',
        describe: project.list[3].description,
        type: 'string'
    })
    .usage('用法: project [options]')
    .example('project -s webshop', 'Creating project webshop')
    .help('h')
    .alias('h', 'help')
    .epilog('made by mada.')
    .argv

let currentPath = pwd()

let renameProject = function (dir, name) {
    return path.join(dir, name)
}

let copyProject = function (p, distFile) {
    cp('-Rf', path.join(__dirname, p.path), distFile);
}

let p, name
console.log(argv.s)
console.log(argv.m)
if (argv.s) {
    p = project.get(0)
    name = argv.s
} else if (argv.m) {
    p = project.get(1)
    name = argv.m
} else if (argv.r) {
    p = project.get(2)
    name = argv.r
} else if (argv.v) {
    p = project.get(3)
    name = argv.v
}
if (!name) {
    console.log('输入格式错误,请查看帮助信息')
    echo('project -h')
    return
}

let distFile = renameProject(currentPath.toString(), name)
console.log('Creating project + ' + name + ' to path: ' + distFile)
copyProject(p, distFile)
