refactor: use a custom replacement build step instead of broccoli-replace
Closes #2050
This commit is contained in:
parent
7141c15e65
commit
d5c528ac2b
|
@ -1374,87 +1374,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"broccoli-replace": {
|
|
||||||
"version": "0.2.0",
|
|
||||||
"resolved": "git://github.com/alexeagle/broccoli-replace.git#cd39a543b17b40db765a07762f099fbc85518290",
|
|
||||||
"dependencies": {
|
|
||||||
"minimatch": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"dependencies": {
|
|
||||||
"lru-cache": {
|
|
||||||
"version": "2.6.2"
|
|
||||||
},
|
|
||||||
"sigmund": {
|
|
||||||
"version": "1.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"applause": {
|
|
||||||
"version": "0.3.4",
|
|
||||||
"dependencies": {
|
|
||||||
"cson": {
|
|
||||||
"version": "1.6.2",
|
|
||||||
"dependencies": {
|
|
||||||
"ambi": {
|
|
||||||
"version": "2.2.0",
|
|
||||||
"dependencies": {
|
|
||||||
"typechecker": {
|
|
||||||
"version": "2.0.8"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"coffee-script": {
|
|
||||||
"version": "1.8.0",
|
|
||||||
"dependencies": {
|
|
||||||
"mkdirp": {
|
|
||||||
"version": "0.3.5"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"extract-opts": {
|
|
||||||
"version": "2.2.0",
|
|
||||||
"dependencies": {
|
|
||||||
"typechecker": {
|
|
||||||
"version": "2.0.8"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"js2coffee": {
|
|
||||||
"version": "0.3.5",
|
|
||||||
"dependencies": {
|
|
||||||
"coffee-script": {
|
|
||||||
"version": "1.7.1",
|
|
||||||
"dependencies": {
|
|
||||||
"mkdirp": {
|
|
||||||
"version": "0.3.5"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"file": {
|
|
||||||
"version": "0.2.2"
|
|
||||||
},
|
|
||||||
"nopt": {
|
|
||||||
"version": "3.0.1",
|
|
||||||
"dependencies": {
|
|
||||||
"abbrev": {
|
|
||||||
"version": "1.0.5"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"underscore": {
|
|
||||||
"version": "1.6.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"requirefresh": {
|
|
||||||
"version": "1.1.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"broccoli-slow-trees": {
|
"broccoli-slow-trees": {
|
||||||
"version": "1.1.0"
|
"version": "1.1.0"
|
||||||
},
|
},
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -48,7 +48,6 @@
|
||||||
"broccoli-funnel": "igorminar/broccoli-funnel#perf-files",
|
"broccoli-funnel": "igorminar/broccoli-funnel#perf-files",
|
||||||
"broccoli-lodash": "^0.1.1",
|
"broccoli-lodash": "^0.1.1",
|
||||||
"broccoli-merge-trees": "^0.2.1",
|
"broccoli-merge-trees": "^0.2.1",
|
||||||
"broccoli-replace": "alexeagle/broccoli-replace#angular_patch",
|
|
||||||
"broccoli-slow-trees": "^1.1.0",
|
"broccoli-slow-trees": "^1.1.0",
|
||||||
"broccoli-stew": "^0.2.1",
|
"broccoli-stew": "^0.2.1",
|
||||||
"broccoli-writer": "^0.1.1",
|
"broccoli-writer": "^0.1.1",
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
import fs = require('fs');
|
||||||
|
import fse = require('fs-extra');
|
||||||
|
import path = require('path');
|
||||||
|
import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from './diffing-broccoli-plugin';
|
||||||
|
|
||||||
|
var minimatch = require('minimatch');
|
||||||
|
var exec = require('child_process').exec;
|
||||||
|
|
||||||
|
var FILE_ENCODING = {encoding: 'utf-8'};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Intercepts each changed file and replaces its contents with
|
||||||
|
* the associated changes.
|
||||||
|
*/
|
||||||
|
class DiffingReplace implements DiffingBroccoliPlugin {
|
||||||
|
constructor(private inputPath, private cachePath, private options) {}
|
||||||
|
|
||||||
|
rebuild(treeDiff: DiffResult) {
|
||||||
|
var patterns = this.options.patterns;
|
||||||
|
var files = this.options.files;
|
||||||
|
|
||||||
|
treeDiff.changedPaths.forEach((changedFilePath) => {
|
||||||
|
var sourceFilePath = path.join(this.inputPath, changedFilePath)
|
||||||
|
var destFilePath = path.join(this.cachePath, changedFilePath);
|
||||||
|
var destDirPath = path.dirname(destFilePath);
|
||||||
|
|
||||||
|
if (!fs.existsSync(destDirPath)) {
|
||||||
|
fse.mkdirpSync(destDirPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileMatches = files.some((filePath) => minimatch(changedFilePath, filePath));
|
||||||
|
if (fileMatches) {
|
||||||
|
var content = fs.readFileSync(sourceFilePath, FILE_ENCODING);
|
||||||
|
patterns.forEach((pattern) => {
|
||||||
|
var replacement = pattern.replacement;
|
||||||
|
if (typeof replacement === 'function') {
|
||||||
|
replacement = function(content) {
|
||||||
|
return pattern.replacement(content, changedFilePath);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
content = content.replace(pattern.match, replacement);
|
||||||
|
});
|
||||||
|
fs.writeFileSync(destFilePath, content, FILE_ENCODING);
|
||||||
|
} else {
|
||||||
|
fs.symlinkSync(sourceFilePath, destFilePath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
treeDiff.removedPaths.forEach((removedFilePath) => {
|
||||||
|
var destFilePath = path.join(this.cachePath, removedFilePath);
|
||||||
|
fs.unlinkSync(destFilePath);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default wrapDiffingPlugin(DiffingReplace);
|
|
@ -5,12 +5,12 @@ var flatten = require('broccoli-flatten');
|
||||||
var htmlReplace = require('../html-replace');
|
var htmlReplace = require('../html-replace');
|
||||||
import mergeTrees from '../broccoli-merge-trees';
|
import mergeTrees from '../broccoli-merge-trees';
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var replace = require('broccoli-replace');
|
|
||||||
var stew = require('broccoli-stew');
|
var stew = require('broccoli-stew');
|
||||||
|
|
||||||
import compileWithTypescript from '../broccoli-typescript';
|
import compileWithTypescript from '../broccoli-typescript';
|
||||||
import destCopy from '../broccoli-dest-copy';
|
import destCopy from '../broccoli-dest-copy';
|
||||||
import {default as transpileWithTraceur, TRACEUR_RUNTIME_PATH} from '../traceur/index';
|
import {default as transpileWithTraceur, TRACEUR_RUNTIME_PATH} from '../traceur/index';
|
||||||
|
import replace from '../broccoli-replace';
|
||||||
|
|
||||||
|
|
||||||
var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
|
var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
|
||||||
|
@ -146,25 +146,36 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||||
return funnels;
|
return funnels;
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeScriptsForPath(relativePath, result) {
|
var scriptPathPatternReplacement = {
|
||||||
return result.replace('@@FILENAME_NO_EXT', relativePath.replace(/\.\w+$/, ''));
|
match: '@@FILENAME_NO_EXT',
|
||||||
}
|
replacement: function(replacement, relativePath) {
|
||||||
|
return relativePath.replace(/\.\w+$/, '');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var htmlTree = new Funnel(modulesTree, {include: ['*/src/**/*.html'], destDir: '/'});
|
var htmlTree = new Funnel(modulesTree, {include: ['*/src/**/*.html'], destDir: '/'});
|
||||||
htmlTree = replace(htmlTree, {
|
htmlTree = replace(htmlTree, {
|
||||||
files: ['examples*/**'],
|
files: ['examples*/**'],
|
||||||
patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')}],
|
patterns: [
|
||||||
replaceWithPath: writeScriptsForPath
|
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')},
|
||||||
|
scriptPathPatternReplacement
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
htmlTree = replace(htmlTree, {
|
htmlTree = replace(htmlTree, {
|
||||||
files: ['benchmarks/**'],
|
files: ['benchmarks/**'],
|
||||||
patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks')}],
|
patterns: [
|
||||||
replaceWithPath: writeScriptsForPath
|
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks')},
|
||||||
|
scriptPathPatternReplacement
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
htmlTree = replace(htmlTree, {
|
htmlTree = replace(htmlTree, {
|
||||||
files: ['benchmarks_external/**'],
|
files: ['benchmarks_external/**'],
|
||||||
patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks_external')}],
|
patterns: [
|
||||||
replaceWithPath: writeScriptsForPath
|
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks_external')},
|
||||||
|
scriptPathPatternReplacement
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
var scripts = mergeTrees(servingTrees);
|
var scripts = mergeTrees(servingTrees);
|
||||||
|
|
|
@ -9,10 +9,10 @@ var glob = require('glob');
|
||||||
import mergeTrees from '../broccoli-merge-trees';
|
import mergeTrees from '../broccoli-merge-trees';
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var renderLodashTemplate = require('broccoli-lodash');
|
var renderLodashTemplate = require('broccoli-lodash');
|
||||||
var replace = require('broccoli-replace');
|
|
||||||
var stew = require('broccoli-stew');
|
var stew = require('broccoli-stew');
|
||||||
import ts2dart from '../broccoli-ts2dart';
|
import ts2dart from '../broccoli-ts2dart';
|
||||||
import dartfmt from '../broccoli-dartfmt';
|
import dartfmt from '../broccoli-dartfmt';
|
||||||
|
import replace from '../broccoli-replace';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A funnel starting at modules, including the given filters, and moving into the root.
|
* A funnel starting at modules, including the given filters, and moving into the root.
|
||||||
|
|
|
@ -7,7 +7,7 @@ var Funnel = require('broccoli-funnel');
|
||||||
import mergeTrees from '../broccoli-merge-trees';
|
import mergeTrees from '../broccoli-merge-trees';
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var renderLodashTemplate = require('broccoli-lodash');
|
var renderLodashTemplate = require('broccoli-lodash');
|
||||||
var replace = require('broccoli-replace');
|
import replace from '../broccoli-replace';
|
||||||
var stew = require('broccoli-stew');
|
var stew = require('broccoli-stew');
|
||||||
|
|
||||||
var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
|
var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
|
||||||
|
@ -84,19 +84,16 @@ module.exports = function makeNodeTree(destinationPath) {
|
||||||
// TODO: remove this when we no longer use traceur
|
// TODO: remove this when we no longer use traceur
|
||||||
var traceurCompatibleTsModulesTree = replace(modulesTree, {
|
var traceurCompatibleTsModulesTree = replace(modulesTree, {
|
||||||
files: ['**/*.ts'],
|
files: ['**/*.ts'],
|
||||||
patterns: [
|
patterns: [{
|
||||||
{
|
match: /$/,
|
||||||
// Empty replacement needed so that replaceWithPath gets triggered...
|
replacement: function(_, relativePath) {
|
||||||
match: /$/g,
|
var content = ""; //we're matching an empty line
|
||||||
replacement: ""
|
if (!relativePath.endsWith('.d.ts')) {
|
||||||
|
content += '\r\nexport var __esModule = true;\n';
|
||||||
|
}
|
||||||
|
return content;
|
||||||
}
|
}
|
||||||
],
|
}]
|
||||||
replaceWithPath: function(path, content) {
|
|
||||||
if (!path.endsWith('.d.ts')) {
|
|
||||||
content += '\r\nexport var __esModule = true;\n';
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var typescriptTree = compileWithTypescript(traceurCompatibleTsModulesTree, {
|
var typescriptTree = compileWithTypescript(traceurCompatibleTsModulesTree, {
|
||||||
|
|
Loading…
Reference in New Issue