function readUploadFiles(dir) { const rootPath = path.join(__dirname, dir); const dirs = fs.readdirSync(rootPath); return dirs.reduce((all, file) => { const curPath = path.join(rootPath, file); const isDir = fs.statSync(curPath).isDirectory(); const extname = path.extname(curPath); if(!isDir && extname !== '.map') { all.push(curPath); } return all; }, []); }
stripExt(url: string) { return path.basename(url, path.extname(url)); }
/** * Read all files within a `dir` & Update to latest filenames */ task.plugin('revReplace', { every:false }, function * (files, opts) { opts = Object.assign({ ignores:IGNORE }, opts); // get original manifest paths; escape safe characters const keys = Object.keys(MANIFEST).map(k => k.replace(/([[^$.|?*+(){}\\])/g, '\\$1')).join('|'); const rgx = new RegExp(keys, 'gi'); for (const f of files) { const ext = p.extname(f.base); // only if not in `ignores` if (!ext || opts.ignores.indexOf(ext) !== -1) continue; // replace orig with rev'd && write it const d = f.data.toString().replace(rgx, k => MANIFEST[k]); f.data = Buffer.from(d); } });
through.obj(function(file, enc, next) { if (file.isNull() || file.isDirectory()) { next(null, file); return; } if (file.extname !== '.md' && path.extname(file.history[0]) !== '.md') { next(null, file); return; } try { let md = new Remarkable(opts); file.contents = Buffer.from(md.render(file.contents.toString())); file.extname = '.html'; } catch (err) { this.emit('error', new PluginError('remarkable', err, { fileName: file.path })); return; } next(null, file); })
function getPackages(file) { var deps = []; const extension = path.extname(file); if (availableExtensions.includes(extension)) { var imports; try { // will throw if compiler deps (typescript, mdx, vue) are not installed yet imports = konan(file, fs.readFileSync(file, "utf8")); } catch (e) { return []; } // only strings for now. imports.strings.forEach(imp => { imp = trimPackageName(imp); // skip relative imports and built-in imports (on newer node versions only) if ( !imp.startsWith("~") && !imp.startsWith(".") && !builtInPackages.includes(imp) ) { deps.push(imp); } }); } return deps; }
function extract(data) { data.forEach(function (item) { let extension = path.extname(item); if (extension === ".svg") { let fileName = item.replace(/-([a-z])/g, function (i) { return i[1].toUpperCase(); }); let fileData = fs.readFileSync("./icons/" + item).toString(); let dom = new JSDOM(fileData); let svgDefs = dom.window.document.querySelector("defs"); if(svgDefs != undefined){ dom.window.document.querySelector("svg").removeChild(svgDefs); } let svgStyle= dom.window.document.querySelector("style"); if(svgStyle != undefined){ dom.window.document.querySelector("svg").removeChild(svgStyle); } let svgTitle = dom.window.document.querySelector("title"); if(svgTitle != undefined){ dom.window.document.querySelector("svg").removeChild(svgTitle); } let fileDataCore = dom.window.document.querySelector("svg").innerHTML.replace(/\n/g, ""); svgObject[fileName.slice(0, -4)] = fileDataCore; } }); }
/** * Create new hashed file names based on contents */ task.plugin('rev', {}, function * (file, opts) { // overwrite default opt values opts = Object.assign({ ignores:IGNORE.concat('.html', '.json') }, opts); // bypass dirs or empty files if (!file.data) { return; } const ext = p.extname(file.base); // if this file's extension matches `ignores`, exit early if (!ext || opts.ignores.indexOf(ext) !== -1) { return; } file.orig = file.base; file.hash = revHash(file.data); // find first occurence of '.', NOT including first char const idx = file.base.indexOf('.', 1); // change filename; append hash to base name file.base = file.base.substr(0, idx).concat('-', file.hash, file.base.substr(idx)); });
const parentExt = path.extname(parent); extensions = [parentExt, ...extensions.filter(ext => ext !== parentExt)];
source[2].sourceMarkdownName = path.basename(source[0], path.extname(source[0])); renderFileToHtml(`${rootDir}/${source[0]}`, `${rootDir}/${source[1]}`, source[2]);
return Promise.reject(new Error(`Config file not found: ${filePath}`)); const ext = path.extname(filePath); switch (ext) { case ".json":
through.obj(function(file, enc, next) { if (file.isNull() || file.isDirectory()) { next(null, file); return; } if (file.extname !== '.md' && path.extname(file.history[0]) !== '.md') { next(null, file); return; } try { let str = file.contents.toString(); str = str.replace(/(\{{2,4})([^}]+)(\}{2,4})/g, (m, open, inner, close) => { return open + unescape(inner) + close; }); file.contents = Buffer.from(str); } catch (err) { this.emit('error', new PluginError('unescape', err, { fileName: file.path })); return; } next(null, file); })
/** * Read all files within a `dir` & Update to latest filenames */ task.plugin('revReplace', { every:false }, function * (files, opts) { opts = Object.assign({ ignores:IGNORE }, opts); // get original manifest paths; escape safe characters const keys = Object.keys(MANIFEST).map(k => k.replace(/([[^$.|?*+(){}\\])/g, '\\$1')).join('|'); const rgx = new RegExp(keys, 'gi'); for (const f of files) { const ext = p.extname(f.base); // only if not in `ignores` if (!ext || opts.ignores.indexOf(ext) !== -1) continue; // replace orig with rev'd && write it const d = f.data.toString().replace(rgx, k => MANIFEST[k]); f.data = Buffer.from(d); } });
/** * Create new hashed file names based on contents */ task.plugin('rev', {}, function * (file, opts) { // overwrite default opt values opts = Object.assign({ ignores:IGNORE.concat('.html', '.json') }, opts); // bypass dirs or empty files if (!file.data) { return; } const ext = p.extname(file.base); // if this file's extension matches `ignores`, exit early if (!ext || opts.ignores.indexOf(ext) !== -1) { return; } file.orig = file.base; file.hash = revHash(file.data); // find first occurence of '.', NOT including first char const idx = file.base.indexOf('.', 1); // change filename; append hash to base name file.base = file.base.substr(0, idx).concat('-', file.hash, file.base.substr(idx)); });
const parentExt = path.extname(parent); extensions = [parentExt, ...extensions.filter(ext => ext !== parentExt)];