2019-10-08 22:17:55 +00:00
|
|
|
|
"use strict";
|
|
|
|
|
|
2015-11-12 18:18:59 +00:00
|
|
|
|
module.exports = function( Release, files, complete ) {
|
2015-01-28 19:37:29 +00:00
|
|
|
|
|
2020-03-02 21:42:38 +00:00
|
|
|
|
const fs = require( "fs" ).promises;
|
|
|
|
|
const shell = require( "shelljs" );
|
|
|
|
|
const inquirer = require( "inquirer" );
|
|
|
|
|
const pkg = require( `${ Release.dir.repo }/package.json` );
|
|
|
|
|
const distRemote = Release.remote
|
|
|
|
|
|
|
|
|
|
// For local and github dists
|
|
|
|
|
.replace( /jquery(\.git|$)/, "jquery-dist$1" );
|
|
|
|
|
|
|
|
|
|
// These files are included with the distribution
|
|
|
|
|
const extras = [
|
|
|
|
|
"amd",
|
|
|
|
|
"src",
|
|
|
|
|
"LICENSE.txt",
|
|
|
|
|
"AUTHORS.txt",
|
|
|
|
|
"package.json"
|
|
|
|
|
];
|
2015-01-28 19:37:29 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clone the distribution repo
|
|
|
|
|
*/
|
|
|
|
|
function clone() {
|
|
|
|
|
Release.chdir( Release.dir.base );
|
2020-03-02 21:42:38 +00:00
|
|
|
|
Release.dir.dist = `${ Release.dir.base }/dist`;
|
2015-01-28 19:37:29 +00:00
|
|
|
|
|
|
|
|
|
console.log( "Using distribution repo: ", distRemote );
|
2020-03-02 21:42:38 +00:00
|
|
|
|
Release.exec( `git clone ${ distRemote } ${ Release.dir.dist }`,
|
2015-01-28 19:37:29 +00:00
|
|
|
|
"Error cloning repo." );
|
|
|
|
|
|
|
|
|
|
// Distribution always works on master
|
|
|
|
|
Release.chdir( Release.dir.dist );
|
|
|
|
|
Release.exec( "git checkout master", "Error checking out branch." );
|
|
|
|
|
console.log();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate bower file for jquery-dist
|
|
|
|
|
*/
|
|
|
|
|
function generateBower() {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
return JSON.stringify( {
|
2015-01-28 19:37:29 +00:00
|
|
|
|
name: pkg.name,
|
|
|
|
|
main: pkg.main,
|
|
|
|
|
license: "MIT",
|
|
|
|
|
ignore: [
|
|
|
|
|
"package.json"
|
|
|
|
|
],
|
|
|
|
|
keywords: pkg.keywords
|
2015-08-16 06:59:58 +00:00
|
|
|
|
}, null, 2 );
|
2015-01-28 19:37:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 16:30:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Replace the version in the README
|
|
|
|
|
* @param {string} readme
|
2020-03-02 21:42:38 +00:00
|
|
|
|
* @param {string} blogPostLink
|
2017-03-17 16:30:55 +00:00
|
|
|
|
*/
|
2020-03-02 21:42:38 +00:00
|
|
|
|
function editReadme( readme, blogPostLink ) {
|
|
|
|
|
return readme
|
|
|
|
|
.replace( /@VERSION/g, Release.newVersion )
|
|
|
|
|
.replace( /@BLOG_POST_LINK/g, blogPostLink );
|
2017-03-17 16:30:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 19:37:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Copy necessary files over to the dist repo
|
|
|
|
|
*/
|
2020-03-02 21:42:38 +00:00
|
|
|
|
async function copy() {
|
2015-01-28 19:37:29 +00:00
|
|
|
|
|
|
|
|
|
// Copy dist files
|
2020-03-02 21:42:38 +00:00
|
|
|
|
const distFolder = `${ Release.dir.dist }/dist`;
|
|
|
|
|
const readme = await fs.readFile(
|
|
|
|
|
`${ Release.dir.repo }/build/fixtures/README.md`, "utf8" );
|
|
|
|
|
const rmIgnore = [ ...files, "node_modules" ]
|
|
|
|
|
.map( file => `${ Release.dir.dist }/${ file }` );
|
2016-05-09 17:53:03 +00:00
|
|
|
|
|
|
|
|
|
shell.config.globOptions = {
|
|
|
|
|
ignore: rmIgnore
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-02 21:42:38 +00:00
|
|
|
|
const { blogPostLink } = await inquirer.prompt( [ {
|
|
|
|
|
type: "input",
|
|
|
|
|
name: "blogPostLink",
|
|
|
|
|
message: "Enter URL of the blog post announcing the jQuery release...\n"
|
|
|
|
|
} ] );
|
|
|
|
|
|
2016-05-09 17:53:03 +00:00
|
|
|
|
// Remove extraneous files before copy
|
2020-03-02 21:42:38 +00:00
|
|
|
|
shell.rm( "-rf", `${ Release.dir.dist }/**/*` );
|
2016-05-09 15:57:31 +00:00
|
|
|
|
|
2015-01-28 19:37:29 +00:00
|
|
|
|
shell.mkdir( "-p", distFolder );
|
2015-11-12 18:18:59 +00:00
|
|
|
|
files.forEach( function( file ) {
|
2020-03-02 21:42:38 +00:00
|
|
|
|
shell.cp( "-f", `${ Release.dir.repo }/${ file }`, distFolder );
|
2015-08-16 06:59:58 +00:00
|
|
|
|
} );
|
2015-01-28 19:37:29 +00:00
|
|
|
|
|
|
|
|
|
// Copy other files
|
2015-11-12 18:18:59 +00:00
|
|
|
|
extras.forEach( function( file ) {
|
2020-03-02 21:42:38 +00:00
|
|
|
|
shell.cp( "-rf", `${ Release.dir.repo }/${ file }`, Release.dir.dist );
|
2015-08-16 06:59:58 +00:00
|
|
|
|
} );
|
2015-01-28 19:37:29 +00:00
|
|
|
|
|
2020-03-02 21:42:38 +00:00
|
|
|
|
// Remove the wrapper & the ESLint config from the dist repo
|
|
|
|
|
shell.rm( "-f", `${ Release.dir.dist }/src/wrapper.js` );
|
|
|
|
|
shell.rm( "-f", `${ Release.dir.dist }/src/.eslintrc.json` );
|
2016-03-09 17:06:17 +00:00
|
|
|
|
|
2015-01-28 19:37:29 +00:00
|
|
|
|
// Write generated bower file
|
2020-03-02 21:42:38 +00:00
|
|
|
|
await fs.writeFile( `${ Release.dir.dist }/bower.json`, generateBower() );
|
2015-01-28 19:37:29 +00:00
|
|
|
|
|
2020-03-02 21:42:38 +00:00
|
|
|
|
await fs.writeFile( `${ Release.dir.dist }/README.md`,
|
|
|
|
|
editReadme( readme, blogPostLink ) );
|
2017-03-17 16:30:55 +00:00
|
|
|
|
|
|
|
|
|
console.log( "Files ready to add." );
|
|
|
|
|
}
|
2016-09-22 21:55:01 +00:00
|
|
|
|
|
2017-03-17 16:30:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Add, commit, and tag the dist files
|
|
|
|
|
*/
|
|
|
|
|
function commit() {
|
|
|
|
|
console.log( "Adding files to dist..." );
|
2016-09-22 21:55:01 +00:00
|
|
|
|
Release.exec( "git add -A", "Error adding files." );
|
2015-01-28 19:37:29 +00:00
|
|
|
|
Release.exec(
|
2020-03-02 21:42:38 +00:00
|
|
|
|
`git commit -m "Release ${ Release.newVersion }"`,
|
2015-12-04 06:49:23 +00:00
|
|
|
|
"Error committing files."
|
2015-01-28 19:37:29 +00:00
|
|
|
|
);
|
|
|
|
|
console.log();
|
|
|
|
|
|
|
|
|
|
console.log( "Tagging release on dist..." );
|
2020-03-02 21:42:38 +00:00
|
|
|
|
Release.exec( `git tag ${ Release.newVersion }`,
|
|
|
|
|
`Error tagging ${ Release.newVersion } on dist repo.` );
|
2016-09-22 21:55:01 +00:00
|
|
|
|
Release.tagTime = Release.exec( "git log -1 --format=\"%ad\"",
|
2015-01-28 19:37:29 +00:00
|
|
|
|
"Error getting tag timestamp." ).trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Push files to dist repo
|
|
|
|
|
*/
|
|
|
|
|
function push() {
|
|
|
|
|
Release.chdir( Release.dir.dist );
|
|
|
|
|
|
|
|
|
|
console.log( "Pushing release to dist repo..." );
|
2020-03-02 21:42:38 +00:00
|
|
|
|
Release.exec(
|
|
|
|
|
`git push ${
|
|
|
|
|
Release.isTest ? " --dry-run" : ""
|
|
|
|
|
} ${ distRemote } master --tags`,
|
|
|
|
|
"Error pushing master and tags to git repo."
|
|
|
|
|
);
|
2015-01-28 19:37:29 +00:00
|
|
|
|
|
|
|
|
|
// Set repo for npm publish
|
|
|
|
|
Release.dir.origRepo = Release.dir.repo;
|
|
|
|
|
Release.dir.repo = Release.dir.dist;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-29 23:36:48 +00:00
|
|
|
|
Release.walk( [
|
2015-01-28 19:37:29 +00:00
|
|
|
|
Release._section( "Copy files to distribution repo" ),
|
|
|
|
|
clone,
|
|
|
|
|
copy,
|
|
|
|
|
Release.confirmReview,
|
|
|
|
|
|
2017-03-17 16:30:55 +00:00
|
|
|
|
Release._section( "Add, commit, and tag files in distribution repo" ),
|
|
|
|
|
commit,
|
|
|
|
|
Release.confirmReview,
|
|
|
|
|
|
2015-01-28 19:37:29 +00:00
|
|
|
|
Release._section( "Pushing files to distribution repo" ),
|
|
|
|
|
push
|
2015-01-29 23:36:48 +00:00
|
|
|
|
], complete );
|
2015-01-28 19:37:29 +00:00
|
|
|
|
};
|