diff --git a/templates/yeoman/src/CreateGenerator.ts b/templates/yeoman/src/CreateGenerator.ts index 1a33673..df2bd62 100644 --- a/templates/yeoman/src/CreateGenerator.ts +++ b/templates/yeoman/src/CreateGenerator.ts @@ -1,10 +1,8 @@ -import * as yeoman from 'yeoman-generator'; import * as glob from 'glob'; import * as gitignore from 'gitignore-parser'; import * as fs from 'fs'; import * as path from 'path'; import * as _ from 'lodash'; -import * as diff from 'diff'; import * as mkdirp from 'mkdirp'; import * as rimraf from 'rimraf'; @@ -33,63 +31,18 @@ function listFilesExcludingGitignored(root: string): string[] { .filter(fn => gitignoreEvaluator.accepts(fn)); } -function writeCommonFiles(outDir: string) { - let filesByTemplate = _.mapValues(templates, listFilesExcludingGitignored); - let commonFiles = _.intersection.apply(_, _.values(filesByTemplate)); - - commonFiles.forEach(fn => { - let templateRoots = _.values(templates); - let origContent = fs.readFileSync(path.join(templateRoots[0], fn)); - - if (isTextFile(fn)) { - // For text files, we copy the portion that's common to all the templates - let commonText = origContent.toString('utf8'); - templateRoots.slice(1).forEach(otherTemplateRoot => { - let otherTemplateContent = fs.readFileSync(path.join(otherTemplateRoot, fn), 'utf8'); - commonText = diff.diffLines(commonText, otherTemplateContent) - .filter(c => !(c.added || c.removed)) - .map(c => c.value) - .join(''); - }); - - writeFileEnsuringDirExists(outDir, fn, commonText); - } else { - // For binary (or maybe-binary) files, we only consider them common if they are identical across all templates - let isIdenticalEverywhere = !templateRoots.slice(1).some(otherTemplateRoot => { - return !fs.readFileSync(path.join(otherTemplateRoot, fn)).equals(origContent); - }); - if (isIdenticalEverywhere) { - writeFileEnsuringDirExists(outDir, fn, origContent); - } - } - }); -} - -function writeDiffsForTemplate(sourceRoot: string, destRoot: string, commonRoot: string) { +function writeTemplate(sourceRoot: string, destRoot: string) { listFilesExcludingGitignored(sourceRoot).forEach(fn => { - const commonFn = path.join(commonRoot, fn); - const sourceContent = fs.readFileSync(path.join(sourceRoot, fn)); - - if (!fs.existsSync(commonFn)) { - // This file is unique to this template - just copy as-is - writeFileEnsuringDirExists(destRoot, fn, sourceContent); - } else { - let commonText = fs.readFileSync(commonFn, 'utf8'); - let sourceText = sourceContent.toString('utf8'); - if (commonText !== sourceText) { - // Write a diff vs the common version of this file - let fileDiff = diff.createPatch(fn, commonText, sourceText, null, null); - writeFileEnsuringDirExists(destRoot, fn + '.patch', fileDiff); - } - } - }); + const sourceContent = fs.readFileSync(path.join(sourceRoot, fn)); + writeFileEnsuringDirExists(destRoot, fn, sourceContent); + }); } const outputRoot = './generator-aspnet-spa'; const commonRoot = path.join(outputRoot, 'templates/common'); rimraf.sync(outputRoot); -writeCommonFiles(commonRoot); _.forEach(templates, (templateRootDir, templateName) => { - writeDiffsForTemplate(templateRootDir, path.join(outputRoot, 'templates', templateName), commonRoot); + const outputDir = path.join(outputRoot, 'templates', templateName); + writeTemplate(templateRootDir, outputDir); }); diff --git a/templates/yeoman/tsd.json b/templates/yeoman/tsd.json index ece762e..a2db2d2 100644 --- a/templates/yeoman/tsd.json +++ b/templates/yeoman/tsd.json @@ -20,9 +20,6 @@ "lodash/lodash.d.ts": { "commit": "544a35a10866b32afda9c7f029c0764558563f4f" }, - "diff/diff.d.ts": { - "commit": "544a35a10866b32afda9c7f029c0764558563f4f" - }, "mkdirp/mkdirp.d.ts": { "commit": "544a35a10866b32afda9c7f029c0764558563f4f" }, diff --git a/templates/yeoman/typings/diff/diff.d.ts b/templates/yeoman/typings/diff/diff.d.ts deleted file mode 100644 index b1f9473..0000000 --- a/templates/yeoman/typings/diff/diff.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -// Type definitions for diff -// Project: https://github.com/kpdecker/jsdiff -// Definitions by: vvakame -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare namespace JsDiff { - interface IDiffResult { - value: string; - count?: number; - added?: boolean; - removed?: boolean; - } - - interface IBestPath { - newPos: number; - componenets: IDiffResult[]; - } - - class Diff { - ignoreWhitespace:boolean; - - constructor(ignoreWhitespace?:boolean); - - diff(oldString:string, newString:string):IDiffResult[]; - - pushComponent(components:IDiffResult[], value:string, added:boolean, removed:boolean):void; - - extractCommon(basePath:IBestPath, newString:string, oldString:string, diagonalPath:number):number; - - equals(left:string, right:string):boolean; - - join(left:string, right:string):string; - - tokenize(value:string):any; // return types are string or string[] - } - - function diffChars(oldStr:string, newStr:string):IDiffResult[]; - - function diffWords(oldStr:string, newStr:string):IDiffResult[]; - - function diffWordsWithSpace(oldStr:string, newStr:string):IDiffResult[]; - - function diffJson(oldObj: Object, newObj: Object): IDiffResult[]; - - function diffLines(oldStr:string, newStr:string):IDiffResult[]; - - function diffCss(oldStr:string, newStr:string):IDiffResult[]; - - function createPatch(fileName:string, oldStr:string, newStr:string, oldHeader:string, newHeader:string):string; - - function applyPatch(oldStr:string, uniDiff:string):string; - - function convertChangesToXML(changes:IDiffResult[]):string; - - function convertChangesToDMP(changes:IDiffResult[]):{0: number; 1:string;}[]; -} - -declare module "diff" { - export = JsDiff; -} diff --git a/templates/yeoman/typings/tsd.d.ts b/templates/yeoman/typings/tsd.d.ts index 16d3f0a..c099e00 100644 --- a/templates/yeoman/typings/tsd.d.ts +++ b/templates/yeoman/typings/tsd.d.ts @@ -3,6 +3,5 @@ /// /// /// -/// /// ///