Comparing version 1.1.0 to 1.2.0
'use strict'; | ||
// Polfill Promise for old node versions | ||
require('es6-promise'); | ||
var Path = require('path'); | ||
@@ -10,4 +7,4 @@ var when = require('when'); | ||
var fs = node.liftAll(require('fs')); | ||
var accord = require('accord'); | ||
var minify = require('./minify'); | ||
@@ -85,2 +82,3 @@ var extensionMap = {}; | ||
adapters: loadedAdapters, | ||
isMinifiable: minify.isMinifiable, | ||
read: function (pathName, options) { | ||
@@ -91,3 +89,4 @@ options = options || {}; | ||
var adapters = extensionMap[Path.extname(pathName)]; | ||
var extension = Path.extname(pathName); | ||
var adapters = extensionMap[extension]; | ||
var adapter = adapters && adapters[0]; | ||
@@ -106,12 +105,16 @@ | ||
var addExtension = function (compiled) { | ||
compiled.extension = adapter.output; | ||
var addInfo = function(compiled) { | ||
compiled.extension = '.' + adapter.output; | ||
compiled.inputPath = pathName; | ||
return when.resolve(compiled); | ||
}; | ||
continuation = adapter.renderFile(pathName, transpilerOptions).then(addExtension); | ||
continuation = adapter.renderFile(pathName, transpilerOptions).then(addInfo); | ||
} else { | ||
continuation = fs.readFile(pathName, 'utf8').then(function (source) { | ||
return when.resolve({ | ||
result: source | ||
result: source, | ||
extension: extension, | ||
inputPath: pathName | ||
}); | ||
@@ -121,4 +124,10 @@ }); | ||
if (options.minify) { | ||
continuation = continuation.then(function(compiled) { | ||
return minify(compiled, options); | ||
}); | ||
} | ||
return continuation; | ||
} | ||
}; |
{ | ||
"name": "baby-tolk", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A file reader that promises to translate non-web assets to web assets given the available transpilers, sourcemaps and all", | ||
@@ -42,3 +42,6 @@ "main": "lib/baby-tolk.js", | ||
"accord": "0.20.3", | ||
"clean-css": "3.4.6", | ||
"es6-promise": "3.0.2", | ||
"html-minifier": "1.0.0", | ||
"uglify-js": "2.5.0", | ||
"when": "3.7.3" | ||
@@ -45,0 +48,0 @@ }, |
@@ -11,3 +11,3 @@ Baby Tolk | ||
Baby Tolk is a "do the right thing" tool for transpiling. It reads a file from the file system, transpiles it (including sourcemaps where supported) with the available transpilers. | ||
Baby Tolk is a "do the right thing" tool for transpiling. It reads a file from the file system, transpiles it (including sourcemaps where supported) with the available transpilers. It can also optionally minify the output. | ||
@@ -30,3 +30,3 @@ Returns a promise that resolves with the resulting transpiler output. | ||
Out of the box this won't transpile anything. In order to do more, for example babel and sass, also do this: | ||
Out of the box this won't transpile anything (but it can minify html, css and JS). In order to do more, for example babel and sass, also do this: | ||
@@ -37,8 +37,8 @@ ``` | ||
Now you are ready to start reading files from the file system. Tolk automatically loads the transpilers it has access to in the scope it is run in. | ||
Now you are ready to start reading files from the file system. Baby Tolk automatically loads the transpilers it has access to in the scope it is run in. | ||
```js | ||
var tolk = require('tolk'); | ||
```javascript | ||
var babyTolk = require('baby-tolk'); | ||
tolk.read('path/to/stylesheet.scss').done(function (compiled) { | ||
babyTolk.read('path/to/stylesheet.scss').then(function (compiled) { | ||
// compiled.result is the transpiled output as a string | ||
@@ -56,3 +56,26 @@ console.log(compiled.result); | ||
Want the output to be minified? | ||
```javascript | ||
babyTolk.read('path/to/stylesheet.scss', {minify: true}).then([success], [fail]); | ||
``` | ||
You can also minify vanilla css/js/html files without the transpilation step. | ||
```javascript | ||
babyTolk.read('path/to/app.js', {minify: true}).then([success], [fail]); | ||
``` | ||
It's also possible to turn source-maps off. | ||
```javascript | ||
babyTolk.read('path/to/app.js', {sourceMaps: false}).then([success], [fail]); | ||
``` | ||
License | ||
@@ -59,0 +82,0 @@ ------- |
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
11593
4
197
89
6
+ Addedclean-css@3.4.6
+ Addedhtml-minifier@1.0.0
+ Addeduglify-js@2.5.0
+ Addedamdefine@1.0.1(transitive)
+ Addedasync@0.2.10(transitive)
+ Addedcamel-case@1.2.2(transitive)
+ Addedchange-case@2.3.1(transitive)
+ Addedclean-css@3.4.6(transitive)
+ Addedcli@0.11.3(transitive)
+ Addedcommander@2.8.1(transitive)
+ Addedconcat-stream@1.5.2(transitive)
+ Addedconstant-case@1.1.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddot-case@1.1.2(transitive)
+ Addedexit@0.1.2(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedhtml-minifier@1.0.0(transitive)
+ Addedis-lower-case@1.1.3(transitive)
+ Addedis-upper-case@1.1.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedlower-case@1.1.4(transitive)
+ Addedlower-case-first@1.0.2(transitive)
+ Addedparam-case@1.1.2(transitive)
+ Addedpascal-case@1.1.2(transitive)
+ Addedpath-case@1.1.2(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedreadable-stream@2.0.6(transitive)
+ Addedrelateurl@0.2.7(transitive)
+ Addedsentence-case@1.1.3(transitive)
+ Addedsnake-case@1.1.2(transitive)
+ Addedsource-map@0.4.4(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedswap-case@1.1.2(transitive)
+ Addedtitle-case@1.1.2(transitive)
+ Addedtypedarray@0.0.7(transitive)
+ Addeduglify-js@2.5.0(transitive)
+ Addedupper-case@1.1.3(transitive)
+ Addedupper-case-first@1.1.2(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedyargs@3.5.4(transitive)
- Removedalign-text@0.1.4(transitive)
- Removedcenter-align@0.1.3(transitive)
- Removedcliui@2.1.0(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedkind-of@3.2.2(transitive)
- Removedlazy-cache@1.0.4(transitive)
- Removedlongest@1.0.1(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedright-align@0.1.3(transitive)
- Removeduglify-js@2.8.29(transitive)
- Removedyargs@3.10.0(transitive)