Skip to content

Commit 10fea13

Browse files
authored
feat: update generator-td to latest deps (#768)
1 parent 25081e3 commit 10fea13

File tree

12 files changed

+76
-120
lines changed

12 files changed

+76
-120
lines changed

.changeset/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"fixed": [],
66
"linked": [],
77
"access": "public",
8-
"baseBranch": "main",
8+
"baseBranch": "master",
99
"updateInternalDependencies": "patch",
1010
"ignore": []
1111
}

.changeset/new-panthers-sparkle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'generator-fluxible': major
3+
---
4+
5+
feat: upgrade to latest yeoman packages

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ node_modules
88
.jshintrc
99
*.sh
1010
examples/*/build
11+
temp/

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
"react-dom": "^17.0.2",
4141
"react-test-renderer": "^17.0.2",
4242
"shelljs": "^0.8.0",
43-
"yargs": "^17.1.0"
43+
"yargs": "^17.1.0",
44+
"yeoman-assert": "^3.1.1",
45+
"yeoman-test": "^6.3.0"
4446
},
4547
"pre-commit": [
4648
"dev:lint",

packages/generator-fluxible/README.md

+1-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ npm install -g generator-fluxible
1717
Finally, initiate the generator:
1818

1919
```bash
20+
cd new-project
2021
yo fluxible
2122
```
2223

@@ -28,18 +29,3 @@ the server will be reloaded and the bundle will be rebuilt.
2829

2930
For other environments, make sure your application is built using
3031
`npm run build` and then run `npm start`.
31-
32-
## Debugging
33-
34-
Fluxible uses [debug](https://www.npmjs.com/package/debug) to expose debugging
35-
information on the server and client.
36-
37-
### Server
38-
39-
Start the application with the `DEBUG` environment variable: `DEBUG=* grunt`.
40-
41-
### Client
42-
43-
`fluxibleDebug` is exposed to the `window` object to manage debugging. You can
44-
enable it via the browser console: `fluxibleDebug.enable('*');` then refresh
45-
the page. To disable, type the following: `fluxibleDebug.disable();`.

packages/generator-fluxible/app/index.js

+27-56
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,27 @@
44
*/
55

66
'use strict';
7-
var yeoman = require('yeoman-generator');
8-
var chalk = require('chalk');
9-
var yosay = require('yosay');
10-
var str = require('underscore.string');
117

