#!/usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const commander_1 = require("commander");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const package_tpl_json_1 = __importDefault(require("./package.tpl.json"));
const package_managebase_tpl_json_1 = __importDefault(require("./package-managebase.tpl.json"));
const package_weapp_tpl_json_1 = __importDefault(require("./package-weapp.tpl.json"));
const package_managebase_ui_tpl_json_1 = __importDefault(require("./package-managebase-ui.tpl.json"));
const packageJson = require(path_1.default.join(__dirname, '../package.json'));
commander_1.program.name('hpsfir').description('hpsfir系列脚手架')
    .version(packageJson.version, '-v, --vers');
commander_1.program.command('create')
    .argument('<projectName>', 'project name')
    .action((projectName) => {
    const dir = process.cwd();
    const projectDir = path_1.default.join(dir, projectName);
    fs_1.default.mkdirSync(projectDir);
    fs_1.default.writeFileSync(path_1.default.join(projectDir, 'package.json'), JSON.stringify({
        ...package_tpl_json_1.default,
        name: projectName,
    }, undefined, 2));
    fs_1.default.cpSync(path_1.default.join(__dirname, '../template'), projectDir, { recursive: true });
    fs_1.default.renameSync(path_1.default.join(projectDir, 'gitignore.tpl'), path_1.default.join(projectDir, '.gitignore'));
    (0, child_process_1.execSync)('git init', { cwd: projectDir, stdio: 'inherit' });
    (0, child_process_1.execSync)('npm i', { cwd: projectDir, stdio: 'inherit' });
    console.log('\n\n\n');
    console.log(`create ${projectName} success!\n`);
    console.log(`1. please cd into '${projectDir}'.`);
    console.log('2. edit the \'src/resource/db.json\' with your mysql info.');
    console.log('3. use cmd: \'npm run start\' start project.');
});
commander_1.program.command('create-managebase')
    .argument('<projectName>', 'project name')
    .action((projectName) => {
    const dir = process.cwd();
    const projectDir = path_1.default.join(dir, projectName);
    fs_1.default.mkdirSync(projectDir);
    fs_1.default.writeFileSync(path_1.default.join(projectDir, 'package.json'), JSON.stringify({
        ...package_managebase_tpl_json_1.default,
        name: projectName,
    }, undefined, 2));
    fs_1.default.cpSync(path_1.default.join(__dirname, '../template-managebase'), projectDir, { recursive: true });
    fs_1.default.renameSync(path_1.default.join(projectDir, 'gitignore.tpl'), path_1.default.join(projectDir, '.gitignore'));
    (0, child_process_1.execSync)('git init', { cwd: projectDir, stdio: 'inherit' });
    (0, child_process_1.execSync)('npm i', { cwd: projectDir, stdio: 'inherit' });
    console.log('\n\n\n');
    console.log(`create ${projectName} success!\n`);
    console.log(`1. please cd into '${projectDir}'.`);
    console.log('2. edit the \'src/resource/db.json\' with your mysql info.');
    console.log('3. use cmd: \'npm run start\' start project.');
});
commander_1.program.command('create-managebase-ui')
    .argument('<projectName>', 'project name')
    .action((projectName) => {
    const dir = process.cwd();
    const projectDir = path_1.default.join(dir, projectName);
    fs_1.default.mkdirSync(projectDir);
    fs_1.default.writeFileSync(path_1.default.join(projectDir, 'package.json'), JSON.stringify({
        ...package_managebase_ui_tpl_json_1.default,
        name: projectName,
    }, undefined, 2));
    fs_1.default.cpSync(path_1.default.join(__dirname, '../template-managebase-ui'), projectDir, { recursive: true });
    fs_1.default.renameSync(path_1.default.join(projectDir, 'gitignore.tpl'), path_1.default.join(projectDir, '.gitignore'));
    (0, child_process_1.execSync)('git init', { cwd: projectDir, stdio: 'inherit' });
    (0, child_process_1.execSync)('npm i', { cwd: projectDir, stdio: 'inherit' });
    console.log('\n\n\n');
    console.log(`create ${projectName} success!\n`);
    console.log(`1. please cd into '${projectDir}'.`);
    console.log('2. use cmd: \'npm run server\' start project.');
});
commander_1.program.command('create-weapp')
    .argument('<projectName>', 'project name')
    .action((projectName) => {
    const dir = process.cwd();
    const projectDir = path_1.default.join(dir, projectName);
    fs_1.default.mkdirSync(projectDir);
    fs_1.default.writeFileSync(path_1.default.join(projectDir, 'package.json'), JSON.stringify({
        ...package_weapp_tpl_json_1.default,
        name: projectName,
    }, undefined, 2));
    fs_1.default.cpSync(path_1.default.join(__dirname, '../template-weapp'), projectDir, { recursive: true });
    fs_1.default.renameSync(path_1.default.join(projectDir, 'gitignore.tpl'), path_1.default.join(projectDir, '.gitignore'));
    (0, child_process_1.execSync)('git init', { cwd: projectDir, stdio: 'inherit' });
    (0, child_process_1.execSync)('npm i', { cwd: projectDir, stdio: 'inherit' });
    console.log('\n\n\n');
    console.log(`create ${projectName} success!\n`);
    console.log(`1. please cd into '${projectDir}'.`);
    console.log('3. use cmd: \'npm run dev:mp-weixin\' start project.');
});
commander_1.program.parse();
