@@ -5,6 +5,7 @@ const prettier = require('prettier');
55const chalk = require ( 'chalk' ) ;
66const homedir = require ( 'os' ) . homedir ( ) ;
77const handlebars = require ( 'handlebars' ) . compile ;
8+ const uuid = require ( 'uuid/v4' ) ;
89
910module . exports = spinner => {
1011 const message = text => {
@@ -76,48 +77,34 @@ module.exports = spinner => {
7677 } ) ;
7778 } ,
7879
79- inject : ( { action, params } ) => {
80- const { importString = [ ] , inject = [ ] } = params ;
81-
82- const promises =
83- inject . length > 0
84- ? inject . map (
85- ( filepath , i ) =>
86- new Promise ( ( resolve , reject ) => {
87- const istring = `\n@import '${
88- importString [ i ]
89- } ';`;
90- let content = fs . readFileSync (
91- filepath ,
92- 'utf-8' ,
93- ) ;
94- if ( content . indexOf ( istring ) < 0 ) {
95- content += istring ;
96- fs . writeFile ( filepath , content , error => {
97- if ( error ) {
98- reject ( error ) ;
99- } else {
100- resolve ( {
101- action,
102- filepath,
103- status : 200 ,
104- } ) ;
105- }
106- } ) ;
107- } else {
108- resolve ( {
109- action,
110- filepath,
111- status : 200 ,
112- } ) ;
113- }
114- } ) ,
115- )
116- : [ ] ;
117-
118- return promises . length > 0
119- ? Promise . all ( promises )
120- : new Promise ( resolve => resolve ( { action, status : 200 } ) ) ;
80+ partialOrder : async ( { action, params } ) => {
81+ const { destination, filename, filepath, overwrite } = params ;
82+
83+ message ( `reactium-gulp for ${ chalk . cyan ( filename ) } ...` ) ;
84+
85+ fs . ensureDirSync ( path . normalize ( destination ) ) ;
86+ const baseDir = path . basename ( destination ) ;
87+ const reactumGulp = path . resolve ( destination , 'reactium-gulp.js' ) ;
88+
89+ // Template content
90+ const template = path . normalize (
91+ `${ __dirname } /template/reactium-gulp.hbs` ,
92+ ) ;
93+ const content = handlebars ( fs . readFileSync ( template , 'utf-8' ) ) ( {
94+ ...params ,
95+ id : uuid ( ) ,
96+ pattern : `/${ baseDir } \\/${ filename . replace ( '.scss' , '' ) } /` ,
97+ } ) ;
98+
99+ return new Promise ( ( resolve , reject ) => {
100+ fs . writeFile ( reactumGulp , content , error => {
101+ if ( error ) {
102+ reject ( error . Error ) ;
103+ } else {
104+ resolve ( { action, status : 200 } ) ;
105+ }
106+ } ) ;
107+ } ) ;
121108 } ,
122109 } ;
123110} ;
0 commit comments