Unverified Commit cc19ccfd by Francisco Giordano Committed by GitHub

Improve prepack script (#1747)

* improve prepack script

* remove .npmignore

* make prepack use pkg.files

* fix linter errors
parent fa004a7f
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
"files": [ "files": [
"build", "build",
"contracts", "contracts",
"!contracts/mocks",
"!contracts/examples",
"test/behaviors" "test/behaviors"
], ],
"scripts": { "scripts": {
...@@ -18,10 +20,10 @@ ...@@ -18,10 +20,10 @@
"lint:js": "eslint .", "lint:js": "eslint .",
"lint:js:fix": "eslint . --fix", "lint:js:fix": "eslint . --fix",
"lint:sol": "solhint --max-warnings 0 \"contracts/**/*.sol\"", "lint:sol": "solhint --max-warnings 0 \"contracts/**/*.sol\"",
"prepack": "scripts/prepack.sh", "prepack": "node scripts/prepack.js",
"release": "scripts/release/release.sh", "release": "scripts/release/release.sh",
"version": "scripts/release/update-changelog-release-date.js && scripts/release/update-ethpm-version.js", "version": "scripts/release/update-changelog-release-date.js && scripts/release/update-ethpm-version.js",
"test": "npm run compile && scripts/test.sh" "test": "scripts/test.sh"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
...@@ -54,6 +56,7 @@ ...@@ -54,6 +56,7 @@
"ethereumjs-util": "^6.0.0", "ethereumjs-util": "^6.0.0",
"ganache-cli": "^6.4.1", "ganache-cli": "^6.4.1",
"ganache-cli-coverage": "https://github.com/frangio/ganache-cli/releases/download/v6.4.1-coverage/ganache-cli-coverage-6.4.1.tgz", "ganache-cli-coverage": "https://github.com/frangio/ganache-cli/releases/download/v6.4.1-coverage/ganache-cli-coverage-6.4.1.tgz",
"micromatch": "^4.0.2",
"openzeppelin-docsite": "github:OpenZeppelin/openzeppelin-docsite", "openzeppelin-docsite": "github:OpenZeppelin/openzeppelin-docsite",
"openzeppelin-test-helpers": "^0.3.2", "openzeppelin-test-helpers": "^0.3.2",
"solhint": "^1.5.0", "solhint": "^1.5.0",
......
...@@ -4,4 +4,7 @@ if [ "$SOLC_NIGHTLY" = true ]; then ...@@ -4,4 +4,7 @@ if [ "$SOLC_NIGHTLY" = true ]; then
docker pull ethereum/solc:nightly docker pull ethereum/solc:nightly
fi fi
# Necessary to avoid an error in Truffle
rm -rf build/contracts
truffle compile truffle compile
#!/usr/bin/env node
// This script removes the build artifacts of ignored contracts.
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const match = require('micromatch');
function exec (cmd, ...args) {
cp.execFileSync(cmd, args, { stdio: 'inherit' });
}
function readJSON (path) {
return JSON.parse(fs.readFileSync(path));
}
exec('npm', 'run', 'compile');
const pkgFiles = readJSON('package.json').files;
// Get only negated patterns.
const ignorePatterns = pkgFiles
.filter(pat => pat.startsWith('!'))
// Add **/* to ignore all files contained in the directories.
.flatMap(pat => [pat, path.join(pat, '**/*')])
// Remove the negation part. Makes micromatch usage more intuitive.
.map(pat => pat.slice(1));
const artifactsDir = 'build/contracts';
for (const artifact of fs.readdirSync(artifactsDir)) {
const fullArtifactPath = path.join(artifactsDir, artifact);
const { sourcePath: fullSourcePath } = readJSON(fullArtifactPath);
const sourcePath = path.relative('.', fullSourcePath);
const ignore = match.any(sourcePath, ignorePatterns);
if (ignore) {
fs.unlinkSync(fullArtifactPath);
}
}
#!/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="ignored_contracts"
mkdir "$tmp_dir"
# 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.
npm run compile
# Return ignored files to their place.
mv "$tmp_dir/"* contracts/
# Delete the temporary directory.
rmdir "$tmp_dir"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment