UNPKG

draaft

Version:

A CLI to pull content from https://pilot.pm content collaboration platform and feed your static site generator with markdown files

66 lines (65 loc) 2.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const errors_1 = require("@oclif/errors"); const fs = require("fs"); const fs_extra_1 = require("fs-extra"); const path = require("path"); const signal_1 = require("../signal"); class Layout extends command_1.Command { async run() { //const {args, flags} = this.parse(Layout) const CURR_DIR = process.cwd(); const templatePath = path.join(__dirname, "../", "templates", "hugo"); function createDirectoryContents(templatePath, CURR_DIR) { const filesToCreate = fs.readdirSync(templatePath); filesToCreate.forEach((file) => { const origFilePath = `${templatePath}/${file}`; // get stats about the current file const stats = fs.statSync(origFilePath); if (stats.isFile()) { const contents = fs.readFileSync(origFilePath, "utf8"); //console.log('reader', contents) const writePath = `${CURR_DIR}/${file}`; try { fs.writeFileSync(writePath, contents, "utf8"); signal_1.signal.created(`📄 ${writePath}`); } catch (error) { signal_1.signal.fatal(error); throw new errors_1.CLIError(error); } } else if (stats.isDirectory()) { try { fs_extra_1.ensureDirSync(`${CURR_DIR}/${file}`); signal_1.signal.created(`📁 ${CURR_DIR}/${file}`); } catch (error) { signal_1.signal.fatal(error); throw new errors_1.CLIError(error); } // recursive call createDirectoryContents(`${templatePath}/${file}`, `${CURR_DIR}/${file}`); } }); } createDirectoryContents(templatePath, CURR_DIR); // function createProject(projectPath: string) { // if (fs.existsSync(projectPath)) { // console.log(chalk.red(`Folder ${projectPath} exists. Delete or use another name.`)); // return false; // } fs.mkdirSync(projectPath); // return true; // } } } Layout.description = "Create basic layout to display content"; Layout.flags = { help: command_1.flags.help({ char: "h" }), // flag with a value (-n, --name=VALUE) ssg: command_1.flags.string({ char: "s", description: "Static site generator" }), // flag with no value (-f, --force) overwrite: command_1.flags.boolean({ char: "f", default: false }), }; exports.default = Layout;