UNPKG

@featurevisor/core

Version:

Core package of Featurevisor for Node.js usage

54 lines 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initPlugin = exports.EXAMPLES_TAR_URL = exports.EXAMPLES_BRANCH_NAME = exports.EXAMPLES_REPO_NAME = exports.EXAMPLES_ORG_NAME = exports.DEFAULT_EXAMPLE = void 0; exports.initProject = initProject; const axios_1 = require("axios"); const tar = require("tar"); exports.DEFAULT_EXAMPLE = "yml"; exports.EXAMPLES_ORG_NAME = "fahad19"; exports.EXAMPLES_REPO_NAME = "featurevisor"; exports.EXAMPLES_BRANCH_NAME = "main"; exports.EXAMPLES_TAR_URL = `https://codeload.github.com/${exports.EXAMPLES_ORG_NAME}/${exports.EXAMPLES_REPO_NAME}/tar.gz/${exports.EXAMPLES_BRANCH_NAME}`; function getExamplePath(exampleName) { return `${exports.EXAMPLES_REPO_NAME}-${exports.EXAMPLES_BRANCH_NAME}/examples/example-${exampleName}/`; } function initProject(directoryPath, exampleName = exports.DEFAULT_EXAMPLE) { return new Promise(function (resolve) { axios_1.default.get(exports.EXAMPLES_TAR_URL, { responseType: "stream" }).then((response) => { response.data .pipe(tar.x({ C: directoryPath, filter: (path) => path.indexOf(getExamplePath(exampleName)) === 0, strip: 3, })) .on("error", (e) => { console.error(e); resolve(false); }) .on("finish", () => { console.log(`Project scaffolded in ${directoryPath}`); console.log(``); console.log(`Please run "npm install" in the directory above.`); resolve(true); }); }); }); } exports.initPlugin = { command: "init", handler: async function (options) { const { rootDirectoryPath, parsed } = options; await initProject(rootDirectoryPath, parsed.example); }, examples: [ { command: "init", description: "scaffold a new project in current directory", }, { command: "init --example=exampleName", description: "scaffold a new project in current directory from known example", }, ], }; //# sourceMappingURL=index.js.map