12-
module.exports = yeoman.generators.Base.extend({
13-
initializing: function () {
14-
this.pkg = require('../package.json');
15-
},
8+
const Generator = require('yeoman-generator');
9+
const chalk = require('chalk');
10+
const yosay = require('yosay');
11+
const str = require('underscore.string');
1612

17-
prompting: function () {
18-
var done = this.async();
13+
module.exports = class extends Generator {
14+
constructor(args, opts) {
15+
super(args, opts);
16+
this.pkg = require('../package.json');
17+
}
1918

19+
async prompting() {
2020
this.log(
2121
yosay(
2222
'Welcome to the riveting ' +
2323
chalk.red('Fluxible') +
2424
' generator!'
2525
)
2626
);
27-
28-
var prompts = [
27+
this.answers = await this.prompt([
2928
{
3029
type: 'input',
3130
name: 'name',
@@ -35,48 +34,20 @@ module.exports = yeoman.generators.Base.extend({
3534
return !!input;
3635
},
3736
},
38-
];
39-
40-
this.prompt(
41-
prompts,
42-
function (props) {
43-
this.displayName = props.name;
44-
this.name = str.slugify(props.name);
45-
this.buildSystem = str.slugify(props.buildSystem);
46-
done();
47-
}.bind(this)
37+
]);
38+
39+
this.displayName = this.answers.name;
40+
this.name = str.slugify(this.answers.name);
41+
this.buildSystem = str.slugify(this.answers.buildSystem);
42+
}
43+
44+
writing() {
45+
this.fs.copyTpl(
46+
this.templatePath(),
47+
this.destinationRoot(),
48+
this,
49+
null,
50+
{ globOptions: { dot: true } }
4851
);
49-
},
50-
51-
writing: {
52-
config: function () {
53-
this.template('babel.config.js', 'babel.config.js', this.context);
54-
// .gitignore is renamed by npm to .npmignore, so use underscore
55-
this.template('_gitignore', '.gitignore', this.context);
56-
this.template('package.json', 'package.json', this.context);
57-
},
58-
59-
projectfiles: function () {
60-
this.template('app.js', 'app.js', this.context);
61-
this.template('client.js', 'client.js', this.context);
62-
this.template('server.js', 'server.js', this.context);
63-
this.template(
64-
'webpack.config.js',
65-
'webpack.config.js',
66-
this.context
67-
);
68-
this.directory('actions', 'actions', this.context);
69-
this.directory('components', 'components', this.context);
70-
this.directory('configs', 'configs', this.context);
71-
this.directory('stores', 'stores', this.context);
72-
},
73-
},
74-
75-
install: function () {
76-
this.installDependencies({
77-
npm: true,
78-
bower: false,
79-
skipInstall: this.options['skip-install'],
80-
});
81-
},
82-
});
52+
}
53+
};

packages/generator-fluxible/app/templates/_gitignore

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
/*global document, window */
22

33
import ReactDOM from 'react-dom';
4-
import debug from 'debug';
54
import { createElementWithContext } from 'fluxible-addons-react';
65
import app from './app';
76

8-
const debugClient = debug('<%= name %>');
97
const dehydratedState = window.App; // Sent from the server
108

119
window.React = ReactDOM; // For chrome dev tool support
1210

13-
// expose debug object to browser, so that it can be enabled/disabled from browser:
14-
// https://github.com/visionmedia/debug#browser-support
15-
window.fluxibleDebug = debug;
16-
17-
debugClient('rehydrating app');
18-
1911
// pass in the dehydrated server state from server.js
2012
app.rehydrate(dehydratedState, (err, context) => {
2113
if (err) {
@@ -24,8 +16,5 @@ app.rehydrate(dehydratedState, (err, context) => {
2416
window.context = context;
2517
const mountNode = document.getElementById('app');
2618

27-
debugClient('React Rendering');
28-
ReactDOM.hydrate(createElementWithContext(context), mountNode, () =>
29-
debugClient('React Rendered')
30-
);
19+
ReactDOM.hydrate(createElementWithContext(context), mountNode);
3120
});

packages/generator-fluxible/app/templates/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"dependencies": {
1414
"body-parser": "^1.19.0",
1515
"compression": "^1.7.4",
16-
"debug": "^4.3.1",
1716
"express": "^4.17.1",
1817
"fluxible": "^1.0.0",
1918
"fluxible-addons-react": "^1.0.0",

packages/generator-fluxible/app/templates/server.js

-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ import bodyParser from 'body-parser';
1111
import path from 'path';
1212
import serialize from 'serialize-javascript';
1313
import { navigateAction } from 'fluxible-router';
14-
import debugLib from 'debug';
1514
import React from 'react';
1615
import ReactDOMServer from 'react-dom/server';
1716
import app from './app';
1817
import HtmlComponent from './components/Html';
1918
import { createElementWithContext } from 'fluxible-addons-react';
2019
const env = process.env.NODE_ENV;
2120

22-
const debug = debugLib('<%= name %>');
23-
2421
const server = express();
2522
server.use('/public', express.static(path.join(__dirname, 'public')));
2623
server.use(compression());
@@ -29,7 +26,6 @@ server.use(bodyParser.json());
2926
server.use((req, res, next) => {
3027
const context = app.createContext();
3128

32-
debug('Executing navigate action');
3329
context.getActionContext().executeAction(
3430
navigateAction,
3531
{
@@ -46,11 +42,9 @@ server.use((req, res, next) => {
4642
return;
4743
}
4844

49-
debug('Exposing context state');
5045
const exposed =
5146
'window.App=' + serialize(app.dehydrate(context)) + ';';
5247

53-
debug('Rendering Application component into html');
5448
const markup = ReactDOMServer.renderToString(
5549
createElementWithContext(context)
5650
);
@@ -62,7 +56,6 @@ server.use((req, res, next) => {
6256
});
6357
const html = ReactDOMServer.renderToStaticMarkup(htmlElement);
6458

65-
debug('Sending markup');
6659
res.type('html');
6760
res.write('<!DOCTYPE html>' + html);
6861
res.end();

packages/generator-fluxible/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
"fluxible"
2828
],
2929
"dependencies": {
30-
"chalk": "^1.0.0",
30+
"chalk": "^4.0.0",
3131
"prop-types": "^15.7.2",
3232
"underscore.string": "^3.0.2",
33-
"yeoman-generator": "^0.20.1",
34-
"yo": ">=1.0.0",
33+
"yeoman-generator": "^5.7.0",
34+
"yo": "^4.0.0",
3535
"yosay": "^2.0.2"
3636
},
3737
"peerDependencies": {
38-
"yo": ">=1.0.0"
38+
"yo": "^4.0.0"
3939
}
4040
}

packages/generator-fluxible/tests/unit/test-app.test.js

+33-20
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,43 @@
22
* Copyright 2015, Yahoo! Inc.
33
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
44
*/
5-
/*globals describe,before,it*/
65

7-
var path = require('path');
8-
var assert = require('yeoman-generator').assert;
9-
var helpers = require('yeoman-generator').test;
10-
var os = require('os');
6+
const path = require('path');
7+
const helpers = require('yeoman-test');
8+
const assert = require('yeoman-assert');
9+
const TMP_DIR = process.env.TMP_DIR || __dirname;
10+
const tempDir = path.join(TMP_DIR, 'temp');
1111

1212
describe('generator-fluxible', function () {
13-
describe('app', function () {
14-
beforeAll(function (done) {
15-
helpers
16-
.run(path.join(__dirname, '../../app'))
17-
.inDir(path.join(os.tmpdir(), './temp-test'))
18-
.withOptions({ 'skip-install': true })
19-
.on('end', done);
20-
});
13+
beforeAll(function (done) {
14+
helpers.testDirectory(tempDir, (err) => {
15+
if (err) {
16+
return done(err);
17+
}
2118

22-
it('creates files', function () {
23-
assert.file([
24-
'package.json',
25-
'babel.config.js',
26-
'app.js',
27-
'components/Application.js',
28-
]);
19+
this.lib = helpers.createGenerator(
20+
'fluxible',
21+
[[require('../../app'), 'fluxible']],
22+
'fluxy',
23+
{ 'skip-install': true }
24+
);
25+
done();
2926
});
3027
});
28+
29+
it('creates files', function () {
30+
return helpers
31+
.run(path.join(__dirname, '../../app'))
32+
.withOptions(test.options)
33+
.withArguments(['fluxy'])
34+
.withPrompts(Object.assign({}, test.prompts, { name: true }))
35+
.then(function () {
36+
assert.file([
37+
'package.json',
38+
'babel.config.js',
39+
'app.js',
40+
'components/Application.js',
41+
]);
42+
});
43+
});
3144
});

0 commit comments

Comments
 (0)