Selector: Inline Sizzle into the selector module
[jquery.git] / build / release / dist.js
blob577eb6404df087c2b2be268fa0f845dc25cc2db7
1 module.exports = function( Release, files, complete ) {
3         var
4                 fs = require( "fs" ),
5                 shell = require( "shelljs" ),
6                 pkg = require( Release.dir.repo + "/package.json" ),
7                 distRemote = Release.remote
9                         // For local and github dists
10                         .replace( /jquery(\.git|$)/, "jquery-dist$1" ),
12                 // These files are included with the distribution
13                 extras = [
14                         "src",
15                         "LICENSE.txt",
16                         "AUTHORS.txt",
17                         "package.json"
18                 ];
20         /**
21          * Clone the distribution repo
22          */
23         function clone() {
24                 Release.chdir( Release.dir.base );
25                 Release.dir.dist = Release.dir.base + "/dist";
27                 console.log( "Using distribution repo: ", distRemote );
28                 Release.exec( "git clone " + distRemote + " " + Release.dir.dist,
29                         "Error cloning repo." );
31                 // Distribution always works on master
32                 Release.chdir( Release.dir.dist );
33                 Release.exec( "git checkout master", "Error checking out branch." );
34                 console.log();
35         }
37         /**
38          * Generate bower file for jquery-dist
39          */
40         function generateBower() {
41                 return JSON.stringify( {
42                         name: pkg.name,
43                         main: pkg.main,
44                         license: "MIT",
45                         ignore: [
46                                 "package.json"
47                         ],
48                         keywords: pkg.keywords
49                 }, null, 2 );
50         }
52         /**
53          * Replace the version in the README
54          * @param {string} readme
55          */
56         function editReadme( readme ) {
57                 var rprev = new RegExp( Release.prevVersion, "g" );
58                 return readme.replace( rprev, Release.newVersion );
59         }
61         /**
62          * Copy necessary files over to the dist repo
63          */
64         function copy() {
66                 // Copy dist files
67                 var distFolder = Release.dir.dist + "/dist",
68                         readme = fs.readFileSync( Release.dir.dist + "/README.md", "utf8" ),
69                         rmIgnore = files
70                                 .concat( [
71                                         "README.md",
72                                         "node_modules"
73                                 ] )
74                                 .map( function( file ) {
75                                         return Release.dir.dist + "/" + file;
76                                 } );
78                 shell.config.globOptions = {
79                         ignore: rmIgnore
80                 };
82                 // Remove extraneous files before copy
83                 shell.rm( "-rf", Release.dir.dist + "/**/*" );
85                 shell.mkdir( "-p", distFolder );
86                 files.forEach( function( file ) {
87                         shell.cp( "-f", Release.dir.repo + "/" + file, distFolder );
88                 } );
90                 // Copy other files
91                 extras.forEach( function( file ) {
92                         shell.cp( "-rf", Release.dir.repo + "/" + file, Release.dir.dist );
93                 } );
95                 // Remove the wrapper from the dist repo
96                 shell.rm( "-f", Release.dir.dist + "/src/wrapper.js" );
98                 // Write generated bower file
99                 fs.writeFileSync( Release.dir.dist + "/bower.json", generateBower() );
101                 fs.writeFileSync( Release.dir.dist + "/README.md", editReadme( readmeĀ ) );
103                 console.log( "Files ready to add." );
104                 console.log( "Edit the dist README.md to include the latest blog post link." );
105         }
107         /**
108          * Add, commit, and tag the dist files
109          */
110         function commit() {
111                 console.log( "Adding files to dist..." );
112                 Release.exec( "git add -A", "Error adding files." );
113                 Release.exec(
114                         "git commit -m \"Release " + Release.newVersion + "\"",
115                         "Error committing files."
116                 );
117                 console.log();
119                 console.log( "Tagging release on dist..." );
120                 Release.exec( "git tag " + Release.newVersion,
121                         "Error tagging " + Release.newVersion + " on dist repo." );
122                 Release.tagTime = Release.exec( "git log -1 --format=\"%ad\"",
123                         "Error getting tag timestamp." ).trim();
124         }
126         /**
127          * Push files to dist repo
128          */
129         function push() {
130                 Release.chdir( Release.dir.dist );
132                 console.log( "Pushing release to dist repo..." );
133                 Release.exec( "git push " + distRemote + " master --tags",
134                         "Error pushing master and tags to git repo." );
136                 // Set repo for npm publish
137                 Release.dir.origRepo = Release.dir.repo;
138                 Release.dir.repo = Release.dir.dist;
139         }
141         Release.walk( [
142                 Release._section( "Copy files to distribution repo" ),
143                 clone,
144                 copy,
145                 Release.confirmReview,
147                 Release._section( "Add, commit, and tag files in distribution repo" ),
148                 commit,
149                 Release.confirmReview,
151                 Release._section( "Pushing files to distribution repo" ),
152                 push
153         ], complete );