Skip to content

Commit fc705e8

Browse files
Simplify by removing diff feature. Now just writes each template as an independent copy.
1 parent 1830c20 commit fc705e8

4 files changed

Lines changed: 6 additions & 117 deletions

File tree

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import * as yeoman from 'yeoman-generator';
21
import * as glob from 'glob';
32
import * as gitignore from 'gitignore-parser';
43
import * as fs from 'fs';
54
import * as path from 'path';
65
import * as _ from 'lodash';
7-
import * as diff from 'diff';
86
import * as mkdirp from 'mkdirp';
97
import * as rimraf from 'rimraf';
108

@@ -33,63 +31,18 @@ function listFilesExcludingGitignored(root: string): string[] {
3331
.filter(fn => gitignoreEvaluator.accepts(fn));
3432
}
3533

36-
function writeCommonFiles(outDir: string) {
37-
let filesByTemplate = _.mapValues(templates, listFilesExcludingGitignored);
38-
let commonFiles = _.intersection.apply(_, _.values(filesByTemplate));
39-
40-
commonFiles.forEach(fn => {
41-
let templateRoots = _.values(templates);
42-
let origContent = fs.readFileSync(path.join(templateRoots[0], fn));
43-
44-
if (isTextFile(fn)) {
45-
// For text files, we copy the portion that's common to all the templates
46-
let commonText = origContent.toString('utf8');
47-
templateRoots.slice(1).forEach(otherTemplateRoot => {
48-
let otherTemplateContent = fs.readFileSync(path.join(otherTemplateRoot, fn), 'utf8');
49-
commonText = diff.diffLines(commonText, otherTemplateContent)
50-
.filter(c => !(c.added || c.removed))
51-
.map(c => c.value)
52-
.join('');
53-
});
54-
55-
writeFileEnsuringDirExists(outDir, fn, commonText);
56-
} else {
57-
// For binary (or maybe-binary) files, we only consider them common if they are identical across all templates
58-
let isIdenticalEverywhere = !templateRoots.slice(1).some(otherTemplateRoot => {
59-
return !fs.readFileSync(path.join(otherTemplateRoot, fn)).equals(origContent);
60-
});
61-
if (isIdenticalEverywhere) {
62-
writeFileEnsuringDirExists(outDir, fn, origContent);
63-
}
64-
}
65-
});
66-
}
67-
68-
function writeDiffsForTemplate(sourceRoot: string, destRoot: string, commonRoot: string) {
34+
function writeTemplate(sourceRoot: string, destRoot: string) {
6935
listFilesExcludingGitignored(sourceRoot).forEach(fn => {
70-
const commonFn = path.join(commonRoot, fn);
71-
const sourceContent = fs.readFileSync(path.join(sourceRoot, fn));
72-
73-
if (!fs.existsSync(commonFn)) {
74-
// This file is unique to this template - just copy as-is
75-
writeFileEnsuringDirExists(destRoot, fn, sourceContent);
76-
} else {
77-
let commonText = fs.readFileSync(commonFn, 'utf8');
78-
let sourceText = sourceContent.toString('utf8');
79-
if (commonText !== sourceText) {
80-
// Write a diff vs the common version of this file
81-
let fileDiff = diff.createPatch(fn, commonText, sourceText, null, null);
82-
writeFileEnsuringDirExists(destRoot, fn + '.patch', fileDiff);
83-
}
84-
}
85-
});
36+
const sourceContent = fs.readFileSync(path.join(sourceRoot, fn));
37+
writeFileEnsuringDirExists(destRoot, fn, sourceContent);
38+
});
8639
}
8740

8841
const outputRoot = './generator-aspnet-spa';
8942
const commonRoot = path.join(outputRoot, 'templates/common');
9043
rimraf.sync(outputRoot);
91-
writeCommonFiles(commonRoot);
9244

9345
_.forEach(templates, (templateRootDir, templateName) => {
94-
writeDiffsForTemplate(templateRootDir, path.join(outputRoot, 'templates', templateName), commonRoot);
46+
const outputDir = path.join(outputRoot, 'templates', templateName);
47+
writeTemplate(templateRootDir, outputDir);
9548
});

templates/yeoman/tsd.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
"lodash/lodash.d.ts": {
2121
"commit": "544a35a10866b32afda9c7f029c0764558563f4f"
2222
},
23-
"diff/diff.d.ts": {
24-
"commit": "544a35a10866b32afda9c7f029c0764558563f4f"
25-
},
2623
"mkdirp/mkdirp.d.ts": {
2724
"commit": "544a35a10866b32afda9c7f029c0764558563f4f"
2825
},

templates/yeoman/typings/diff/diff.d.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

templates/yeoman/typings/tsd.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
/// <reference path="glob/glob.d.ts" />
44
/// <reference path="minimatch/minimatch.d.ts" />
55
/// <reference path="lodash/lodash.d.ts" />
6-
/// <reference path="diff/diff.d.ts" />
76
/// <reference path="mkdirp/mkdirp.d.ts" />
87
/// <reference path="rimraf/rimraf.d.ts" />

0 commit comments

Comments
 (0)