1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/**
* This script is for internal `react-boilerplate`'s usage. The only purpose of generating all of these templates is
* to be able to lint them and detect critical errors. Every generated component's name has to start with
* 'RbGenerated' so it can be easily excluded from the test coverage reports.
*/
const nodePlop = require('node-plop');
const path = require('path');
const chalk = require('chalk');
const rimraf = require('rimraf');
const xmark = require('./helpers/xmark');
process.chdir(path.join(__dirname, '../generators'));
const prettyStringify = data => JSON.stringify(data, null, 2);
const checkForErrors = result => {
if (Array.isArray(result.failures) && result.failures.length > 0) {
throw result.failures;
}
};
const reportErrorsFor = title => err => {
// TODO Replace with our own helpers/log that is guaranteed to be blocking?
xmark(() =>
console.error(
chalk.red(` ERROR generating '${title}': `),
prettyStringify(err),
),
);
process.exit(1);
};
// Generated tests are designed to fail, which would in turn fail CI builds
const removeTestsDirFrom = relativePath => () =>
rimraf.sync(path.join(__dirname, '/../../app/', relativePath, '/tests'));
const plop = nodePlop('./index.js');
const componentGen = plop.getGenerator('component');
componentGen
.runActions({
name: 'RbGeneratedComponentEsclass',
type: 'React.Component',
wantMessages: true,
wantLoadable: true,
})
.then(checkForErrors)
.then(removeTestsDirFrom('components/RbGeneratedComponentEsclass'))
.catch(reportErrorsFor('component/React.Component'));
componentGen
.runActions({
name: 'RbGeneratedComponentEsclasspure',
type: 'React.PureComponent',
wantMessages: true,
wantLoadable: true,
})
.then(checkForErrors)
.then(removeTestsDirFrom('components/RbGeneratedComponentEsclasspure'))
.catch(reportErrorsFor('component/React.PureComponent'));
componentGen
.runActions({
name: 'RbGeneratedComponentStatelessfunction',
type: 'Stateless Function',
wantMessages: true,
wantLoadable: true,
})
.then(checkForErrors)
.then(removeTestsDirFrom('components/RbGeneratedComponentStatelessfunction'))
.catch(reportErrorsFor('component/Stateless Function'));
const containerGen = plop.getGenerator('container');
containerGen
.runActions({
name: 'RbGeneratedContainerPureComponent',
type: 'React.PureComponent',
wantHeaders: true,
wantActionsAndReducer: true,
wantSagas: true,
wantMessages: true,
wantLoadable: true,
})
.then(checkForErrors)
.then(removeTestsDirFrom('containers/RbGeneratedContainerPureComponent'))
.catch(reportErrorsFor('container/React.PureComponent'));
containerGen
.runActions({
name: 'RbGeneratedContainerComponent',
type: 'React.Component',
wantHeaders: true,
wantActionsAndReducer: true,
wantSagas: true,
wantMessages: true,
wantLoadable: true,
})
.then(checkForErrors)
.then(removeTestsDirFrom('containers/RbGeneratedContainerComponent'))
.catch(reportErrorsFor('container/React.Component'));
containerGen
.runActions({
name: 'RbGeneratedContainerStateless',
type: 'Stateless Function',
wantHeaders: true,
wantActionsAndReducer: true,
wantSagas: true,
wantMessages: true,
wantLoadable: true,
})
.then(checkForErrors)
.then(removeTestsDirFrom('containers/RbGeneratedContainerStateless'))
.catch(reportErrorsFor('container/Stateless'));
const languageGen = plop.getGenerator('language');
languageGen.runActions({ language: 'fr' }).catch(reportErrorsFor('language'));
|