Skip to content

Commit 8c2693c

Browse files
authored
Unify build scripts to all rely on npm run build (#1161)
While `npm run build` prepares a module-aware package, we don't actually deploy one. This fixes that and avoids future issue by unifying the three build scripts in use.
1 parent 0071110 commit 8c2693c

File tree

6 files changed

+50
-27
lines changed

6 files changed

+50
-27
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
node_modules
99
coverage
1010
dist
11+
npm

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ coverage
1414
resources
1515
src
1616
dist
17+
npm

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
"prettier": "prettier --write 'src/**/*.js'",
3030
"check": "flow check",
3131
"check-cover": "for file in {src/*.js,src/**/*.js}; do echo $file; flow coverage $file; done",
32-
"build": "npm run build:clean && npm run build:npm && npm run build:npm-flow && npm run build:module && npm run build:module-flow",
32+
"build": "npm run build:clean && npm run build:npm && npm run build:npm-flow && npm run build:module && npm run build:module-flow && npm run build:package-json",
3333
"build:clean": "rm -rf ./dist",
34-
"build:npm": "babel src --optional runtime --ignore __tests__ --out-dir dist/ && cp package.json dist/",
34+
"build:package-json": "node ./resources/copy-package-json.js",
35+
"build:npm": "babel src --optional runtime --ignore __tests__ --out-dir dist/",
3536
"build:npm-flow": "find ./src -name '*.js' -not -path '*/__tests__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/dist\\//g'`.flow; done",
3637
"build:module": "BABEL_MODULES=1 babel src --optional runtime --ignore __tests__ --out-dir dist/module/",
3738
"build:module-flow": "find ./src -name '*.js' -not -path '*/__tests__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/dist\\/module\\//g'`.flow; done",

resources/copy-package-json.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
/**
9+
* Ensure a vanilla package.json before deploying so other tools do not
10+
* interpret the built output as requiring any further transformation.
11+
*/
12+
13+
const fs = require('fs');
14+
15+
const package = require('../package.json');
16+
delete package.scripts;
17+
delete package.options;
18+
delete package.devDependencies;
19+
fs.writeFileSync('./dist/package.json', JSON.stringify(package, null, 2));

resources/gitpublish.sh

100755100644
+24-12
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,35 @@
66
# "graphql": "git://github.com/graphql/graphql-js.git#npm"
77
#
88

9-
babel src --ignore __tests__ --out-dir npm
9+
# Build
10+
npm run build
1011

11-
# Ensure a vanilla package.json before deploying so other tools do not interpret
12-
# The built output as requiring any further transformation.
13-
node -e "var package = require('./package.json'); \
14-
delete package.scripts; \
15-
delete package.options; \
16-
delete package.devDependencies; \
17-
require('fs').writeFileSync('./npm/package.json', JSON.stringify(package, null, 2));"
12+
# Create empty npm directory
13+
rm -rf npm
14+
git clone -b npm "https://${GH_TOKEN}@github.com/graphql/graphql-js.git" npm
1815

16+
# Remove existing files first
17+
rm -rf npm/**/*
18+
rm -rf npm/*
19+
20+
# Copy over necessary files
21+
cp -r dist/* npm/
1922
cp README.md npm/
2023
cp LICENSE npm/
2124

25+
# Reference current commit
26+
HEADREV=`git rev-parse HEAD`
27+
echo $HEADREV
28+
29+
# Deploy
2230
cd npm
23-
git init
2431
git config user.name "Travis CI"
2532
git config user.email "[email protected]"
26-
git add .
27-
git commit -m "Deploy master to NPM branch"
28-
git push --force --quiet "https://${GH_TOKEN}@github.com/graphql/graphql-js.git" master:npm
33+
git add -A .
34+
if git diff --staged --quiet; then
35+
echo "Nothing to publish"
36+
else
37+
git commit -a -m "Deploy $HEADREV to NPM branch"
38+
git push > /dev/null 2>&1
39+
echo "Pushed"
40+
fi

resources/prepublish.sh

+2-13
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,5 @@ fi;
1818

1919
# When Travis CI publishes to NPM, the published files are available in the root
2020
# directory, which allows for a clean include or require of sub-modules.
21-
#
22-
# var language = require('graphql/language');
23-
#
24-
babel src --ignore __tests__ --out-dir ./;
25-
find ./src -name '*.js' -not -path '*/__tests__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\//g'`.flow; done;
26-
27-
# Ensure a vanilla package.json before deploying so other tools do not interpret
28-
# The built output as requiring any further transformation.
29-
node -e "var package = require('./package.json'); \
30-
delete package.scripts; \
31-
delete package.options; \
32-
delete package.devDependencies; \
33-
require('fs').writeFileSync('package.json', JSON.stringify(package));"
21+
npm run build
22+
cp -r ./dist/* ./

0 commit comments

Comments
 (0)