Skip to content

Commit

Permalink
use base ref
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jul 7, 2021
1 parent 6cdc626 commit c62b15f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ jobs:
run: 'npm run benchmark -- --revs HEAD HEAD~1'

diff-npm-package:
name: Diff context of NPM package
name: Diff content of NPM package
runs-on: ubuntu-latest
steps:
- name: Checkout repo
Expand All @@ -224,13 +224,14 @@ jobs:
node-version: ${{ env.NODE_VERSION_USED_FOR_DEVELOPMENT }}

- name: Generate report
run: 'node resources/diff-npm-package.js HEAD~1 HEAD'
run: 'node resources/diff-npm-package.js ${{ github.event.pull_request.base.sha }} HEAD'

- name: Upload generated report
uses: actions/upload-artifact@v2
with:
name: npm-dist-diff.html
path: ./npm-dist-diff.html
if-no-files-found: ignore

deploy-to-npm-branch:
name: Deploy to `npm` branch
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# https://help.github.com/articles/ignoring-files/#create-a-global-gitignore
# https://www.gitignore.io/

/diff-npm-package.html
/.eslintcache
/node_modules
/coverage
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copied from '.gitignore', please keep it in sync.
/diff-npm-package.html
/.eslintcache
/node_modules
/coverage
Expand Down
1 change: 1 addition & 0 deletions cspell.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: en
ignorePaths:
# Copied from '.gitignore', please keep it in sync.
- diff-npm-package.html
- .eslintcache
- node_modules
- coverage
Expand Down
24 changes: 11 additions & 13 deletions resources/diff-npm-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ fs.rmSync(tmpDir, { recursive: true, force: true });
fs.mkdirSync(tmpDir);

const args = process.argv.slice(2);
const fromRevision = args.pop() ?? 'HEAD';
const toRevision = args.pop() ?? LOCAL;
let [fromRevision, toRevision] = args;
if (args.length < 2) {
console.warn(`Assuming you meant: diff-npm-package ${fromRevision} ${toRevision}`);
fromRevision = fromRevision ?? 'HEAD';
toRevision = toRevision ?? LOCAL;
console.warn(
`Assuming you meant: diff-npm-package ${fromRevision} ${toRevision}`,
);
}

console.log(`📦 Bulding NPM package for ${fromRevision}...`);
console.log(`📦 Building NPM package for ${fromRevision}...`);
const fromPackage = prepareNPMPackage(fromRevision);

console.log(`📦 Bulding NPM package for ${toRevision}...`);
console.log(`📦 Building NPM package for ${toRevision}...`);
const toPackage = prepareNPMPackage(toRevision);

console.log(`➖➕ Generating diff...`);
console.log('➖➕ Generating diff...');
const diff = exec(`npm diff --diff=${fromPackage} --diff=${toPackage}`);

if (diff === '') {
Expand All @@ -35,7 +38,7 @@ if (diff === '') {
console.log('Report saved to: ', reportPath);
}

function generateReport(diff) {
function generateReport(diffString) {
return `
<!DOCTYPE html>
<html lang="en-us">
Expand All @@ -51,19 +54,15 @@ function generateReport(diff) {
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js"></script>
</head>
<script>
const diffString = ${JSON.stringify(diff)};
const diffString = ${JSON.stringify(diffString)};
document.addEventListener('DOMContentLoaded', () => {
const targetElement = document.getElementById('myDiffElement');
const configuration = {
drawFileList: true,
fileListToggle: true,
fileListStartVisible: false,
fileContentToggle: true,
matching: 'lines',
outputFormat: 'side-by-side',
synchronisedScroll: true,
highlight: true,
renderNothingWhenEmpty: false,
};
const diff2htmlUi = new Diff2HtmlUI(targetElement, diffString, configuration);
Expand All @@ -77,7 +76,6 @@ function generateReport(diff) {
</html>
`;
}

function prepareNPMPackage(revision) {
if (revision === LOCAL) {
exec('npm --quiet run build:npm', { cwd: localRepoDir });
Expand Down

0 comments on commit c62b15f

Please sign in to comment.