UNPKG

mili

Version:

Scaffolding with continuous control over the development of the project.

47 lines (46 loc) 2.28 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.compile = void 0; const R = require("ramda"); const micromatch = require("micromatch"); const exec_handler_1 = require("./exec-handler"); const readdeepdir_1 = require("../util/readdeepdir"); const const_1 = require("../const"); const nanoid_1 = require("nanoid"); const fs = require("fs-extra"); const path = require("path"); function compile(cwd, templatePath, templates, base) { return __awaiter(this, void 0, void 0, function* () { const resource = new Map(base); const cacheDir = path.join(const_1.TEMPLATE_CACHE_FILEPATH, (0, nanoid_1.nanoid)()); yield fs.ensureDir(cacheDir); yield fs.emptyDir(cacheDir); yield fs.copy(templatePath, cacheDir); for (const filename of yield (0, readdeepdir_1.readdeepdir)(cacheDir)) { for (const template of templates) { if (!micromatch.isMatch(filename, template.path, { dot: true })) continue; let filepath = filename; const encoding = template.encoding; for (const handler of template.handlers) { const subpath = yield (0, exec_handler_1.execHandler)(cwd, cacheDir, filepath, resource, R.mergeDeepLeft(handler, { options: { encoding } })); if (subpath) filepath = subpath; if (filepath === '/dev/null') break; } break; } } }); } exports.compile = compile;