ohm-builder
Advanced tools
Comparing version 0.3.3 to 0.4.0
#!/usr/bin/env node | ||
require('shelljs/global'); | ||
var shell = require('shelljs'); | ||
var path = require('path'); | ||
config.fatal = true; | ||
if (process.argv.length < 3) { | ||
echo('Usage: ' + path.basename(process.argv[1]) + ' <inputFile>'); | ||
echo(' or ' + path.basename(process.argv[1]) + ' <inputFile> <html_output>'); | ||
exit(1); | ||
console.error('Usage: ' + path.basename(process.argv[1]) + ' <inputFile>'); | ||
console.error(' or ' + path.basename(process.argv[1]) + ' <inputFile> <html_output>'); | ||
process.exit(1); | ||
} | ||
@@ -17,45 +15,27 @@ | ||
if (inputFile === outputFile) { | ||
echo('Must provide different file names'); | ||
exit(2); | ||
console.error('Must provide different file names'); | ||
process.exit(2); | ||
} | ||
// Replace all ohm tags with inlining the code | ||
var regex = /<script\s+type="text\/ohm-js"\s+src=".*\.ohm"><\/script>/; | ||
var matchStrings = grep(regex, inputFile).trim().split('\n').map(function(x) { | ||
return x.trim(); | ||
}).filter(function (x) { | ||
if (x) return x; | ||
var contents = shell.cat(inputFile).toString(); | ||
var jsdom = require('jsdom'); | ||
var doc = jsdom.jsdom(contents); | ||
var window = doc.defaultView; | ||
var $ = require('jquery')(window); | ||
var sourceDir = path.dirname(outputFile || inputFile); | ||
$('script[type="text/ohm-js"]').each(function (_, b) { | ||
var node = $(b); | ||
var fname = node.attr('src'); | ||
var grammarContents = shell.cat(path.join(sourceDir, fname)); | ||
node.text('\n' + grammarContents); // prefix with whitespace | ||
node.removeAttr('src'); | ||
}); | ||
if (!matchStrings.length) { // try the other order | ||
regex = /<script\s+src=".*\.ohm"\s+type="text\/ohm-js"><\/script>/; | ||
matchStrings = grep(regex, inputFile).split('\n').map(function(x) { | ||
return x.trim(); | ||
}); | ||
} | ||
var output = cat(inputFile); | ||
if (!matchStrings.length) { | ||
console.error('Warn: could not find script tag'); | ||
} else { | ||
matchStrings.forEach(function (matchString) { | ||
if (!matchString) | ||
return; | ||
var sourceDir = path.dirname(outputFile || inputFile); | ||
var ohmFile = path.join(sourceDir, matchString.match(/src="([^"]+)"/)[1]); | ||
var ohmGrammar = cat(ohmFile).trim(); | ||
var newTag = matchString | ||
.replace(/\s+src="[^"]*"/, '') | ||
.replace('></script>', '>\n' + ohmGrammar + '\n</script>'); | ||
output = output.replace(matchString.trim(), newTag.trim()); | ||
if (output.trim() === cat(inputFile).trim()) { | ||
echo('No replacement was made. Internal error.'); | ||
exit(4); | ||
} | ||
}); | ||
} | ||
var output = jsdom.serializeDocument(doc); | ||
if (outputFile) | ||
output.to(outputFile); | ||
(new shell.ShellString(output)).to(outputFile); | ||
else | ||
echo(output); | ||
console.log(output); | ||
console.warn('Success!'); |
{ | ||
"name": "ohm-builder", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"description": "Bring ohm to your browser the easy way", | ||
"main": "ohm-builder.js", | ||
"scripts": { | ||
"test": "node ./scripts/run-tests.js" | ||
"test": "node ./scripts/run-tests.js", | ||
"posttest": "npm run lint", | ||
"lint": "eslint .", | ||
"release:major": "release major", | ||
"release:minor": "release minor", | ||
"release:patch": "release patch" | ||
}, | ||
@@ -33,4 +38,10 @@ "files": [ | ||
"dependencies": { | ||
"jquery": "^3.0.0", | ||
"jsdom": "^9.3.0", | ||
"shelljs": "^0.7.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^2.13.1", | ||
"shelljs-release": "^0.1.3" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3262
3
2
33
+ Addedjquery@^3.0.0
+ Addedjsdom@^9.3.0
+ Addedabab@1.0.4(transitive)
+ Addedacorn@4.0.13(transitive)
+ Addedacorn-globals@3.1.0(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedarray-equal@1.0.2(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcontent-type-parser@1.0.2(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedcssom@0.3.8(transitive)
+ Addedcssstyle@0.2.37(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedescodegen@1.14.3(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestraverse@4.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhtml-encoding-sniffer@1.0.2(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjquery@3.7.1(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjsdom@9.12.0(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addednwmatcher@1.4.4(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedparse5@1.5.1(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedsymbol-tree@3.2.4(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwebidl-conversions@3.0.14.0.2(transitive)
+ Addedwhatwg-encoding@1.0.5(transitive)
+ Addedwhatwg-url@4.8.0(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedxml-name-validator@2.0.1(transitive)