-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
30 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,51 +1,48 @@ | ||
#!/usr/bin/env node | ||
|
||
const chalk = require('chalk'); | ||
const { execSync } = require('child_process'); | ||
const chalk = require("chalk"); | ||
const { execSync } = require("child_process"); | ||
|
||
function printErrorAndExit(error) { | ||
console.log(error); | ||
console.log(`\n${chalk.red.bold(' Commit failed ')}\n`); | ||
console.log(`\n${chalk.red.bold(" Commit failed ")}\n`); | ||
process.exit(1); | ||
} | ||
|
||
console.log(`\n${chalk.bgGreen.bold(' Validating commit ')}\n`); | ||
console.log(`\n${chalk.bgGreen.bold(" Validating commit ")}\n`); | ||
console.log(` > Checking the build`); | ||
try { | ||
execSync(`npm run build`, | ||
{ | ||
stdio: ['pipe', 'pipe', 'pipe'], | ||
env: { | ||
...process.env, | ||
FORCE_COLOR: 'true', | ||
}, | ||
} | ||
); | ||
execSync(`npm run build`, { | ||
stdio: ["pipe", "pipe", "pipe"], | ||
env: { | ||
...process.env, | ||
FORCE_COLOR: "true", | ||
}, | ||
}); | ||
console.log(` ✔ Build successful`); | ||
const result = execSync(`git diff --name-only`, | ||
{ | ||
stdio: ['pipe', 'pipe', 'pipe'], | ||
encoding: 'utf-8', | ||
env: { | ||
...process.env, | ||
FORCE_COLOR: 'true', | ||
}, | ||
} | ||
); | ||
const changedFiles = result.split('\n').filter(f => f.startsWith('dist/')); | ||
const result = execSync(`git diff --name-only`, { | ||
stdio: ["pipe", "pipe", "pipe"], | ||
encoding: "utf-8", | ||
env: { | ||
...process.env, | ||
FORCE_COLOR: "true", | ||
}, | ||
}); | ||
const changedFiles = result.split("\n").filter((f) => f.startsWith("dist/")); | ||
if (changedFiles.length > 0) { | ||
console.log(` > Adding modified build files`); | ||
changedFiles.forEach((f) => { | ||
execSync(`git add ${f}`, { | ||
stdio: ['pipe', 'pipe', 'pipe'], | ||
stdio: ["pipe", "pipe", "pipe"], | ||
}); | ||
}); | ||
console.log(` ✔ Commit expanded with ${changedFiles.length} changed file(s)`); | ||
console.log( | ||
` ✔ Commit expanded with ${changedFiles.length} changed file(s)` | ||
); | ||
} | ||
|
||
console.log(`\n${chalk.bold(' Commit successful ')}\n`); | ||
console.log(`\n${chalk.bold(" Commit successful ")}\n`); | ||
process.exit(0); | ||
|
||
} catch (error) { | ||
printErrorAndExit(error); | ||
} |
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 |
---|---|---|
|
@@ -3,6 +3,6 @@ | |
"target": "es2015", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"types": ["node"], | ||
"types": ["node"] | ||
} | ||
} | ||
} |