Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ohm-builder

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ohm-builder - npm Package Compare versions

Comparing version 0.3.3 to 0.4.0

64

ohm-builder.js
#!/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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc