Browse Source

Automate build step (#1551)

* remove note that was fixed in #1526

* add build script

* add prepack script

* remove custom compilation steps
Francisco Giordano 6 years ago
parent
commit
a99b9da3d4
3 changed files with 30 additions and 15 deletions
  1. 2 14
      RELEASING.md
  2. 3 1
      package.json
  3. 25 0
      scripts/build.sh

+ 2 - 14
RELEASING.md

@@ -34,13 +34,7 @@ git push upstream vX.Y.Z-rc.R
 
 Draft the release notes in our [GitHub releases](https://github.com/OpenZeppelin/openzeppelin-solidity/releases). Make sure to mark it as a pre-release! Try to be consistent with our previous release notes in the title and format of the text. Release candidates don't need a detailed changelog, but make sure to include a link to GitHub's compare page.
 
-Before publishing on npm you need to generate the build artifacts. This is not done automatically at the moment because of a bug in Truffle. Since some of the contracts should not be included in the package, this is a _hairy_ process that you need to do with care.
-
-1. Delete the `contracts/mocks`, `contracts/examples` and `build` directories.
-2. Run `truffle compile`. (Note that the Truffle process may never exit and you will have to interrupt it.)
-3. Recover the directories using `git checkout`. It doesn't matter if you do this now or later.
-
-Once the CI run for the new tag is green, publish on npm under the `next` tag.
+Once the CI run for the new tag is green, publish on npm under the `next` tag. You should see the contracts compile automatically.
 
 ```
 npm publish --tag next
@@ -68,13 +62,7 @@ git push upstream vX.Y.Z
 
 Draft the release notes in GitHub releases. Try to be consistent with our previous release notes in the title and format of the text. Make sure to include a detailed changelog.
 
-Before publishing on npm you need to generate the build artifacts. This is not done automatically at the moment because of a bug in Truffle. Since some of the contracts should not be included in the package, this is a _hairy_ process that you need to do with care.
-
-1. Delete the `contracts/mocks`, `contracts/examples` and `build` directories.
-2. Run `truffle compile`. (Note that the Truffle process may never exit and you will have to interrupt it.)
-3. Recover the directories using `git checkout`. It doesn't matter if you do this now or later.
-
-Once the CI run for the new tag is green, publish on npm.
+Once the CI run for the new tag is green, publish on npm. You should see the contracts compile automatically.
 
 ```
 npm publish

+ 3 - 1
package.json

@@ -17,7 +17,9 @@
     "lint:fix": "npm run lint:js:fix && npm run lint:sol:fix",
     "console": "truffle console",
     "coverage": "scripts/coverage.sh",
-    "version": "scripts/version.js"
+    "version": "scripts/version.js",
+    "build": "scripts/build.sh",
+    "prepack": "npm run build"
   },
   "repository": {
     "type": "git",

+ 25 - 0
scripts/build.sh

@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+# Configure to exit script as soon as a command fails.
+set -o errexit
+
+# Clean the existing build directory.
+rm -rf build
+
+# Create a temporary directory to place ignored files (e.g. examples).
+tmp_dir="$(mktemp -dp.)"
+
+# Move the ignored files to the temporary directory.
+while IFS="" read -r ignored
+do
+  mv "contracts/$ignored" "$tmp_dir"
+done < contracts/.npmignore
+
+# Compile everything else.
+node_modules/.bin/truffle compile
+
+# Return ignored files to their place.
+mv "$tmp_dir/"* contracts/
+
+# Delete the temporary directory.
+rmdir "$tmp_dir"