Skip to content

Commit

Permalink
chore: publishing scripts (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
kvet authored Jul 7, 2017
1 parent 5eb9809 commit 261a96f
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 3 deletions.
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
},
"license": "SEE LICENSE IN README.md",
"devDependencies": {
"concurrently": "^3.4.0",
"conventional-changelog-cli": "^1.3.1",
"fs-extra": "^3.0.1",
"gh-pages": "^1.0.0",
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-intercept": "^0.1.0",
"gulp-rename": "^1.2.2",
"inquirer": "^3.1.1",
"lerna": "2.0.0-rc.5",
"run-sequence": "^1.2.2"
"run-sequence": "^1.2.2",
"semver": "^5.3.0"
},
"scripts": {
"postinstall": "lerna bootstrap --concurrency=1",
Expand All @@ -28,6 +32,8 @@
"watch": "lerna run --parallel build:watch",
"lint": "lerna run lint",
"lint:ci": "lerna run lint:ci",
"test": "lerna run test"
"test": "lerna run test",
"publish:npm": "node ./scripts/publish-npm.js",
"publish:site": "node ./scripts/publish-site.js"
}
}
13 changes: 13 additions & 0 deletions scripts/gh-pages-files/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
* text eol=lf

# images
*.gif binary
*.jpg binary
*.png binary
*.svg binary
*.ico binary

# fonts
*.eot binary
*.ttf binary
*.woff binary
3 changes: 3 additions & 0 deletions scripts/gh-pages-files/shippable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
branches:
except:
- gh-pages
108 changes: 108 additions & 0 deletions scripts/publish-npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const { join } = require('path');
const { readFileSync, writeFileSync } = require('fs');
const { execSync } = require('child_process');
const { prompt } = require('inquirer');
const { valid, lt, inc, prerelease } = require('semver');

console.log('====================');
console.log(`| Publishing npm packages`);
console.log('====================');

const currentVersion = require('../lerna.json').version;
const suggestedVersion = inc(currentVersion, (prerelease(currentVersion) !== null ? 'prerelease' : 'patch'));

prompt({
name: 'version',
message: `Enter new version [current: ${currentVersion}]:`,
default: suggestedVersion,
validate: (input) => {
if(valid(input) === null)
return 'Version is invalid';
if(lt(input, currentVersion))
return 'New version should be greate than current';

return true;
}
})
.then(({ version }) => {
console.log();

console.log('Fetching the latest changes from upstream...');
execSync('git checkout master');
execSync('git fetch upstream master');
execSync('git merge --ff-only');

console.log('Cleaning previous build result...');
const rmScript = "require('fs-extra').removeSync(require('path').join(process.cwd(), 'dist'))";
execSync(`./node_modules/.bin/lerna exec --loglevel silent -- node -e "\\"${rmScript}\\""`);

console.log('Installing dependencies...');
execSync('npm install');

console.log('Building...');
execSync('npm run build');

console.log('Genereting CHANGELOG.md...');
const changelogFile = join(process.cwd(), 'CHANGELOG.md');
execSync('./node_modules/.bin/conventional-changelog -p angular -i CHANGELOG.md -s');
writeFileSync(
changelogFile,
String(readFileSync(changelogFile))
.replace('name=""', `name="${version}"`)
.replace('[](', `[${version}](`)
.replace('...v)', `...v${version})`),
);

prompt({
message: 'Ready to publish. Please check build result and CHANGELOG.md. Is it ok?',
name: 'publishNpm',
type: 'confirm',
default: false,
})
.then(({ publishNpm }) => {
if (!publishNpm) {
console.log('Npm publishing is aborted...');
return;
}

console.log('Login into npm...');
try { execSync('npm logout', { stdio: 'ignore' }); } catch (e) {}
execSync('npm login', { stdio: 'inherit' });

console.log('Publishing npm...');
execSync(`./node_modules/.bin/lerna publish --exact --force-publish * --repo-version ${version} --yes --skip-git`);

console.log('Logout from npm...');
execSync('npm logout', { stdio: 'ignore' });

console.log('Preparing pull request...');
const commitMessage = `chore: publish ${version}`;
const branchName = `v${version.replace(/\./g, '-')}`;
execSync(`git checkout -b "${branchName}"`);
execSync('git add .');
execSync(`git commit -m "${commitMessage}"`);
execSync(`git push origin ${branchName}`);
execSync(`git checkout master`);

console.log('--------------------');
console.log(`You have to pull request changes from branch ${branchName}!`);
console.log(`Don\'t forget to create a release on GitHub!`);
console.log('--------------------');

prompt({
message: 'It is a good point to publish site. Proceed?',
name: 'publishSite',
type: 'confirm',
default: false,
})
.then(({ publishSite }) => {
if (!publishSite) {
console.log('Site publishing is aborted...');
return;
}

execSync(`npm run publish:site`);
});
});
});

44 changes: 44 additions & 0 deletions scripts/publish-site.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { join } = require('path');
const { execSync } = require('child_process');
const { publish } = require('gh-pages');
const { copySync, removeSync } = require('fs-extra');


const SITE_DIRECTORY = join(process.cwd(), 'site');
const GENERATED_SITE_DIRECTORY = join(process.cwd(), 'site/_site');
const REPO = 'devexpress/devextreme-reactive';
const BRANCH = 'gh-pages';
const COMMIT_MESSAGE = 'chore: update site';


console.log('====================');
console.log(`| Publishing site to ${REPO}@${BRANCH}`);
console.log('| Assume that repo is clean and up to date')
console.log('====================');
console.log();

console.log('Building site content...');
execSync('npm run build:site');

console.log('Cleaning generated site...');
removeSync(GENERATED_SITE_DIRECTORY);

console.log('Generating site...');
execSync(`bundle exec jekyll build --source ${SITE_DIRECTORY} --destination ${GENERATED_SITE_DIRECTORY}`, { cwd: SITE_DIRECTORY });

console.log('Coping github staff...');
copySync(join(__dirname, 'gh-pages-files'), GENERATED_SITE_DIRECTORY);

console.log('Publishing...');
publish(GENERATED_SITE_DIRECTORY, {
branch: BRANCH,
repo: `https://github.com/${REPO}.git`,
message: COMMIT_MESSAGE,
src: ['**/*', '.gitattributes'],
}, (err) => {
if (err) {
console.log(String(err));
return;
}
console.log(`Published!`);
});

0 comments on commit 261a96f

Please sign in to comment.