Skip to content

Commit b35aa2d

Browse files
committed
Tune logic and fix paths
1 parent 69e3464 commit b35aa2d

File tree

7 files changed

+53
-49
lines changed

7 files changed

+53
-49
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @nomcopter/generator-typescript-react
1+
# generator-typescript-react
22
[![CircleCI](SHIELDS IO LINK)](CIRCLE LINK)
33
[![npm](SHIELDS IO LINK)](NPM PACKAGE LINK)
44

generators/app/templates/demo/_index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
33
import { AppContainer } from 'react-hot-loader';
4-
import { Demo } from './_Demo';
4+
import '../styles/index.less';
5+
6+
import { Demo } from './Demo';
7+
import './demo.less';
58

69
const APP_ELEMENT = document.getElementById('app')!;
710
const render = (Component: React.ComponentClass<any>) => {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { expect } from 'chai';
22

33
describe('<%= humanReadableName %>', () => {
4-
4+
it('should be sane', () => {
5+
expect(true).to.equal(true);
6+
})
57
});

generators/app/templates/webpack/_base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
22
import * as webpack from 'webpack';
3-
import { CONSTANTS } from './_constants';
3+
import { CONSTANTS } from './constants';
44

55
// tslint:disable-next-line no-var-requires
66
const VENDOR_LIBS = Object.keys(require('../package.json').dependencies);

generators/app/templates/webpack/_bundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as webpack from 'webpack';
2-
import config from './_base';
2+
import config from './base';
33

44
const bundleConfig = {
55
...config,

generators/app/templates/webpack/_hot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as webpack from 'webpack';
2-
import config from './_base';
3-
import { CONSTANTS } from './_constants';
2+
import config from './base';
3+
import { CONSTANTS } from './constants';
44

55
const baseEntry = config.entry as webpack.Entry;
66
const entry = {

src/app/index.ts

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,22 @@ import * as _ from 'lodash';
22
import * as path from 'path';
33
import * as Base from 'yeoman-generator';
44

5-
export default class GeneratorTypescriptReact extends Base {
6-
private readonly destinationName: string;
7-
private readonly copyWithoutTemplating: (templateNames: string[], directory?: string) => void;
8-
private readonly copyWithTemplating: (templateData: object, templateNames: string[], directory?: string) => void;
9-
5+
class GeneratorTypescriptReact extends Base {
106
private humanReadableName: string;
117
private kebabCaseName: string;
128

13-
constructor() {
14-
super(...arguments);
15-
16-
this.destinationName = path.basename(this.destinationRoot());
17-
18-
this.copyWithTemplating = (templateData, templateNames, directory = '.') => {
19-
templateNames.forEach(filename => {
20-
this.fs.copyTpl(
21-
this.templatePath(path.join(directory, '_' + filename)),
22-
this.destinationPath(path.join(directory, filename)),
23-
templateData,
24-
);
25-
});
26-
};
27-
28-
this.copyWithoutTemplating = (templateNames, directory = '.') => {
29-
templateNames.forEach(filename => {
30-
this.fs.copy(
31-
this.templatePath(path.join(directory, '_' + filename)),
32-
this.destinationPath(path.join(directory, filename)),
33-
);
34-
});
35-
};
36-
}
37-
389
prompting() {
10+
const destinationName = path.basename(this.destinationRoot());
3911
return this.prompt([{
4012
type: 'input',
4113
name: 'kebab',
4214
message: 'What is the Package Name for this app?',
43-
default: _.kebabCase(this.destinationName),
15+
default: _.kebabCase(destinationName),
4416
}, {
4517
type: 'input',
4618
name: 'human',
4719
message: 'What is the Human-Readable Name for this app?',
48-
default: _.startCase(this.destinationName),
20+
default: _.startCase(destinationName),
4921
}])
5022
.then(answers => {
5123
this.kebabCaseName = answers.kebab;
@@ -59,27 +31,54 @@ export default class GeneratorTypescriptReact extends Base {
5931
humanReadableName: this.humanReadableName,
6032
};
6133

62-
this.copyWithoutTemplating([
34+
this._copyWithoutTemplating([
6335
'.editorconfig', '.npmignore', 'circle.yml', 'LICENSE',
6436
'tsconfig.json', 'tsconfig-build.json', 'tslint.json',
6537
]);
66-
this.copyWithTemplating(allTemplateData, ['.gitignore', 'package.json', 'README.md']);
38+
this._copyWithTemplating(allTemplateData, ['.gitignore', 'package.json', 'README.md']);
6739

68-
this.copyWithoutTemplating(['demo.less', 'index.tsx'], 'demo');
69-
this.copyWithTemplating(allTemplateData, ['Demo.tsx'], 'demo');
40+
this._copyWithoutTemplating(['demo.less', 'index.tsx'], 'demo');
41+
this._copyWithTemplating(allTemplateData, ['Demo.tsx'], 'demo');
7042

71-
this.copyWithTemplating(allTemplateData, ['index.ts'], 'src');
43+
this._copyWithTemplating(allTemplateData, ['index.ts'], 'src');
7244

73-
this.copyWithoutTemplating(['index.less'], 'styles');
45+
this._copyWithoutTemplating(['index.less'], 'styles');
7446

75-
this.copyWithoutTemplating(['mocha.opts', 'registerTsNode.js'], 'test');
76-
this.copyWithTemplating(allTemplateData, ['spec.ts'], 'test');
47+
this._copyWithoutTemplating(['mocha.opts', 'registerTsNode.js'], 'test');
48+
this._copyWithTemplating(allTemplateData, ['spec.ts'], 'test');
7749

78-
this.copyWithoutTemplating(['base.ts', 'bundle.ts', 'constants.ts', 'hot.ts'], 'webpack');
79-
this.copyWithTemplating(allTemplateData, ['index-template.html'], 'webpack');
50+
this._copyWithoutTemplating(['base.ts', 'bundle.ts', 'constants.ts', 'hot.ts'], 'webpack');
51+
this._copyWithTemplating(allTemplateData, ['index-template.html'], 'webpack');
8052
}
8153

8254
install() {
8355
this.spawnCommandSync('yarn', ['install'], { cwd: this.destinationRoot() });
8456
}
57+
58+
end() {
59+
this.log();
60+
this.log('To start devving, use webpack-dev-server:');
61+
this.log(' yarn start');
62+
}
63+
64+
private _copyWithTemplating(templateData: object, templateNames: string[], directory: string = '.') {
65+
templateNames.forEach(filename => {
66+
this.fs.copyTpl(
67+
this.templatePath(path.join(directory, '_' + filename)),
68+
this.destinationPath(path.join(directory, filename)),
69+
templateData,
70+
);
71+
});
72+
}
73+
74+
private _copyWithoutTemplating(templateNames: string[], directory: string = '.') {
75+
templateNames.forEach(filename => {
76+
this.fs.copy(
77+
this.templatePath(path.join(directory, '_' + filename)),
78+
this.destinationPath(path.join(directory, filename)),
79+
);
80+
});
81+
}
8582
}
83+
84+
export = GeneratorTypescriptReact;

0 commit comments

Comments
 (0)