UNPKG

mili

Version:

Scaffolding with continuous control over the development of the project.

65 lines (64 loc) 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseTemplate = void 0; const isSSH = require("is-ssh"); const fs = require("fs-extra"); const path = require("path"); const isUrl = require("is-url"); const validateNpmPackageName = require("validate-npm-package-name"); const const_1 = require("../const"); function calcStorage(name, version) { return path.join(const_1.TEMPLATE_STORAGE_FILEPATH, encodeURIComponent(name), version || 'noversion'); } function parseTemplate(template, version = 'latest', options) { if (template.startsWith('npm:')) { const name = template.substr('npm:'.length); if (!validateNpmPackageName(name)) throw new Error(`Invalid npm package name ${name}`); const result = { type: 'npm', name, version, storage: calcStorage(template, version), }; if (options.registry) result.registry = options.registry; return result; } else if (isUrl(template)) { return { type: 'git', name: template, version, storage: calcStorage(template, version), }; } else if (template.startsWith('github:')) { const name = `https://github.com/${template.substr('github:'.length)}.git`; return { type: 'git', name, version, storage: calcStorage(name, version), }; } else if (isSSH(template)) { return { type: 'git', name: template, version, storage: calcStorage(template, version), }; } else if (fs.pathExistsSync(template)) { return { type: 'fs', name: template, version: 'latest', cwd: options.cwd || process.cwd(), storage: calcStorage(template, 'latest'), }; } throw new Error(`Invalid template: ${template}`); } exports.parseTemplate = parseTemplate;