forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpm-react.js
More file actions
75 lines (66 loc) · 1.92 KB
/
npm-react.js
File metadata and controls
75 lines (66 loc) · 1.92 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
'use strict';
var fs = require('fs');
var grunt = require('grunt');
var src = 'packages/react/';
var dest = 'build/packages/react/';
var modSrc = 'build/modules/';
var lib = dest + 'lib/';
var dist = dest + 'dist/';
var distFiles = [
'react.js',
'react.min.js',
'react-with-addons.js',
'react-with-addons.min.js',
];
function buildRelease() {
// delete build/react-core for fresh start
if (grunt.file.exists(dest)) {
grunt.file.delete(dest);
}
// mkdir -p build/react-core/lib
grunt.file.mkdir(lib);
// Copy npm-react/**/* to build/npm-react
// and build/modules/**/* to build/react-core/lib
var mappings = [].concat(
grunt.file.expandMapping('**/*', dest, {cwd: src}),
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
);
mappings.forEach(function(mapping) {
var mappingSrc = mapping.src[0];
var mappingDest = mapping.dest;
if (grunt.file.isDir(mappingSrc)) {
grunt.file.mkdir(mappingDest);
} else {
grunt.file.copy(mappingSrc, mappingDest);
}
});
// Make built source available inside npm package
grunt.file.mkdir(dist);
distFiles.forEach(function(file) {
grunt.file.copy('build/' + file, dist + file);
});
// modify build/react-core/package.json to set version ##
var pkg = grunt.file.readJSON(dest + 'package.json');
pkg.version = grunt.config.data.pkg.version;
grunt.file.write(dest + 'package.json', JSON.stringify(pkg, null, 2));
}
function packRelease() {
var done = this.async();
var spawnCmd = {
cmd: 'npm',
args: ['pack', 'packages/react'],
opts: {
cwd: 'build/',
},
};
grunt.util.spawn(spawnCmd, function() {
var buildSrc = 'build/react-' + grunt.config.data.pkg.version + '.tgz';
var buildDest = 'build/packages/react.tgz';
fs.rename(buildSrc, buildDest, done);
});
}
module.exports = {
buildRelease: buildRelease,
packRelease: packRelease,
};