broccoli-ractive
Advanced tools
Comparing version 0.1.4 to 0.1.5
124
index.js
var Promise = require( 'es6-promise' ).Promise, | ||
quickTemp = require( 'quick-temp' ), | ||
Writer = require( 'broccoli-writer' ), | ||
Ractive = require( 'ractive' ), | ||
@@ -18,5 +18,7 @@ rcu = require( 'rcu' ), | ||
module.exports = RactiveCompiler; | ||
rcu.init( Ractive ); | ||
var RactiveCompiler, templates = {}, builders = {}; | ||
var templates = {}, builders = {}; | ||
@@ -46,3 +48,3 @@ promisify = (function ( slice ) { | ||
RactiveCompiler = function ( inputTree, options ) { | ||
function RactiveCompiler ( inputTree, options ) { | ||
var key; | ||
@@ -71,72 +73,57 @@ | ||
} | ||
}; | ||
} | ||
RactiveCompiler.prototype = { | ||
constructor: RactiveCompiler, | ||
RactiveCompiler.prototype = Object.create( Writer.prototype ); | ||
RactiveCompiler.prototype.constructor = RactiveCompiler; | ||
read: function (readTree) { | ||
var self = this; | ||
RactiveCompiler.prototype.write = function ( readTree, destDir ) { | ||
var self = this; | ||
quickTemp.makeOrRemake( this, 'ractiveCompiler' ); | ||
return readTree( self.inputTree ).then( function ( srcDir ) { | ||
return this.write( readTree, this.ractiveCompiler ).then( function () { | ||
return self.ractiveCompiler; | ||
// glob all input file patterns, and create components from them | ||
var promises = self.files.map( resolvePattern ).map( function ( pattern ) { | ||
return glob( pattern ).then( createComponents ); | ||
}); | ||
}, | ||
cleanup: function () { | ||
quickTemp.remove( this, 'ractive-compiler' ); | ||
}, | ||
return Promise.all( promises ); | ||
write: function ( readTree, destDir ) { | ||
var self = this; | ||
function resolvePattern ( pattern ) { | ||
return path.join( srcDir, pattern ); | ||
} | ||
return readTree( self.inputTree ).then( function ( srcDir ) { | ||
function createComponents ( matches ) { | ||
var promises = matches.map( function ( componentPath ) { | ||
var relativePath, outputPath, outputFolder; | ||
// glob all input file patterns, and create components from them | ||
var promises = self.files.map( resolvePattern ).map( function ( pattern ) { | ||
return glob( pattern ).then( createComponents ); | ||
}); | ||
relativePath = path.relative( srcDir, componentPath ); | ||
return Promise.all( promises ); | ||
outputPath = path.join( destDir, self.destDir, relativePath.replace( fileExtension, '.js' ) ); | ||
outputFolder = path.join( outputPath, '..' ); | ||
function resolvePattern ( pattern ) { | ||
return path.join( srcDir, pattern ); | ||
} | ||
return createComponent( componentPath ).then( writeComponent ); | ||
function createComponents ( matches ) { | ||
var promises = matches.map( function ( componentPath ) { | ||
var relativePath, outputPath, outputFolder; | ||
function writeComponent ( built ) { | ||
return mkdirp( outputFolder ).then( function () { | ||
return writeFile( outputPath, built ); | ||
}); | ||
} | ||
}); | ||
relativePath = path.relative( srcDir, componentPath ); | ||
return Promise.all( promises ); | ||
} | ||
}); | ||
outputPath = path.join( destDir, self.destDir, relativePath.replace( fileExtension, '.js' ) ); | ||
outputFolder = path.join( outputPath, '..' ); | ||
function createComponent ( componentPath ) { | ||
return readFile( componentPath ).then( function ( result ) { | ||
var source, parsed, builder, built; | ||
return createComponent( componentPath ).then( writeComponent ); | ||
source = result.toString(); | ||
parsed = rcu.parse( source ); | ||
function writeComponent ( built ) { | ||
return mkdirp( outputFolder ).then( function () { | ||
return writeFile( outputPath, built ); | ||
}); | ||
} | ||
}); | ||
builder = builders[ self.type ]; | ||
built = builder( parsed ); | ||
return Promise.all( promises ); | ||
} | ||
return built; | ||
}); | ||
function createComponent ( componentPath ) { | ||
return readFile( componentPath ).then( function ( result ) { | ||
var source, parsed, builder, built; | ||
source = result.toString(); | ||
parsed = rcu.parse( source ); | ||
builder = builders[ self.type ]; | ||
built = builder( parsed ); | ||
return built; | ||
}); | ||
} | ||
} | ||
@@ -186,11 +173,16 @@ }; | ||
builders.amd = function ( definition ) { | ||
var builtModule = '' + | ||
'define([' + | ||
definition.imports.map( getImportPath ).concat( '"require"', '"ractive"' ).join( ',\n' ) + | ||
'], function(' + | ||
definition.imports.map( getImportName ).concat( 'require', 'Ractive' ).join( ',\n' ) + | ||
var dependencies, builtModule; | ||
dependencies = definition.imports.map( getImportPath ).concat( definition.modules ); | ||
builtModule = '' + | ||
'define([\n\t' + | ||
dependencies.map( quote ).concat( '"require"', '"ractive"' ).join( ',\n\t' ) + '\n' + | ||
'], function(\n\t' + | ||
dependencies.map( getDependencyName ).concat( 'require', 'Ractive' ).join( ',\n\t' ) + '\n' + | ||
'){\n' + | ||
createBody( definition ) + | ||
'return __export__;'; | ||
'return __export__;\n' + | ||
'});'; | ||
@@ -200,8 +192,12 @@ return builtModule; | ||
function getImportPath ( imported ) { | ||
return '\t"' + imported.href.replace( fileExtension, '' ) + '"'; | ||
return imported.href.replace( fileExtension, '' ); | ||
} | ||
function getImportName ( imported, i ) { | ||
return '\t__import' + i + '__'; | ||
function quote ( str ) { | ||
return '"' + str + '"'; | ||
} | ||
function getDependencyName ( imported, i ) { | ||
return '__import' + i + '__'; | ||
} | ||
}; | ||
@@ -208,0 +204,0 @@ |
{ | ||
"name": "broccoli-ractive", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"author": "Rich-Harris", | ||
@@ -18,4 +18,4 @@ "main": "index.js", | ||
"glob": "^4.0.0", | ||
"quick-temp": "^0.1.2", | ||
"clean-css": "^2.1.8" | ||
"clean-css": "^2.1.8", | ||
"broccoli-writer": "^0.1.1" | ||
}, | ||
@@ -22,0 +22,0 @@ "devDependencies": { |
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
477421
13477
+ Addedbroccoli-writer@^0.1.1
+ Addedbroccoli-writer@0.1.1(transitive)
+ Addedrsvp@3.6.2(transitive)
- Removedquick-temp@^0.1.2