-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* improve prepack script * remove .npmignore * make prepack use pkg.files * fix linter errors
- Loading branch information
Francisco Giordano
authored
May 14, 2019
1 parent
fa004a7
commit cc19ccf
Showing
6 changed files
with
202 additions
and
111 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/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); | ||
} | ||
} |
Oops, something went wrong.