UNPKG

gulp-slm

Version:
1 lines 2.95 kB
{"version":3,"file":"index.mjs","names":[],"sources":["../../../node_modules/.pnpm/replace-ext@2.0.0/node_modules/replace-ext/index.js","../src/index.ts"],"sourcesContent":["'use strict';\n\nvar path = require('path');\n\nfunction replaceExt(npath, ext) {\n if (typeof npath !== 'string') {\n return npath;\n }\n\n if (npath.length === 0) {\n return npath;\n }\n\n var nFileName = path.basename(npath, path.extname(npath)) + ext;\n var nFilepath = path.join(path.dirname(npath), nFileName);\n\n // Because `path.join` removes the head './' from the given path.\n // This removal can cause a problem when passing the result to `require` or\n // `import`.\n if (startsWithSingleDot(npath)) {\n return '.' + path.sep + nFilepath;\n }\n\n return nFilepath;\n}\n\nfunction startsWithSingleDot(fpath) {\n var first2chars = fpath.slice(0, 2);\n return first2chars === '.' + path.sep || first2chars === './';\n}\n\nmodule.exports = replaceExt;\n","import type { Transform } from \"node:stream\";\n\nimport PluginError from \"plugin-error\";\nimport replaceExt from \"replace-ext\";\nimport slm from \"slm\";\nimport through from \"through2\";\n\nexport type Options = {\n filename?: string;\n extension?: string;\n data?: any;\n locals?: any;\n};\n\nconst gulpSlm: (opts?: Options) => Transform = (opts: Options = {}) =>\n through.obj((file, _enc, cb) => {\n opts.filename = file.path;\n\n if (file.data) {\n opts.data = file.data;\n }\n\n file.path = replaceExt(file.path, opts.extension !== undefined ? opts.extension : \".html\");\n\n if (file.isStream()) {\n return cb(new PluginError(\"gulp-slm\", \"Streaming not supported\"));\n }\n\n if (file.isBuffer()) {\n try {\n const contents = String(file.contents);\n const compiled = slm.compile(contents, opts)(opts.locals || opts.data);\n file.contents = Buffer.from(compiled);\n } catch (e) {\n return cb(new PluginError(\"gulp-slm\", e as any));\n }\n }\n\n cb(null, file);\n });\n\nexport default gulpSlm;\n"],"x_google_ignoreList":[0],"mappings":"+qBAEA,IAAI,EAAA,EAAe,OAAO,CAE1B,SAAS,EAAW,EAAO,EAAK,CAK9B,GAJI,OAAO,GAAU,UAIjB,EAAM,SAAW,EACnB,OAAO,EAGT,IAAI,EAAY,EAAK,SAAS,EAAO,EAAK,QAAQ,EAAM,CAAC,CAAG,EACxD,EAAY,EAAK,KAAK,EAAK,QAAQ,EAAM,CAAE,EAAU,CASzD,OAJI,EAAoB,EAAM,CACrB,IAAM,EAAK,IAAM,EAGnB,EAGT,SAAS,EAAoB,EAAO,CAClC,IAAI,EAAc,EAAM,MAAM,EAAG,EAAE,CACnC,OAAO,IAAgB,IAAM,EAAK,KAAO,IAAgB,KAG3D,EAAO,QAAU,UCjBjB,MAAM,GAA0C,EAAgB,EAAE,GAChE,EAAQ,KAAK,EAAM,EAAM,IAAO,CAS9B,GARA,EAAK,SAAW,EAAK,KAEjB,EAAK,OACP,EAAK,KAAO,EAAK,MAGnB,EAAK,MAAA,EAAA,EAAA,SAAkB,EAAK,KAAM,EAAK,YAAc,IAAA,GAA6B,QAAjB,EAAK,UAAoB,CAEtF,EAAK,UAAU,CACjB,OAAO,EAAG,IAAI,EAAY,WAAY,0BAA0B,CAAC,CAGnE,GAAI,EAAK,UAAU,CACjB,GAAI,CACF,IAAM,EAAW,OAAO,EAAK,SAAS,CAChC,EAAW,EAAI,QAAQ,EAAU,EAAK,CAAC,EAAK,QAAU,EAAK,KAAK,CACtE,EAAK,SAAW,OAAO,KAAK,EAAS,OAC9B,EAAG,CACV,OAAO,EAAG,IAAI,EAAY,WAAY,EAAS,CAAC,CAIpD,EAAG,KAAM,EAAK,EACd"}