UNPKG

1.99 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const index_1 = require("./utils/index");
4const path = require("path");
5const fs = require("fs");
6const render_1 = require("./render");
7const rimraf = require("rimraf");
8const download = require("download-git-repo");
9const options_1 = require("./options");
10const defautlTarget = path.join(path.dirname(__dirname), index_1.TEMPLATE_NAME);
11/**
12 * Generate source with meatdata
13 *
14 * @export
15 * @param {string} source
16 * @param {string} dest
17 * @param {Metadate} metadata
18 * @returns {Promise<boolean>}
19 */
20function generator(source, dest, metadata) {
21 return render_1.default(source, dest, metadata);
22}
23exports.generator = generator;
24/**
25 * Download template from a specify url
26 *
27 * @export
28 * @param {string} templateUrl
29 * @param {*} [target=defautlTarget]
30 * @param {CloneOption} [option]
31 * @returns
32 */
33function clone(templateUrl, target = defautlTarget, option) {
34 return new Promise((resolve, reject) => {
35 if (option && option.cache) {
36 resolve(target);
37 }
38 else if (fs.existsSync(target)) {
39 rimraf(target, () => {
40 done();
41 });
42 }
43 else {
44 done();
45 }
46 function done() {
47 download(templateUrl, target, { clone: option.clone }, err => {
48 // download('direct:https://github.com/balloonzzq/webpack.git#temp', target, { clone: true }, (err) => {
49 if (err) {
50 reject(err);
51 }
52 else {
53 resolve(target);
54 }
55 });
56 }
57 });
58}
59exports.clone = clone;
60/**
61 * Get options from template's meta.json or meta.js
62 *
63 * @export
64 * @param {string} name
65 * @param {string} dir
66 * @param {*} opt
67 * @returns
68 */
69function getOptions(name, dir, opt) {
70 return options_1.default(name, dir, opt);
71}
72exports.getOptions = getOptions;
73//# sourceMappingURL=index.js.map
\No newline at end of file