UNPKG

novu

Version:

Novu CLI. Run Novu Studio and sync workflows with Novu Cloud

67 lines (66 loc) 2.48 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DownloadError = void 0; exports.createApp = createApp; const picocolors_1 = require("picocolors"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const git_1 = require("./helpers/git"); const is_folder_empty_1 = require("./helpers/is-folder-empty"); const is_online_1 = require("./helpers/is-online"); const is_writeable_1 = require("./helpers/is-writeable"); const templates_1 = require("./templates"); class DownloadError extends Error { } exports.DownloadError = DownloadError; async function createApp({ appPath, packageManager, typescript, eslint, srcDir, importAlias, secretKey, applicationId, userId, }) { let repoInfo; const mode = typescript ? 'ts' : 'js'; const template = 'app-react-email'; const root = path_1.default.resolve(appPath); if (!(await (0, is_writeable_1.isWriteable)(path_1.default.dirname(root)))) { console.error('The application path is not writable, please check folder permissions and try again.'); console.error('It is likely you do not have write permissions for this folder.'); process.exit(1); } const appName = path_1.default.basename(root); fs_1.default.mkdirSync(root, { recursive: true }); if (!(0, is_folder_empty_1.isFolderEmpty)(root, appName)) { process.exit(1); } const useYarn = packageManager === 'yarn'; const isOnline = !useYarn || (await (0, is_online_1.getOnline)()); const originalDirectory = process.cwd(); console.log(`Creating a new Novu app in ${(0, picocolors_1.green)(root)}.`); console.log(); process.chdir(root); await (0, templates_1.installTemplate)({ appName, root, template, mode, packageManager, isOnline, eslint, srcDir, importAlias, secretKey, applicationId, userId, }); if ((0, git_1.tryGitInit)(root)) { console.log('Initialized a git repository.'); console.log(); } let cdPath; if (path_1.default.join(originalDirectory, appName) === appPath) { cdPath = appName; } else { cdPath = appPath; } console.log(`${(0, picocolors_1.green)('Success!')} Created ${appName} at ${appPath}`); }