11'use strict' ;
2- var path = require ( 'path' ) ;
3- var fs = require ( 'fs' ) ;
4-
5- module . exports = {
6- rewrite : rewrite ,
7- rewriteFile : rewriteFile ,
8- appName : appName ,
9- processDirectory : processDirectory ,
10- relativeRequire : relativeRequire
11- } ;
12-
13- function rewriteFile ( args ) {
2+
3+ import path from 'path' ;
4+ import fs from 'fs' ;
5+
6+ export function rewriteFile ( args ) {
147 args . path = args . path || process . cwd ( ) ;
158 var fullPath = path . join ( args . path , args . file ) ;
169
@@ -20,13 +13,13 @@ function rewriteFile (args) {
2013 fs . writeFileSync ( fullPath , body ) ;
2114}
2215
23- function escapeRegExp ( str ) {
16+ function escapeRegExp ( str ) {
2417 return str . replace ( / [ \- \[ \] \/ \{ \} \( \) \* \+ \? \. \\ \^ \$ \| ] / g, '\\$&' ) ;
2518}
2619
27- function rewrite ( args ) {
20+ export function rewrite ( args ) {
2821 // check if splicable is already in the body text
29- var re = new RegExp ( args . splicable . map ( function ( line ) {
22+ var re = new RegExp ( args . splicable . map ( function ( line ) {
3023 return '\s*' + escapeRegExp ( line ) ;
3124 } ) . join ( '\n' ) ) ;
3225
@@ -54,28 +47,19 @@ function rewrite (args) {
5447 spaceStr += ' ' ;
5548 }
5649
57- lines . splice ( otherwiseLineIndex + 1 , 0 , args . splicable . map ( function ( line ) {
50+ lines . splice ( otherwiseLineIndex + 1 , 0 , args . splicable . map ( function ( line ) {
5851 return spaceStr + line ;
5952 } ) . join ( '\n' ) ) ;
6053
6154 return lines . join ( '\n' ) ;
6255}
6356
64- function appName ( self ) {
65- var counter = 0 , suffix = self . options [ 'app-suffix' ] ;
66- // Have to check this because of generator bug #386
67- process . argv . forEach ( function ( val ) {
68- if ( val . indexOf ( '--app-suffix' ) > - 1 ) {
69- counter ++ ;
70- }
71- } ) ;
72- if ( counter === 0 || ( typeof suffix === 'boolean' && suffix ) ) {
73- suffix = 'App' ;
74- }
75- return suffix ? self . _ . classify ( suffix ) : '' ;
57+ export function appSuffix ( self ) {
58+ var suffix = self . options [ 'app-suffix' ] ;
59+ return ( typeof suffix === 'string' ) ? self . _ . classify ( suffix ) : '' ;
7660}
7761
78- function destinationPath ( self , filepath ) {
62+ function destinationPath ( self , filepath ) {
7963 filepath = path . normalize ( filepath ) ;
8064 if ( ! path . isAbsolute ( filepath ) ) {
8165 filepath = path . join ( self . destinationRoot ( ) , filepath ) ;
@@ -84,7 +68,7 @@ function destinationPath (self, filepath) {
8468 return filepath ;
8569}
8670
87- function relativeRequire ( self , to , fr ) {
71+ export function relativeRequire ( self , to , fr ) {
8872 fr = destinationPath ( self , fr ) ;
8973 to = destinationPath ( self , to ) ;
9074 return path . relative ( path . dirname ( fr ) , to )
@@ -93,7 +77,7 @@ function relativeRequire (self, to, fr) {
9377 . replace ( / [ \/ \\ ] i n d e x \. j s $ / , '' ) ; // strip index.js suffix from path
9478}
9579
96- function filterFile ( template ) {
80+ function filterFile ( template ) {
9781 // Find matches for parans
9882 var filterMatches = template . match ( / \( ( [ ^ ) ] + ) \) / g) ;
9983 var filters = [ ] ;
@@ -107,7 +91,7 @@ function filterFile (template) {
10791 return { name : template , filters : filters } ;
10892}
10993
110- function templateIsUsable ( self , filteredFile ) {
94+ function templateIsUsable ( self , filteredFile ) {
11195 var filters = self . filters || self . config . get ( 'filters' ) ;
11296 var enabledFilters = [ ] ;
11397 for ( var key in filters ) {
@@ -121,7 +105,7 @@ function templateIsUsable (self, filteredFile) {
121105 return true ;
122106}
123107
124- function processDirectory ( self , source , destination ) {
108+ export function processDirectory ( self , source , destination ) {
125109 var root = self . isPathAbsolute ( source ) ? source : path . join ( self . sourceRoot ( ) , source ) ;
126110 var files = self . expandFiles ( '**' , { dot : true , cwd : root } ) ;
127111 var dest , src ;
0 commit comments