ohm-builder
Advanced tools
Comparing version 0.3.1 to 0.3.3
@@ -22,23 +22,33 @@ #!/usr/bin/env node | ||
// Replace all ohm tags with inlining the code | ||
var regexString = '<script src=".*.ohm" type="text/ohm-js"></script>'; | ||
var matchString = grep(regexString, inputFile).trim(); | ||
if (!matchString) { // try the other order | ||
regexString = '<script type="text/ohm-js" src=".*.ohm"></script>'; | ||
matchString = grep(regexString, inputFile).trim(); | ||
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; | ||
}); | ||
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(); | ||
}); | ||
} | ||
if (!matchString) { | ||
var output = cat(inputFile); | ||
if (!matchStrings.length) { | ||
console.error('Warn: could not find script tag'); | ||
var output = cat(inputFile); | ||
} else { | ||
var sourceDir = path.dirname(outputFile || inputFile); | ||
var ohmFile = path.join(sourceDir, matchString.match(/src="(.*)"/)[1]); | ||
var ohmGrammar = cat(ohmFile).trim(); | ||
var newTag = matchString | ||
.replace('></script>', '>\n' + ohmGrammar + '\n</script>') | ||
.replace(/\s+src=".*"/, ''); | ||
var output = sed(matchString.trim(), newTag.trim(), inputFile); | ||
if (output.trim() === cat(inputFile).trim()) { | ||
echo('No replacement was made. Internal error.'); | ||
exit(4); | ||
} | ||
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); | ||
} | ||
}); | ||
} | ||
@@ -51,2 +61,2 @@ | ||
console.error('Success!'); | ||
console.warn('Success!'); |
{ | ||
"name": "ohm-builder", | ||
"version": "0.3.1", | ||
"version": "0.3.3", | ||
"description": "Bring ohm to your browser the easy way", | ||
@@ -5,0 +5,0 @@ "main": "ohm-builder.js", |
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
3591
53