template-file
Advanced tools
Comparing version 4.0.2 to 4.1.0
@@ -35,13 +35,7 @@ #!/usr/bin/env node | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs_1 = require("fs"); | ||
const glob_1 = __importDefault(require("glob")); | ||
const meow_1 = __importDefault(require("meow")); | ||
const p_limit_1 = __importDefault(require("p-limit")); | ||
const path_1 = __importDefault(require("path")); | ||
const util_1 = require("util"); | ||
const _1 = require("."); | ||
function main() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const glob = util_1.promisify(glob_1.default); | ||
const limitOpenFiles = p_limit_1.default(64); | ||
const cli = meow_1.default(` | ||
@@ -68,8 +62,3 @@ Usage | ||
const data = yield Promise.resolve().then(() => __importStar(require(path_1.default.resolve(dataFile)))); | ||
function renderToFile(file, destination) { | ||
return limitOpenFiles(() => _1.renderTemplateFile(file, data).then(renderedString => fs_1.promises.writeFile(destination, renderedString))); | ||
} | ||
glob(sourceGlob) | ||
.then(files => files.map(file => renderToFile(file, path_1.default.join(destination, path_1.default.basename(file))))) | ||
.then(fileWriteOperations => Promise.all(fileWriteOperations)); | ||
_1.renderToFolder(sourceGlob, destination, data); | ||
}); | ||
@@ -76,0 +65,0 @@ } |
interface Data extends Record<string | number | symbol, string | number | Data | (() => string | number | Data)> { | ||
} | ||
export declare function renderGlob(sourceGlob: string, data: Data, onFileCallback: (filename: string, contents: string) => void): Promise<void>; | ||
export declare function renderString(template: string, data: Data): string | Promise<string>; | ||
export declare function renderTemplateFile(filepath: string, data: Data): Promise<string>; | ||
export declare function renderToFolder(sourceGlob: string, destination: string, data: Data): Promise<void>; | ||
export {}; |
@@ -11,6 +11,25 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renderTemplateFile = exports.renderString = void 0; | ||
exports.renderToFolder = exports.renderTemplateFile = exports.renderString = exports.renderGlob = void 0; | ||
const deep_1 = require("@blakek/deep"); | ||
const fs_1 = require("fs"); | ||
const glob_1 = __importDefault(require("glob")); | ||
const mkdirp_1 = __importDefault(require("mkdirp")); | ||
const path_1 = __importDefault(require("path")); | ||
const util_1 = require("util"); | ||
const utils_1 = require("./utils"); | ||
function renderGlob(sourceGlob, data, onFileCallback) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const glob = util_1.promisify(glob_1.default); | ||
const files = yield glob(sourceGlob); | ||
for (const file of files) { | ||
const contents = yield utils_1.limitOpenFiles(() => renderTemplateFile(file, data)); | ||
onFileCallback(file, contents); | ||
} | ||
}); | ||
} | ||
exports.renderGlob = renderGlob; | ||
function renderString(template, data) { | ||
@@ -38,2 +57,13 @@ return template.replace(/\{\{\s*(.*?)\s*\}\}/g, (_match, captured) => { | ||
exports.renderTemplateFile = renderTemplateFile; | ||
function renderToFolder(sourceGlob, destination, data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield mkdirp_1.default(destination); | ||
function writeFile(filename, contents) { | ||
const fullPath = path_1.default.join(destination, path_1.default.basename(filename)); | ||
fs_1.promises.writeFile(fullPath, contents); | ||
} | ||
return renderGlob(sourceGlob, data, writeFile); | ||
}); | ||
} | ||
exports.renderToFolder = renderToFolder; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "template-file", | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"main": "dist/index.js", | ||
@@ -42,3 +42,4 @@ "description": "🔀 Replace {{ variables }} in all your files", | ||
"ts-node/register" | ||
] | ||
], | ||
"timeout": "30s" | ||
}, | ||
@@ -54,2 +55,3 @@ "browserslist": [ | ||
"meow": "^8.0.0", | ||
"mkdirp": "^1.0.4", | ||
"p-limit": "^3.1.0" | ||
@@ -68,2 +70,3 @@ }, | ||
"@types/glob": "^7.1.3", | ||
"@types/mkdirp": "^1.0.1", | ||
"@typescript-eslint/eslint-plugin": "^4.9.0", | ||
@@ -70,0 +73,0 @@ "@typescript-eslint/parser": "^4.9.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78323
12
147
5
23
+ Addedmkdirp@^1.0.4
+ Addedmkdirp@1.0.4(transitive)