forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpm-react-addons.js
More file actions
133 lines (117 loc) · 3.07 KB
/
npm-react-addons.js
File metadata and controls
133 lines (117 loc) · 3.07 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';
var fs = require('fs');
var grunt = require('grunt');
var path = require('path');
var addons = {
CSSTransitionGroup: {
module: 'ReactCSSTransitionGroup',
name: 'css-transition-group',
docs: 'animation',
},
LinkedStateMixin: {
module: 'LinkedStateMixin',
name: 'linked-state-mixin',
docs: 'two-way-binding-helpers',
},
Perf: {
module: 'ReactDefaultPerf',
name: 'perf',
docs: 'perf',
},
PureRenderMixin: {
module: 'ReactComponentWithPureRenderMixin',
name: 'pure-render-mixin',
docs: 'pure-render-mixin',
},
TestUtils: {
module: 'ReactTestUtils',
name: 'test-utils',
docs: 'test-utils',
},
TransitionGroup: {
module: 'ReactTransitionGroup',
name: 'transition-group',
docs: 'animation',
},
createFragment: {
module: 'ReactFragment',
method: 'create',
name: 'create-fragment',
docs: 'create-fragment',
},
shallowCompare: {
module: 'shallowCompare',
name: 'shallow-compare',
},
updates: {
module: 'update',
name: 'update',
docs: 'update',
},
};
function generateSource(info) {
var pieces = [
"module.exports = require('react/lib/",
info.module,
"')",
];
if (info.method) {
pieces.push('.', info.method);
}
pieces.push(';');
return pieces.join('');
}
function buildReleases() {
var pkgTemplate = grunt.file.readJSON('./packages/react-addons/package.json');
Object.keys(addons).map(function(k) {
var info = addons[k];
var pkgName = 'react-addons-' + info.name;
var destDir = 'build/packages/' + pkgName;
var destLicense = path.join(destDir, 'LICENSE');
var destPatents = path.join(destDir, 'PATENTS');
var pkgData = Object.assign({}, pkgTemplate);
pkgData.name = pkgName;
grunt.file.mkdir(destDir);
var link = info.docs ? info.docs : 'addons';
link = `https://facebook.github.io/react/docs/${link}.html`;
fs.writeFileSync(path.join(destDir, 'index.js'), generateSource(info));
fs.writeFileSync(path.join(destDir, 'package.json'), JSON.stringify(pkgData, null, 2));
grunt.file.copy('LICENSE', destLicense);
grunt.file.copy('PATENTS', destPatents);
fs.writeFileSync(
path.join(destDir, 'README.md'),
`
# ${pkgName}
This package provides the React ${k} add-on.
See <${link}> for more information.`.slice(1)
);
});
}
function packReleases() {
var done = this.async();
var count = 0;
var addonKeys = Object.keys(addons);
addonKeys.forEach(function(k) {
var info = addons[k];
var pkgName = 'react-addons-' + info.name;
var pkgDir = 'build/packages/' + pkgName;
var spawnCmd = {
cmd: 'npm',
args: ['pack', pkgDir],
};
grunt.util.spawn(spawnCmd, function() {
var buildSrc = pkgName + '-' + grunt.config.data.pkg.version + '.tgz';
var buildDest = 'build/packages/' + pkgName + '.tgz';
fs.rename(buildSrc, buildDest, maybeDone);
});
});
function maybeDone() {
if (++count === addonKeys.length) {
done();
}
}
}
module.exports = {
buildReleases: buildReleases,
packReleases: packReleases,
};