本文整理匯總了TypeScript中gulp-insert.transform函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript transform函數的具體用法?TypeScript transform怎麽用?TypeScript transform使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了transform函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getCompilerSettings
gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/false));
const {js, dts} = servicesProject.src()
.pipe(newer(servicesFile))
.pipe(sourcemaps.init())
.pipe(tsc(servicesProject));
const completedJs = js.pipe(prependCopyright())
.pipe(sourcemaps.write("."));
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/true))
.pipe(insert.transform((contents, file) => {
file.path = standaloneDefinitionsFile;
return contents.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, "$1$2enum $3 {$4");
}));
return merge2([
completedJs,
completedJs.pipe(clone())
.pipe(insert.transform((content, file) => (file.path = nodePackageFile, content))),
completedDts,
completedDts.pipe(clone())
.pipe(insert.transform((content, file) => {
file.path = nodeDefinitionsFile;
return content + "\r\nexport = ts;";
}))
.pipe(gulp.dest(builtLocalDirectory)),
completedDts.pipe(clone())
.pipe(insert.transform((content, file) => {
file.path = nodeStandaloneDefinitionsFile;
return content.replace(/declare (namespace|module) ts/g, 'declare module "typescript"');
}))
]).pipe(gulp.dest(builtLocalDirectory));
});
示例2: function
gulp.task("compile", function() {
var tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(ts(tsProject));
var dts = tsResult.dts
.pipe(insert.transform(function(contents: string, file: any) {
contents = contents.replace(/\/\/\/\s*\<reference path=".*"\s*\/\>\s*\n/ig, "");
contents += "declare module \"updraft\" {\n" +
" export = Updraft;\n" +
"}\n";
return contents;
}));
dts = tsResult.dts.pipe(gulp.dest("./"));
var js = tsResult.js;
js = js.pipe(insert.transform(function(contents: string, file: any) {
contents = contents.replace(/(Updraft = {})/g, "/* istanbul ignore next */ $1");
contents = contents.replace(/(var _a(,|;))/g, "/* istanbul ignore next */ $1");
return contents;
}));
if(minify) {
js = js.pipe(uglify());
}
js = js
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("./"));
return merge([dts, js]);
});
示例3:
gulp.task(typesMapJson, /*help*/ false, [], () => {
return gulp.src("src/server/typesMap.json")
.pipe(insert.transform((contents, file) => {
JSON.parse(contents);
return contents;
}))
.pipe(gulp.dest(builtLocalDirectory));
});
示例4: baselineDelete
function baselineDelete(subfolder = "") {
return gulp.src(["tests/baselines/local/**/*.delete"])
.pipe(insert.transform((content, fileObj) => {
const target = path.join(refBaseline, fileObj.relative.substr(0, fileObj.relative.length - ".delete".length));
del.sync(target);
del.sync(fileObj.path);
return "";
}));
}
示例5:
gulp.task('gulp-insert-tests', () => {
return gulp.src('*.js')
.pipe(insert.prepend('/* Inserted using gulp-insert prepend method */\n'))
.pipe(insert.prepend('\n/* Inserted using gulp-insert append method */'))
.pipe(insert.wrap(
'/* Inserted using gulp-insert wrap method */\n',
'\n/* Inserted using gulp-insert wrap method */'
))
.pipe(insert.transform((contents, file) => {
var comment = '/* Local file: ' + file.path + ' */\n';
return comment + contents;
}))
.pipe(gulp.dest('gulp-insert'));
});
示例6: getCompilerSettings
gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
const serverLibraryProject = tsc.createProject("src/server/tsconfig.library.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
const {js, dts}: { js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream } = serverLibraryProject.src()
.pipe(sourcemaps.init())
.pipe(newer(tsserverLibraryFile))
.pipe(serverLibraryProject());
return merge2([
js.pipe(prependCopyright())
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(".")),
dts.pipe(prependCopyright(/*outputCopyright*/true))
.pipe(insert.transform((content) => {
return content + "\r\nexport = ts;\r\nexport as namespace ts;";
}))
.pipe(gulp.dest("."))
]);
});
示例7: RegExp
gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules"], () => {
const fileMatcher = RegExp(cmdLineOptions["files"]);
const lintOptions = getLinterOptions();
let failed = 0;
return gulp.src(lintTargets)
.pipe(insert.transform((contents, file) => {
if (!fileMatcher.test(file.path)) return contents;
const result = lintFile(lintOptions, file.path);
if (result.failureCount > 0) {
console.log(result.output);
failed += result.failureCount;
}
return contents; // TODO (weswig): Automatically apply fixes? :3
}))
.on("end", () => {
if (failed > 0) {
console.error("Linter errors.");
process.exit(1);
}
});
});