pgbundle: Fix build ignore and index parsing; ignore .vdl.js files.
Fixed file header parsing to ignore '+build ignore' instead of
'+build omit' and ignore blank lines before index.
Prevented crash on parsing blank file.
Added .vdl.js files to ignore pattern.
Improved Makefile.
Change-Id: I5a794729f64c7215ca751cf40a4a279af79cb947
diff --git a/pgbundle/Makefile b/pgbundle/Makefile
index 43cd1c5..4ba5419 100644
--- a/pgbundle/Makefile
+++ b/pgbundle/Makefile
@@ -1,11 +1,15 @@
-export SHELL := /bin/bash -euo pipefail
+PATH := $(PATH):$(VANADIUM_ROOT)/environment/cout/node/bin
+SHELL := /bin/bash -euo pipefail
node_modules: package.json
- npm prune
+ @npm prune
npm install
- touch node_modules
+ @touch node_modules
-lint:
- jshint .
+.PHONY: clean
+clean:
+ @$(RM) -rf node_modules
.PHONY: lint
+lint:
+ @jshint .
diff --git a/pgbundle/index.js b/pgbundle/index.js
index 99e1a52..bf8428a 100644
--- a/pgbundle/index.js
+++ b/pgbundle/index.js
@@ -15,20 +15,28 @@
process.exit(1);
}
-// If the first line is "// +build OMIT", strip the line and return the
+// If the first line is "// +build ignore", strip the line and return the
// remaining lines.
-function stripBuildOmit(lines) {
- if (lines[0] === '// +build OMIT') {
+function stripBuildIgnore(lines) {
+ if (lines.length > 0 && _.trim(lines[0]) === '// +build ignore') {
return _.rest(lines);
}
return lines;
}
+// Strip all blank lines at the beginning of the file.
+function stripLeadingBlankLines(lines) {
+ var nb = 0;
+ for (; nb < lines.length && _.trim(lines[nb]) === ''; ++nb) /* no-op */;
+ return _.slice(lines, nb);
+}
+
// If the first line is an index comment, strip the line and return the index
// and remaining lines.
function getIndex(lines) {
var index = null;
- var match = lines[0].match(/^\/\/\s*index=(\d+)/);
+ var match = lines.length > 0 &&
+ _.trim(lines[0]).match(/^\/\/\s*index=(\d+)/);
if (match && match[1]) {
index = match[1];
lines = _.rest(lines);
@@ -48,8 +56,8 @@
if (fileName === BUNDLE_NAME) {
return true;
}
- // Ignore generated .vdl.go files.
- if ((/\.vdl\.go$/i).test(fileName)) {
+ // Ignore generated .vdl.go and .vdl.js files.
+ if ((/\.vdl\.(go|js)$/i).test(fileName)) {
return true;
}
// Ignore files inside "bin" and "pkg" directories.
@@ -94,7 +102,8 @@
var text = fs.readFileSync(abspath, {encoding: 'utf8'});
var lines = text.split('\n');
- lines = stripBuildOmit(lines);
+ lines = stripBuildIgnore(lines);
+ lines = stripLeadingBlankLines(lines);
var indexAndLines = getIndex(lines);
var index = indexAndLines.index;
lines = indexAndLines.lines;
diff --git a/pgbundle/package.json b/pgbundle/package.json
index 71ef866..d3be8b6 100644
--- a/pgbundle/package.json
+++ b/pgbundle/package.json
@@ -4,17 +4,17 @@
"version": "0.0.1",
"bin": "./bin/pgbundle",
"bugs": {
- "url": "https://github.com/veyron/pgbundle/issues"
+ "url": "https://github.com/veyron/release-issues/issues"
},
"dependencies": {
- "glob": "^4.0.6",
- "lodash": "^2.4.1",
+ "glob": "^4.3.5",
+ "lodash": "^3.0.0",
"minimist": "^1.1.0"
},
- "homepage": "https://github.com/veyron/pgbundle",
+ "homepage": "https://vanadium.googlesource.com/release.js.pgbundle",
"private": true,
"repository": {
"type": "git",
- "url": "https://github.com/veyron/pgbundle.git"
+ "url": "https://vanadium.googlesource.com/release.js.pgbundle"
}
}