{"version":3,"sources":["../src/run.ts"],"names":[],"mappings":";AA2BA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAC,GAAG,EAAC,MAAM,aAAa,CAAC;AAEhC,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAajD,qBAAa,GAAG;IACf,SAAgB,MAAM,EAAE,YAAY,CAAC;IACrC,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,GAAG,EAAE,GAAG,CAAC;gBAEb,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,GAAG;IAmBhD,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;IAiCtE,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;CAU3F","file":"run.d.ts","sourcesContent":["/**\n *\tMIT License\n *\n *\tCopyright (c) 2019 - 2022 Toreda, Inc.\n *\n *\tPermission is hereby granted, free of charge, to any person obtaining a copy\n *\tof this software and associated documentation files (the \"Software\"), to deal\n *\tin the Software without restriction, including without limitation the rights\n *\tto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n *\tcopies of the Software, and to permit persons to whom the Software is\n *\tfurnished to do so, subject to the following conditions:\n\n * \tThe above copyright notice and this permission notice shall be included in all\n * \tcopies or substantial portions of the Software.\n *\n * \tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n *\tIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n *\tFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * \tAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n *\tLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n *\tOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * \tSOFTWARE.\n *\n */\n\nimport {dest, src} from 'gulp';\n\nimport {Config} from './config';\nimport {EventEmitter} from 'events';\nimport {Log} from '@toreda/log';\nimport Path from 'path';\nimport {WebpackOptions} from './webpack/options';\nimport sourcemaps from 'gulp-sourcemaps';\nimport tsc from 'gulp-typescript';\nimport webpack from 'webpack';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst mergeStream = require('merge-stream');\n\n/**\n * Run other packages used in the build process with minimal config.\n *\n * @category Run\n */\nexport class Run {\n\tpublic readonly events: EventEmitter;\n\tpublic readonly cfg: Config;\n\tpublic readonly log: Log;\n\n\tconstructor(cfg: Config, events: EventEmitter, log: Log) {\n\t\tif (!cfg) {\n\t\t\tthrow new Error('Run init - cfg arg missing.');\n\t\t}\n\n\t\tif (!events) {\n\t\t\tthrow new Error('Run init - events arg missing.');\n\t\t}\n\n\t\tthis.log = log.makeLog('Run');\n\t\tthis.events = events;\n\t\tthis.cfg = cfg;\n\t}\n\n\t/**\n\t * Run webpack during build process.\n\t * @param options\t\tOptions provided to webpack.\n\t * @returns\n\t */\n\tpublic webpack(options: WebpackOptions = {}): Promise<NodeJS.ReadWriteStream> {\n\t\tconst fnLog = this.log.makeLog('webpack');\n\t\tfnLog.debug('Webpack started');\n\t\tconst cfgPath = this.cfg.getWebpackCfgPath(options);\n\n\t\tconst resolvedPath = Path.resolve(cfgPath);\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\timport(resolvedPath).then((webpackConfig) => {\n\t\t\t\twebpack(webpackConfig, (err, stats) => {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\tfnLog.error(`Webpack stopped due to failure: ${err.message}.`);\n\t\t\t\t\t\treturn reject(err);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!stats) {\n\t\t\t\t\t\tthrow new Error('weback build failure: no stats in build callback');\n\t\t\t\t\t}\n\n\t\t\t\t\tif (stats.hasErrors()) {\n\t\t\t\t\t\tfnLog.error('webpack build error: ');\n\t\t\t\t\t\tstats.compilation.errors.forEach((error) => {\n\t\t\t\t\t\t\tfnLog.error(error);\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn reject(stats.compilation.errors.join('\\n'));\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(src('.', {allowEmpty: true}));\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t}\n\n\tpublic typescript(destPath: string, tsConfigPath?: string): Promise<NodeJS.ReadWriteStream> {\n\t\tconst outputPath = typeof destPath === 'string' ? destPath : 'dist';\n\t\tconst useConfigPath = tsConfigPath ? tsConfigPath : './tsconfig.json';\n\t\t// eslint-disable-next-line @typescript-eslint/no-var-requires\n\t\tconst tsConfig = require(Path.resolve(useConfigPath));\n\t\tconst filesGlob = tsConfig.filesGlob;\n\n\t\tconst tsResult = src(filesGlob).pipe(tsc(tsConfig.compilerOptions));\n\t\treturn mergeStream(tsResult, tsResult.js).pipe(sourcemaps.write('.')).pipe(dest(outputPath));\n\t}\n}\n"]}