Skip to content

Commit

Permalink
Merge branch 'master' into unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
taye committed Apr 9, 2017
2 parents 4c3560f + 671497e commit 4c9dfbf
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 34 deletions.
20 changes: 20 additions & 0 deletions build/bump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const version = require('./version');

const [,, release, prereleaseId] = process.argv;

let newVersion;

if (release) {
newVersion = version.bump({
release,
prereleaseId,
});
}
// if this was run with no arguments, get the current version with
// updated build metadata
else {
newVersion = version.get();
}

version.write(newVersion);
console.log(newVersion);
4 changes: 2 additions & 2 deletions build/bundleProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const filenames = {
minMap: 'interact.min.js.map',
};

module.exports = function bundleProcessor ({ bundleStream, headerFile, minHeaderFile, release }) {
module.exports = function bundleProcessor ({ bundleStream, headerFile, minHeaderFile, noMetadata }) {
mkdirp(destDir);

let streamCode = '';
Expand Down Expand Up @@ -45,7 +45,7 @@ module.exports = function bundleProcessor ({ bundleStream, headerFile, minHeader
code,
map,
headerFilename,
replacer: input => replacer(input, { release }),
replacer: input => replacer(input, { updateMetadata: !noMetadata }),
};
}
};
Expand Down
7 changes: 2 additions & 5 deletions build/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ const fs = require('fs');
const mkdirp = require('mkdirp');
const replacer = require('./replacer');

module.exports = ({ release = process.argv.includes('--release'), stdio = 'inherit' } = {}) => {
module.exports = ({ stdio = 'inherit' } = {}) => {
process.stdout.write('Docs...');
mkdirp.sync('dist');

const drjson = replacer(fs.readFileSync('dr.json').toString(), {
release,
decorate: false,
});
const drjson = replacer(fs.readFileSync('dr.json').toString());

fs.writeFileSync('_dr.json', drjson);

Expand Down
4 changes: 0 additions & 4 deletions build/getVersion.js

This file was deleted.

9 changes: 9 additions & 0 deletions build/gitRev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const child_process = require('child_process');

function run (cmd) {
return child_process.execSync(cmd).toString().trim();
}

module.exports = {
short: () => run('git rev-parse --short HEAD'),
};
15 changes: 7 additions & 8 deletions build/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const browserify = require('browserify');
const browserify = require('browserify');
const bundleProcessor = require('./bundleProcessor');

const config = {
debug: true,
entries: 'index.js',
standalone: 'interact',

transform: [[ 'babelify', {} ]],
transform: [[ 'babelify', { compact: false } ]],

cache: {},
packageCache: {},
};

const b = browserify(config);

const pwdRegex = new RegExp(`^${process.env.PWD}.`);
const release = process.argv.includes('--release');
const watch = process.argv.includes('--watch');
const docs = process.argv.includes('--docs')? require('./docs') : null;
const pwdRegex = new RegExp(`^${process.env.PWD}.`);
const noMetadata = process.argv.includes('--no-metadata');
const watch = process.argv.includes('--watch');
const docs = process.argv.includes('--docs')? require('./docs') : null;

if (watch) {
b.plugin(require('watchify'));
Expand All @@ -35,7 +35,6 @@ else {
function update (ids) {
if (docs) {
docs({
release,
stdio: ['ignore', 'ignore', 'inherit'],
});
}
Expand All @@ -54,7 +53,7 @@ function update (ids) {
}

bundleProcessor({
release,
noMetadata,
bundleStream: b.bundle(),
headerFile: 'src/header.js',
minHeaderFile: 'src/minHeader.js',
Expand Down
8 changes: 6 additions & 2 deletions build/replacer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const gitRev = require('./gitRev');
const version = require('./version');

module.exports = (input, versionOptions) => [
[ /[{]VERSION[}]/g, require('./getVersion')(versionOptions) ],
[ /[{]YEAR[}]/g, new Date().getFullYear() ],
[ /[{]VERSION[}]/g, version.get(versionOptions) ],
[ /[{]YEAR[}]/g , new Date().getFullYear() ],
[ /[{]GIT_REV[}]/g, gitRev.short() ],
].reduce((result, [rx, str]) => result.replace(rx, str), input);
51 changes: 51 additions & 0 deletions build/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const child_process = require('child_process');
const fs = require('fs');
const semver = require('semver');
const gitRev = require('./gitRev');

const version = {
get ({ updateMetadata = true } = {}) {
const package = JSON.parse(fs.readFileSync('package.json').toString());

const parsed = semver.parse(package.version);
const dirty = child_process.execSync(`
git diff-index --quiet HEAD -- . ':!dist' ':!package.json' &&
git diff --quiet -- . ':!dist' ||
echo -dirty`).toString().trim();
const matchedMetadata = parsed.raw.match(/[+].*$/);
const newMetadata = updateMetadata
? `+sha.${gitRev.short()}`.trim()
: matchedMetadata? matchedMetadata[0] : '';

return `v${parsed.version}${newMetadata}${dirty}`;
},

bump ({
version: prev = version.get(),
release = 'minor',
prereleaseId,
}) {
const semverArgs = [prev, release, prereleaseId];

let newVersion = semver.inc(...semverArgs);

if (newVersion === null) {
throw `Invalid args to semver.inc (${semverArgs.join()})`;
}

if (release === 'prerelease') {
newVersion += `+sha.${gitRev.short()}`;
}

return newVersion;
},

write (newVersion) {
const package = JSON.parse(fs.readFileSync('package.json').toString());
package.version = newVersion;

fs.writeFileSync('package.json', `${JSON.stringify(package, null, 2)}\n`);
},
};

module.exports = version;
18 changes: 9 additions & 9 deletions dr.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@
"files": [
{
"url": "src/actions/drag.js",
"link": "https://github.com/taye/interact.js/blob/{VERSION}/src/actions/drag.js"
"link": "https://github.com/taye/interact.js/blob/{GIT_REV}/src/actions/drag.js"
},
{
"url": "src/actions/drop.js",
"link": "https://github.com/taye/interact.js/blob/{VERSION}/src/actions/drop.js"
"link": "https://github.com/taye/interact.js/blob/{GIT_REV}/src/actions/drop.js"
},
{
"url": "src/actions/resize.js",
"link": "https://github.com/taye/interact.js/blob/{VERSION}/src/actions/resize.js"
"link": "https://github.com/taye/interact.js/blob/{GIT_REV}/src/actions/resize.js"
},
{
"url": "src/actions/gesture.js",
"link": "https://github.com/taye/interact.js/blob/{VERSION}/src/actions/gesture.js"
"link": "https://github.com/taye/interact.js/blob/{GIT_REV}/src/actions/gesture.js"
},
{
"url": "src/Interactable.js",
"link": "https://github.com/taye/interact.js/blob/{VERSION}/src/Interactable.js"
"link": "https://github.com/taye/interact.js/blob/{GIT_REV}/src/Interactable.js"
},
{
"url": "src/autoStart/base.js",
"link": "https://github.com/taye/interact.js/blob/{VERSION}/src/autoStart/base.js"
"link": "https://github.com/taye/interact.js/blob/{GIT_REV}/src/autoStart/base.js"
},
{
"url": "src/interactablePreventDefault.js",
"link": "https://github.com/taye/interact.js/blob/{VERSION}/src/interactablePreventDefault.js"
"link": "https://github.com/taye/interact.js/blob/{GIT_REV}/src/interactablePreventDefault.js"
},
{
"url": "src/interact.js",
"link": "https://github.com/taye/interact.js/blob/{VERSION}/src/interact.js"
"link": "https://github.com/taye/interact.js/blob/{GIT_REV}/src/interact.js"
},
{
"url": "src/Interaction.js",
"link": "https://github.com/taye/interact.js/blob/{VERSION}/src/Interaction.js"
"link": "https://github.com/taye/interact.js/blob/{GIT_REV}/src/Interaction.js"
}
]
}
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interactjs",
"version": "1.3.0",
"version": "1.3.0-alpha",
"repository": {
"type": "git",
"url": "https://github.com/taye/interact.js.git"
Expand All @@ -24,9 +24,11 @@
"precommit": "npm run lint -- --fail-on-error",
"prepush": "npm run preversion",
"preversion": "npm test && istanbul check-coverage",
"version": "git clean -fx dist && npm run build -- --release && git add -A dist",
"postversion": "git push && git push --tags",
"unstable": "git clean -ix && git checkout -f unstable && git merge --no-ff --no-edit master && git clean -fx && npm run build && git commit -m 'dist: bundle js and generate docs' -- dist"
"version": "git clean -fx dist && git add -- package.json && npm run build -- --no-metadata && git add -A -- dist",
"postversion": "",
"release": "npm version --no-git-tag-version -m 'v%s'",
"pre-release": "git clean -fx dist/* && git diff-index HEAD --stat --exit-code && git merge --no-ff --no-edit master && NEW_VERSION=$(node build/bump prerelease) && git add package.json && npm run preversion && npm run build && git commit -m \"v$NEW_VERSION\" -- package.json dist",
"bump": "node build/bump $@"
},
"description": "Drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE8+)",
"homepage": "http://interactjs.io",
Expand Down Expand Up @@ -71,6 +73,7 @@
"jsdom": "^9.11.0",
"lodash": "^3.10.1",
"mkdirp": "^0.5.1",
"semver": "^5.3.0",
"tap-spec": "^4.1.1",
"tape": "^4.6.3",
"through2": "^2.0.0",
Expand Down

0 comments on commit 4c9dfbf

Please sign in to comment.