UNPKG

zents-cli

Version:

ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.

57 lines (56 loc) 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const log_1 = require("../helper/log"); const AbstractCommand_1 = require("../classes/AbstractCommand"); const cli_ux_1 = tslib_1.__importDefault(require("cli-ux")); const copyDir_1 = require("../helper/copyDir"); const doesDirOrFileExists_1 = require("../helper/doesDirOrFileExists"); const execa_1 = tslib_1.__importDefault(require("execa")); const path_1 = require("path"); const fs_1 = require("fs"); const removeDirOrFile_1 = require("../helper/removeDirOrFile"); class Build extends AbstractCommand_1.AbstractCommand { async run() { this.parse(Build); this.welcome('Building ZenTS project!'); const { dist } = await this.getCompilerDirectories(); await this.prepareDistDirectory(dist); await this.compileTypeScript(); await this.copyTemplates(); this.log(log_1.success('Project build successfully!')); } async prepareDistDirectory(outDir) { const distDirectory = path_1.join(process.cwd(), outDir); await removeDirOrFile_1.removeDirOrFile(distDirectory); return distDirectory; } async compileTypeScript() { try { cli_ux_1.default.action.start(log_1.info('Compiling TypeScript files...')); await execa_1.default('tsc', { preferLocal: true, localDir: process.cwd(), }); } catch (err) { cli_ux_1.default.action.stop(log_1.error()); this.log(log_1.error(err)); process.exit(9); } cli_ux_1.default.action.stop(log_1.success()); } async copyTemplates() { cli_ux_1.default.action.start(log_1.info('Copying template files...')); const { src, dist } = await this.getViewDirectories(); if (!(await doesDirOrFileExists_1.doesDirOrFileExists(src))) { cli_ux_1.default.action.stop("source directory doesn't exist"); return; } await fs_1.promises.mkdir(dist); await copyDir_1.copyDir(src, dist); cli_ux_1.default.action.stop(log_1.success()); } } exports.default = Build; Build.description = 'build a ZenTS application. This command will compile the TypeScript files and copy the projects templates to the dist folder.';