From 2cd82b23554b80cd95a3997c21ec341f5703973e Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Fri, 29 Sep 2017 12:21:40 -0700 Subject: [PATCH 1/2] Adds a script which automatically builds a #npm branch This branch can then be used as a "latest" npm dependency, rather than using the master branch for that purpose. This will allow us to remove built dependencies from the checked-in repo. --- .gitignore | 1 + .travis.yml | 19 ++++++++++++------- package.json | 3 ++- resources/gitpublish.sh | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100755 resources/gitpublish.sh diff --git a/.gitignore b/.gitignore index cd9cca688f..946cdc1eb9 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ yarn-error.log TODO /pages/out /pages/generated +/npm diff --git a/.travis.yml b/.travis.yml index 2cd9da2b3e..2223387ab6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,10 +18,15 @@ addons: - g++-4.9 deploy: -- provider: script - skip_cleanup: true - script: npm run deploy - on: - tags: false - branch: master - repo: facebook/immutable-js + - provider: script + script: npm run gitpublish + skip_cleanup: true + on: + branch: master + repo: facebook/immutable-js + - provider: script + skip_cleanup: true + script: npm run deploy + on: + branch: master + repo: facebook/immutable-js diff --git a/package.json b/package.json index 84ee797c4e..848b74fe8f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ "test:types:flow": "flow check type-definitions/tests", "perf": "node ./resources/bench.js", "start": "gulp --gulpfile gulpfile.js dev", - "deploy": "(cd ./pages/out && git init && git config user.name \"Travis CI\" && git config user.email \"github@fb.com\" && git add . && git commit -m \"Deploy to GitHub Pages\" && git push --force --quiet \"https://${GH_TOKEN}@github.com/facebook/immutable-js.git\" master:gh-pages > /dev/null 2>1)" + "deploy": "(cd ./pages/out && git init && git config user.name \"Travis CI\" && git config user.email \"github@fb.com\" && git add . && git commit -m \"Deploy to GitHub Pages\" && git push --force --quiet \"https://${GH_TOKEN}@github.com/facebook/immutable-js.git\" master:gh-pages > /dev/null 2>1)", + "gitpublish": ". ./resources/gitpublish.sh" }, "jest": { "moduleFileExtensions": [ diff --git a/resources/gitpublish.sh b/resources/gitpublish.sh new file mode 100755 index 0000000000..0ae3d33fc2 --- /dev/null +++ b/resources/gitpublish.sh @@ -0,0 +1,35 @@ +#!/bin/sh -e + +# This script maintains a git branch which mirrors master but in a form that +# what will eventually be deployed to npm, allowing npm dependencies to use: +# +# "immutable": "git://github.com/facebook/immutable-js.git#npm" +# + +# Create empty npm directory +rm -rf npm +mkdir npm + +# Copy over necessary files +cp -r dist npm/ +cp -r contrib npm/ +cp README.md npm/ +cp LICENSE npm/ +cp PATENTS npm/ + +# Ensure a vanilla package.json before deploying so other tools do not interpret +# The built output as requiring any further transformation. +node -e "var package = require('./package.json'); \ + delete package.scripts; \ + delete package.options; \ + delete package.jest; \ + delete package.devDependencies; \ + require('fs').writeFileSync('./npm/package.json', JSON.stringify(package, null, 2));" + +cd npm +git init +git config user.name "Travis CI" +git config user.email "github@fb.com" +git add . +git commit -m "Deploy master to NPM branch" +git push --force --quiet "https://${GH_TOKEN}@github.com/facebook/immutable-js.git" master:npm From 0c3313c68cd2986d6c6689b1d09c062e2246136d Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Fri, 29 Sep 2017 12:38:54 -0700 Subject: [PATCH 2/2] Include bower.json --- resources/gitpublish.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/resources/gitpublish.sh b/resources/gitpublish.sh index 0ae3d33fc2..de925ed275 100755 --- a/resources/gitpublish.sh +++ b/resources/gitpublish.sh @@ -8,7 +8,10 @@ # Create empty npm directory rm -rf npm -mkdir npm +git clone -b npm "https://${GH_TOKEN}@github.com/facebook/graphql.git" npm + +# Remove existing files first +rm -rf npm/**/* # Copy over necessary files cp -r dist npm/ @@ -16,6 +19,7 @@ cp -r contrib npm/ cp README.md npm/ cp LICENSE npm/ cp PATENTS npm/ +cp bower.json npm/ # Ensure a vanilla package.json before deploying so other tools do not interpret # The built output as requiring any further transformation. @@ -27,9 +31,13 @@ node -e "var package = require('./package.json'); \ require('fs').writeFileSync('./npm/package.json', JSON.stringify(package, null, 2));" cd npm -git init git config user.name "Travis CI" git config user.email "github@fb.com" -git add . -git commit -m "Deploy master to NPM branch" -git push --force --quiet "https://${GH_TOKEN}@github.com/facebook/immutable-js.git" master:npm +git add -A . +if git diff --staged --quiet; then + echo "Nothing to publish" +else + git commit -a -m "Deploy master to NPM branch" + git push > /dev/null 2>&1 + echo "Pushed" +fi