error: (error: TypeScriptError) => { if (error.tsFile) { console.error('[' + gutil.colors.gray('gulp-typescript') + '] ' + gutil.colors.red(error.fullFilename + '(' + error.startPosition.line + ',' + error.startPosition.character + '): ') + 'error TS' + error.diagnostic.code + ' ' + flattenDiagnosticsVerbose(error.diagnostic.messageText)); } else { console.error(error.message); } },
fileDownload.init().then((files) => { if (files === null) { gutil.log(gutil.colors.yellow("No files found on the specified startFolder path")); } else { gutil.log(gutil.colors.green("Retrieved all files from the folder.")); // Start retrieving the file content let proms = []; files.forEach(file => { proms.push(fileDownload.download(file).then((uFile: IFileDownload) => { var vinylFile: any = new gutil.File({ cwd: "", base: "", path: uFile.name, contents: ((uFile.content instanceof Buffer) ? uFile.content : new Buffer(uFile.content)) }); stream.write(vinylFile); })); }); Promise.all(proms).then(data => { if (options.verbose) { gutil.log("And we're done..."); } // End the file stream stream.end(); }); } }).catch(err => {
function log(): void { const errors = _.flatten(allErrors); const seen = new Set<string>(); errors.map(err => { if (!seen.has(err)) { seen.add(err); util.log(`${util.colors.red('Error')}: ${err}`); } }); const regex = /^([^(]+)\((\d+),(\d+)\): (.*)$/; const messages = errors .map(err => regex.exec(err)) .filter(match => !!match) .map(x => x as string[]) .map(([, path, line, column, message]) => ({ path, line: parseInt(line), column: parseInt(column), message })); try { fs.writeFileSync(buildLogPath, JSON.stringify(messages)); } catch (err) { //noop } util.log(`Finished ${util.colors.green('compilation')} with ${errors.length} errors after ${util.colors.magenta((new Date().getTime() - startTime!) + ' ms')}`); }
action: function (packageDescriptor: PackageDescriptor, packagePath: string, callback: (error?: Error) => void): void { let packageTypingsFilePath = path.join(packagePath, "typings.json"); let packageTypingsPath = path.join(packagePath, targetPath); if (!fs.existsSync(packageTypingsPath)) { fs.mkdirSync(packageTypingsPath); } else { rimraf.sync(packageTypingsPath + "/**/*"); } Logger.verbose(`Linking typings for workspace package '${util.colors.cyan(packageDescriptor.name)}'`); let typingFilePaths = getTypingFileReferences(require(packageTypingsFilePath)); for (let typingFilePathEntry in typingFilePaths) { let typingFilePath = path.resolve(packagePath, typingFilePaths[typingFilePathEntry]); let targetTypingFilePath = path.join(packageTypingsPath, typingFilePathEntry); fs.mkdirSync(targetTypingFilePath); fs.symlinkSync(typingFilePath, path.join(targetTypingFilePath, `${typingFilePathEntry}.d.ts`)); Logger.verbose(`Linked typing '${util.colors.cyan(typingFilePathEntry)}' (-> '${util.colors.blue(typingFilePath)}')`); } callback(); }
/** * Creates a symbolic link between a package and a mapped path where the mapped path is external to the workspace. */ function linkExternalPackage(pluginBinding: NpmPluginBinding<NpmInstallOptions & NpmWorkspacePluginOptions>, packageName: string, packagePath: string, mappedPath: string) { if (pluginBinding.options.registryMap[packageName]) { Logger.warn(util.colors.yellow(`Package '${packageName}' has an entry in options.registryMap. Ignoring.`)); } if (!path.isAbsolute(mappedPath)) { mappedPath = path.normalize(path.join(pluginBinding.options.cwd, mappedPath)); } if (mappedPath.indexOf(pluginBinding.options.cwd) >= 0) { Logger.warn(util.colors.yellow(`externalWorkspacePackageMap['${packageName}'] is linking to a path inside the current workspace. Ignoring, but it should be removed.`)); } let packageDescriptorPath = path.join(mappedPath, "package.json"); if (!fs.existsSync(packageDescriptorPath)) { throw new Error(`externalWorkspacePackageMap['${packageName}'] is linking to a path that is not a packge. No 'package.json' could be found at '${mappedPath}'.`); } let packageDescriptor: PackageDescriptor = require(packageDescriptorPath); if (packageDescriptor.name !== packageName) { throw new Error(`externalWorkspacePackageMap['${packageName}'] is linking to a package that is named differently ('${packageDescriptor.name}').`); } pluginBinding.createPackageSymLink(packagePath, packageName, mappedPath); Logger.verbose(`Linked '${util.colors.cyan(packageName)}' (-> '${util.colors.blue(mappedPath)}') - (${util.colors.bold("external")})`); }
}).catch(err => { if (typeof err.message !== "undefined") { gutil.log(gutil.colors.red(`ERROR: ${err.message}`)); } else { gutil.log(gutil.colors.red(`ERROR: ${JSON.stringify(err)}`)); } });
error: (error: TypeScriptError, typescript: typeof ts) => { console.error('[' + gutil.colors.gray('gulp-typescript') + '] ' + gutil.colors.bgRed(error.diagnostic.code + '') + ' ' + gutil.colors.red(flattenDiagnosticsVerbose(error.diagnostic.messageText)) ); if (error.tsFile) { console.error('> ' + gutil.colors.gray('file: ') + (fullFilename ? error.fullFilename : error.relativeFilename) + gutil.colors.gray(':')); const lines = error.tsFile.text.split(/(\r\n|\r|\n)/); const logLine = (lineIndex: number, errorStart: number, errorEnd?: number) => { const line = lines[lineIndex]; if (errorEnd === undefined) errorEnd = line.length; console.error('> ' + gutil.colors.gray('[' + lineIndex + '] ') + line.substring(0, errorStart) + gutil.colors.red(line.substring(errorStart, errorEnd)) + line.substring(errorEnd) ); } for (let i = error.startPosition.line; i <= error.endPosition.line; i++) { logLine(i, i === error.startPosition.line ? error.startPosition.character - 1 : 0, i === error.endPosition.line ? error.endPosition.character - 1 : undefined ); } } },
return new Promise<void>((resolve, reject) => { Logger.info(util.colors.bold(`Uninstalling workspace package '${util.colors.cyan(packageDescriptor.name)}'`)); try { rimraf.sync(path.resolve(packagePath, "node_modules")); let postUninstallActions: ConditionableAction<AsyncAction>[] = _.union(pluginBinding.options.postUninstallActions, file["getWorkspace"]()["postUninstall"]); if (postUninstallActions) { Logger.verbose(`Running post-uninstall actions for workspace package '${util.colors.cyan(packageDescriptor.name)}'`); executeAsynchronousActions(postUninstallActions, packageDescriptor, packagePath) .then(resolve) .catch((error) => { handleError(error, packageDescriptor.name, pluginBinding.options.continueOnError, reject); }); } else { resolve(); } } catch (error) { handleError(error, packageDescriptor.name, pluginBinding.options.continueOnError, reject); } });
}).catch(error => { if (typeof error === "string") { gutil.log(gutil.colors.red(`ERROR: ${error}`)); } else { gutil.log(gutil.colors.red('ERROR:'), JSON.stringify(error)); } resolve(null); });
export = (done: any) => { util.log(util.colors.yellow(` Warning! Please use ${util.colors.green('npm run build.prod')} Instead of ${util.colors.red('npm run build.prod.aot')} or ${util.colors.red('npm run build.prod.aot')} They will be deleted soon!`)); done(); };