"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var libs_1 = require("./libs");
exports.npm = libs_1.template.npm;
function create(source) {
    return libs_1.template.create(source);
}
exports.create = create;
function copyFile(args) {
    var _this = this;
    if (args === void 0) { args = {}; }
    var _a = args.force, force = _a === void 0 ? false : _a;
    return function (req, res) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
        var path, dir, _a;
        return tslib_1.__generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    path = libs_1.fsPath.resolve("." + req.path.target);
                    dir = libs_1.fsPath.dirname(path);
                    _a = force;
                    if (_a) return [3, 2];
                    return [4, libs_1.fs.pathExists(path)];
                case 1:
                    _a = !(_b.sent());
                    _b.label = 2;
                case 2:
                    if (!_a) return [3, 5];
                    return [4, libs_1.fs.ensureDir(dir)];
                case 3:
                    _b.sent();
                    return [4, libs_1.fs.writeFile(path, req.buffer)];
                case 4:
                    _b.sent();
                    _b.label = 5;
                case 5:
                    res.complete();
                    return [2];
            }
        });
    }); };
}
exports.copyFile = copyFile;
function deleteFile(args) {
    var _this = this;
    if (args === void 0) { args = {}; }
    return function (req, res) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
        var path;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    path = libs_1.fsPath.resolve("." + req.path.target);
                    return [4, libs_1.fs.remove(path)];
                case 1:
                    _a.sent();
                    res.complete();
                    return [2];
            }
        });
    }); };
}
exports.deleteFile = deleteFile;
//# sourceMappingURL=tmpl.js.map