@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
1 lines • 3.35 kB
Source Map (JSON)
{"version":3,"sources":["../../../packages/tools/gulp-svg-code/index.ts"],"names":[],"mappings":"","file":"index.d.ts","sourcesContent":["'use strict';\r\n\r\nimport { Buffer } from 'buffer';\r\nimport Path from 'path';\r\nimport pluginError from 'plugin-error';\r\nimport through2 from 'through2';\r\nimport Vinyl from 'vinyl';\r\nimport * as util from '../utilities';\r\nimport * as SvgCode from './svg-code-convert';\r\n\r\nconst PLUGIN_NAME = 'gulp-svg-code';\r\n\r\n/**\r\n * Plugin level function\r\n */\r\nfunction gulpSvgCode() {\r\n // eslint-disable-next-line unused-imports/no-unused-vars\r\n function extendError(pError, error) {\r\n if (error && (typeof error === 'object')) {\r\n ['name', 'errno'].forEach(\r\n function (property) {\r\n if (property in error) {\r\n this[property] = error[property];\r\n }\r\n },\r\n pError);\r\n }\r\n\r\n return pError;\r\n }\r\n\r\n let pathPrefix = null;\r\n const collection = {};\r\n return through2.obj(\r\n function (file, enc, cb) {\r\n let error = null;\r\n try {\r\n const path = Path.parse(file.path);\r\n if (path.ext === '.svg') {\r\n if (pathPrefix === null) {\r\n pathPrefix = path.dir;\r\n } else {\r\n const segments = path.dir.split('\\\\');\r\n const segPrefix = pathPrefix.split('\\\\');\r\n const newPrefix = [];\r\n for (let i = 0; i < segPrefix.length; i++) {\r\n if (segments[i].toLocaleUpperCase() !== segPrefix[i].toLocaleUpperCase()) {\r\n pathPrefix = newPrefix.join('\\\\');\r\n break;\r\n }\r\n\r\n newPrefix.push(segments[i]);\r\n }\r\n }\r\n\r\n const data = file.contents.toString('utf8');\r\n collection[file.path] = data;\r\n }\r\n } catch (e) {\r\n error = (!e.plugin || (e.plugin !== PLUGIN_NAME)) ?\r\n util.extendError(new pluginError({ plugin: PLUGIN_NAME, message: e.message }), e) : e;\r\n }\r\n\r\n return cb(error);\r\n },\r\n function (cb) {\r\n const converter = new SvgCode.SvgCodeConverter();\r\n converter.contentReset();\r\n converter.generate(collection, pathPrefix);\r\n const cssFile = new Vinyl({\r\n cwd: '/',\r\n base: pathPrefix,\r\n path: pathPrefix + '\\\\svg.css',\r\n contents: Buffer.from(converter.contentCss, 'utf8')\r\n });\r\n\r\n this.push(cssFile);\r\n\r\n const tsFile = new Vinyl({\r\n cwd: '/',\r\n base: pathPrefix,\r\n path: pathPrefix + '\\\\svg.ts',\r\n contents: Buffer.from(converter.contentTs, 'utf8')\r\n });\r\n\r\n this.push(tsFile);\r\n cb();\r\n });\r\n}\r\n\r\nmodule.exports = gulpSvgCode;\r\n"]}