本文整理汇总了TypeScript中broccoli-replace.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: makeNodeTree
module.exports = function makeNodeTree(destinationPath) {
// list of npm packages that this build will create
var outputPackages = ['angular2', 'benchpress', 'rtts_assert'];
var modulesTree = new Funnel('modules', {
include: ['angular2/**', 'benchpress/**', 'rtts_assert/**', '**/e2e_test/**'],
exclude: [
// the following code and tests are not compatible with CJS/node environment
'angular2/src/core/zone/vm_turn_zone.es6',
'angular2/test/core/zone/**'
]
});
var nodeTree = traceurCompiler(modulesTree, '.js', '.map', {
sourceMaps: true,
annotations: true, // parse annotations
types: true, // parse types
script: false, // parse as a module
memberVariables: true, // parse class fields
typeAssertionModule: 'rtts_assert/rtts_assert',
// Don't use type assertions since this is partly transpiled by typescript
typeAssertions: false,
modules: 'commonjs'
});
// Transform all tests to make them runnable in node
nodeTree = replace(nodeTree, {
files: ['**/test/**/*_spec.js'],
patterns: [
{
// Override the default DOM adapter with Parse5 for all tests
match: /"use strict";/,
replacement:
"'use strict'; var parse5Adapter = require('angular2/src/dom/parse5_adapter'); " +
"parse5Adapter.Parse5DomAdapter.makeCurrent();"
},
{
// Append main() to all tests since all of our tests are wrapped in exported main fn
match: /$/g,
replacement: "\r\n main();"
}
]
});
// Now we add the LICENSE file into all the folders that will become npm packages
outputPackages.forEach(function(destDir) {
var license = new Funnel('.', {files: ['LICENSE'], destDir: destDir});
nodeTree = mergeTrees([nodeTree, license]);
});
// Get all docs and related assets and prepare them for js build
var docs = new Funnel(modulesTree, {include: ['**/*.md', '**/*.png'], exclude: ['**/*.dart.md']});
docs = stew.rename(docs, 'README.js.md', 'README.md');
// Generate shared package.json info
var BASE_PACKAGE_JSON = require(path.join(projectRootDir, 'package.json'));
var COMMON_PACKAGE_JSON = {
version: BASE_PACKAGE_JSON.version,
homepage: BASE_PACKAGE_JSON.homepage,
bugs: BASE_PACKAGE_JSON.bugs,
license: BASE_PACKAGE_JSON.license,
contributors: BASE_PACKAGE_JSON.contributors,
dependencies: BASE_PACKAGE_JSON.dependencies,
devDependencies: {
"yargs": BASE_PACKAGE_JSON.devDependencies['yargs'],
"gulp-sourcemaps": BASE_PACKAGE_JSON.devDependencies['gulp-sourcemaps'],
"gulp-traceur": BASE_PACKAGE_JSON.devDependencies['gulp-traceur'],
"gulp": BASE_PACKAGE_JSON.devDependencies['gulp'],
"gulp-rename": BASE_PACKAGE_JSON.devDependencies['gulp-rename'],
"through2": BASE_PACKAGE_JSON.devDependencies['through2']
}
};
// Add a .template extension since renderLodashTemplate strips one extension
var packageJsons = stew.rename(new Funnel(modulesTree, {include: ['**/package.json']}), '.json',
'.json.template');
packageJsons = renderLodashTemplate(
packageJsons, {files: ["**/**"], context: {'packageJson': COMMON_PACKAGE_JSON}});
var typescriptTree = new TypescriptCompiler(modulesTree, {
target: 'ES5',
sourceMap: true,
mapRoot: '', /* force sourcemaps to use relative path */
module: 'commonjs',
allowNonTsExtensions: false,
typescript: require('typescript'),
noEmitOnError: true,
outDir: 'angular2'
});
nodeTree = mergeTrees([nodeTree, typescriptTree, docs, packageJsons]);
// TODO(iminar): tree differ seems to have issues with trees created by mergeTrees, investigate!
// ENOENT error is thrown while doing fs.readdirSync on inputRoot
// in the meantime, we just do noop mv to create a new tree
nodeTree = stew.mv(nodeTree, '');
return destCopy(nodeTree, destinationPath);
};
示例2: destCopy
module.exports = function makeNodeTree(destinationPath) {
// list of npm packages that this build will create
var outputPackages = ['angular2', 'benchpress', 'rtts_assert'];
var modulesTree = new Funnel('modules', {
include: ['angular2/**', 'benchpress/**', 'rtts_assert/**', '**/e2e_test/**'],
exclude: [
// the following code and tests are not compatible with CJS/node environment
'angular2/test/core/zone/**',
'angular2/test/test_lib/fake_async_spec.ts',
'angular2/test/services/xhr_impl_spec.ts',
'angular2/test/forms/**'
]
});
var nodeTree = transpileWithTraceur(modulesTree, {
destExtension: '.js',
destSourceMapExtension: '.map',
traceurOptions: {
sourceMaps: true,
annotations: true, // parse annotations
types: true, // parse types
script: false, // parse as a module
memberVariables: true, // parse class fields
typeAssertionModule: 'rtts_assert/rtts_assert',
// Don't use type assertions since this is partly transpiled by typescript
typeAssertions: false,
modules: 'commonjs'
}
});
// Now we add the LICENSE file into all the folders that will become npm packages
outputPackages.forEach(function(destDir) {
var license = new Funnel('.', {files: ['LICENSE'], destDir: destDir});
nodeTree = mergeTrees([nodeTree, license]);
});
// Get all docs and related assets and prepare them for js build
var docs = new Funnel(modulesTree, {include: ['**/*.md', '**/*.png'], exclude: ['**/*.dart.md']});
docs = stew.rename(docs, 'README.js.md', 'README.md');
// Generate shared package.json info
var BASE_PACKAGE_JSON = require(path.join(projectRootDir, 'package.json'));
var COMMON_PACKAGE_JSON = {
version: BASE_PACKAGE_JSON.version,
homepage: BASE_PACKAGE_JSON.homepage,
bugs: BASE_PACKAGE_JSON.bugs,
license: BASE_PACKAGE_JSON.license,
contributors: BASE_PACKAGE_JSON.contributors,
dependencies: BASE_PACKAGE_JSON.dependencies,
devDependencies: {
"yargs": BASE_PACKAGE_JSON.devDependencies['yargs'],
"gulp-sourcemaps": BASE_PACKAGE_JSON.devDependencies['gulp-sourcemaps'],
"gulp-traceur": BASE_PACKAGE_JSON.devDependencies['gulp-traceur'],
"gulp": BASE_PACKAGE_JSON.devDependencies['gulp'],
"gulp-rename": BASE_PACKAGE_JSON.devDependencies['gulp-rename'],
"through2": BASE_PACKAGE_JSON.devDependencies['through2']
}
};
// Add a .template extension since renderLodashTemplate strips one extension
var packageJsons = stew.rename(new Funnel(modulesTree, {include: ['**/package.json']}), '.json',
'.json.template');
packageJsons = renderLodashTemplate(
packageJsons, {files: ["**/**"], context: {'packageJson': COMMON_PACKAGE_JSON}});
// HACK: workaround for Traceur behavior.
// It expects all transpiled modules to contain this marker.
// TODO: remove this when we no longer use traceur
var traceurCompatibleTsModulesTree = replace(modulesTree, {
files: ['**/*.ts'],
patterns: [
{
// Empty replacement needed so that replaceWithPath gets triggered...
match: /$/g,
replacement: ""
}
],
replaceWithPath: function(path, content) {
if (!path.endsWith('.d.ts')) {
content += '\r\nexport var __esModule = true;\n';
}
return content;
}
});
var typescriptTree = compileWithTypescript(traceurCompatibleTsModulesTree, {
allowNonTsExtensions: false,
emitDecoratorMetadata: true,
declaration: true,
mapRoot: '', /* force sourcemaps to use relative path */
module: 'commonjs',
noEmitOnError: true,
rootDir: '.',
rootFilePaths: ['angular2/traceur-runtime.d.ts', 'angular2/globals.d.ts'],
sourceMap: true,
sourceRoot: '.',
target: 'ES5'
});
//.........这里部分代码省略.........
示例3: Funnel
module.exports = function makeBrowserTree(options, destinationPath) {
var modulesTree = new Funnel(
'modules',
{include: ['**/**'], exclude: ['**/*.cjs', 'benchmarks/e2e_test/**'], destDir: '/'});
// Use Traceur to transpile *.js sources to ES6
var traceurTree = transpileWithTraceur(modulesTree, {
destExtension: '.es6',
destSourceMapExtension: '.map',
traceurOptions: {
sourceMaps: true,
annotations: true, // parse annotations
types: true, // parse types
script: false, // parse as a module
memberVariables: true, // parse class fields
modules: 'instantiate',
// typeAssertionModule: 'rtts_assert/rtts_assert',
// typeAssertions: options.typeAssertions,
outputLanguage: 'es6'
}
});
// Use TypeScript to transpile the *.ts files to ES6
// We don't care about errors: we let the TypeScript compilation to ES5
// in node_tree.ts do the type-checking.
var typescriptTree = compileWithTypescript(modulesTree, {
allowNonTsExtensions: false,
declaration: true,
emitDecoratorMetadata: true,
mapRoot: '', // force sourcemaps to use relative path
noEmitOnError: false, // temporarily ignore errors, we type-check only via cjs build
rootDir: '.',
sourceMap: true,
sourceRoot: '.',
target: 'ES6'
});
typescriptTree = stew.rename(typescriptTree, '.js', '.es6');
var es6Tree = mergeTrees([traceurTree, typescriptTree]);
// TODO(iminar): tree differ seems to have issues with trees created by mergeTrees, investigate!
// ENOENT error is thrown while doing fs.readdirSync on inputRoot
// in the meantime, we just do noop mv to create a new tree
es6Tree = stew.mv(es6Tree, '');
// Call Traceur again to lower the ES6 build tree to ES5
var es5Tree = transpileWithTraceur(es6Tree, {
destExtension: '.js',
destSourceMapExtension: '.js.map',
traceurOptions: {modules: 'instantiate', sourceMaps: true}
});
// Now we add a few more files to the es6 tree that Traceur should not see
['angular2', 'rtts_assert'].forEach(function(destDir) {
var extras = new Funnel('tools/build', {files: ['es5build.js'], destDir: destDir});
es6Tree = mergeTrees([es6Tree, extras]);
});
var vendorScriptsTree = flatten(new Funnel('.', {
files: [
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
'node_modules/zone.js/zone.js',
'node_modules/zone.js/long-stack-trace-zone.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/systemjs/lib/extension-register.js',
'node_modules/systemjs/lib/extension-cjs.js',
'node_modules/rx/dist/rx.js',
'node_modules/reflect-metadata/Reflect.js',
'tools/build/snippets/runtime_paths.js',
path.relative(projectRootDir, TRACEUR_RUNTIME_PATH)
]
}));
var vendorScripts_benchmark =
new Funnel('tools/build/snippets', {files: ['url_params_to_form.js'], destDir: '/'});
var vendorScripts_benchmarks_external =
new Funnel('node_modules/angular', {files: ['angular.js'], destDir: '/'});
var servingTrees = [];
function copyVendorScriptsTo(destDir) {
servingTrees.push(new Funnel(vendorScriptsTree, {srcDir: '/', destDir: destDir}));
if (destDir.indexOf('benchmarks') > -1) {
servingTrees.push(new Funnel(vendorScripts_benchmark, {srcDir: '/', destDir: destDir}));
}
if (destDir.indexOf('benchmarks_external') > -1) {
servingTrees.push(
new Funnel(vendorScripts_benchmarks_external, {srcDir: '/', destDir: destDir}));
}
}
function writeScriptsForPath(relativePath, result) {
copyVendorScriptsTo(path.dirname(relativePath));
return result.replace('@@FILENAME_NO_EXT', relativePath.replace(/\.\w+$/, ''));
}
var htmlTree = new Funnel(modulesTree, {include: ['*/src/**/*.html'], destDir: '/'});
htmlTree = replace(htmlTree, {
files: ['examples*/**'],
patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')}],
//.........这里部分代码省略.........
示例4: TraceurCompiler
module.exports = function makeBrowserTree(options) {
var modulesTree = new Funnel(
'modules',
{include: ['**/**'], exclude: ['**/*.cjs', 'benchmarks/e2e_test/**'], destDir: '/'});
// Use Traceur to transpile original sources to ES6
var es6Tree = new TraceurCompiler(modulesTree, '.es6', '.map', {
sourceMaps: true,
annotations: true, // parse annotations
types: true, // parse types
script: false, // parse as a module
memberVariables: true, // parse class fields
modules: 'instantiate',
typeAssertionModule: 'rtts_assert/rtts_assert',
typeAssertions: options.typeAssertions,
outputLanguage: 'es6'
});
// Call Traceur again to lower the ES6 build tree to ES5
var es5Tree =
new TraceurCompiler(es6Tree, '.js', '.js.map', {modules: 'instantiate', sourceMaps: true});
// Now we add a few more files to the es6 tree that Traceur should not see
['angular2', 'rtts_assert'].forEach(function(destDir) {
var extras = new Funnel('tools/build', {files: ['es5build.js'], destDir: destDir});
es6Tree = mergeTrees([es6Tree, extras]);
});
var vendorScriptsTree = flatten(new Funnel('.', {
files: [
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
'node_modules/zone.js/zone.js',
'node_modules/zone.js/long-stack-trace-zone.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/systemjs/lib/extension-register.js',
'node_modules/systemjs/lib/extension-cjs.js',
'node_modules/rx/dist/rx.all.js',
'tools/build/snippets/runtime_paths.js',
path.relative(projectRootDir, TraceurCompiler.RUNTIME_PATH)
]
}));
var vendorScripts_benchmark =
new Funnel('tools/build/snippets', {files: ['url_params_to_form.js'], destDir: '/'});
var vendorScripts_benchmarks_external =
new Funnel('node_modules/angular', {files: ['angular.js'], destDir: '/'});
var servingTrees = [];
function copyVendorScriptsTo(destDir) {
servingTrees.push(new Funnel(vendorScriptsTree, {srcDir: '/', destDir: destDir}));
if (destDir.indexOf('benchmarks') > -1) {
servingTrees.push(new Funnel(vendorScripts_benchmark, {srcDir: '/', destDir: destDir}));
}
if (destDir.indexOf('benchmarks_external') > -1) {
servingTrees.push(
new Funnel(vendorScripts_benchmarks_external, {srcDir: '/', destDir: destDir}));
}
}
function writeScriptsForPath(relativePath, result) {
copyVendorScriptsTo(path.dirname(relativePath));
return result.replace('@@FILENAME_NO_EXT', relativePath.replace(/\.\w+$/, ''));
}
var htmlTree = new Funnel(modulesTree, {include: ['*/src/**/*.html'], destDir: '/'});
htmlTree = replace(htmlTree, {
files: ['examples*/**'],
patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')}],
replaceWithPath: writeScriptsForPath
});
htmlTree = replace(htmlTree, {
files: ['benchmarks/**'],
patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks')}],
replaceWithPath: writeScriptsForPath
});
htmlTree = replace(htmlTree, {
files: ['benchmarks_external/**'],
patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks_external')}],
replaceWithPath: writeScriptsForPath
});
// Copy all vendor scripts into all examples and benchmarks
['benchmarks/src', 'benchmarks_external/src', 'examples/src/benchpress'].forEach(
copyVendorScriptsTo);
var scripts = mergeTrees(servingTrees, {overwrite: true});
var css = new Funnel(modulesTree, {include: ["**/*.css"]});
var polymerFiles = new Funnel('.', {
files: [
'bower_components/polymer/lib/polymer.html',
'tools/build/snippets/url_params_to_form.js'
]
});
var polymer = stew.mv(flatten(polymerFiles), 'benchmarks_external/src/tree/polymer');
htmlTree = mergeTrees([htmlTree, scripts, polymer, css]);
es5Tree = mergeTrees([es5Tree, htmlTree]);
//.........这里部分代码省略.........