Skip to content

Commit 6c3bf72

Browse files
committed
Add index to commit from build script
1 parent 6804deb commit 6c3bf72

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

build.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
// Setup
44
const rollup = require('rollup').rollup
55
const dest = 'index.js'
6+
const git = require('simple-git')(__dirname)
67

78
// Main
8-
rollup({entry: 'index-es6.js'}).then((b) => b.write({format: 'cjs', dest}))
9+
rollup({entry: 'index-es6.js'}).then((b) => {
10+
b.write({format: 'cjs', dest}).then(() => {
11+
git.add(['index.js'])
12+
}).catch(console.error)
13+
})

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
66
const buf = ' ';
77
const tab = ' ';
88
const borderX = `${Array(30).join('-')}\n`;
9+
let proc = process;
10+
let root = proc && proc.cwd ? proc.cwd() : null;
911
let limit;
1012

1113
// Helpers
@@ -22,6 +24,7 @@ const formatBytes = (bytes) => {
2224
function init (opts) {
2325
opts = opts || {};
2426
limit = opts.limit;
27+
root = opts.root || root;
2528
}
2629

2730
function formatted (bndl) { return analyze(bndl, true) }
@@ -30,9 +33,9 @@ function analyze (bundle, format) {
3033
let deps = {};
3134
return new Promise((resolve, reject) => {
3235
let modules = bundle.modules.map((m, i) => {
33-
let id = m.id.replace(__dirname, '');
36+
let id = m.id.replace(root, '');
3437
m.dependencies.forEach((d) => {
35-
d = d.replace(__dirname, '');
38+
d = d.replace(root, '');
3639
deps[d] = deps[d] || [];
3740
deps[d].push(id);
3841
});
@@ -49,7 +52,7 @@ function analyze (bundle, format) {
4952
formatted += `size:${buf}${formatBytes(m.size)}\n`;
5053
formatted += `dependents:${buf}${m.dependents.length}\n`;
5154
m.dependents.forEach((d) => {
52-
formatted += `${tab}-${buf}${d.replace(__dirname, '')}\n`;
55+
formatted += `${tab}-${buf}${d.replace(root, '')}\n`;
5356
});
5457
formatted += `${borderX}`;
5558
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"homepage": "https://github.com/doesdev/rollup-analyzer#readme",
3232
"devDependencies": {
3333
"ghooks": "^1.3.2",
34-
"rollup": "^0.36.4"
34+
"rollup": "^0.36.4",
35+
"simple-git": "^1.63.0"
3536
},
3637
"config": {
3738
"ghooks": {

0 commit comments

Comments
 (0)