@@ -53,22 +53,24 @@ const each = async (array, callback) => {
53
53
}
54
54
}
55
55
56
- /** Log a message from MSG. */
56
+ /**
57
+ * Log a message from the messages config. Parses variables in message.
58
+ *
59
+ * @param {String } type The key of the message to write.
60
+ */
57
61
const logInfo = ( type ) => ( config . messages [ type ] ) ?
58
62
cnsl . describe ( parseVariables ( config . messages [ type ] . join ( '' ) ) ) : false ;
59
63
60
64
/**
61
- * Create the directory for the pattern if it doesn't exist
65
+ * Create the directory for the pattern if it doesn't exist.
62
66
*
63
- * @param {String } dir The directory to write
67
+ * @param {String } dir The directory to write.
64
68
* @param {String } type The pattern type: elements, components, objects
65
- * @param {Function } callback They file writing function
66
- *
67
- * @return {[type] } false if directory exists
69
+ * @param {Function } callback They file writing function.
68
70
*/
69
71
const directory = ( dir , type , callback ) => {
70
72
if ( ! fs . existsSync ( dir ) ) {
71
- fs . mkdirSync ( dir ) ;
73
+ fs . mkdirSync ( dir , { recursive : true } ) ;
72
74
73
75
callback ( true ) ;
74
76
} else {
@@ -77,19 +79,21 @@ const directory = (dir, type, callback) => {
77
79
} ;
78
80
79
81
/**
80
- * Make the file for the pattern if it doesn't exist
82
+ * Make the file for the pattern if it doesn't exist.
81
83
*
82
- * @param {String } dir The directory to write
83
- * @param {String } type The pattern type: elements, components, objects
84
- * @param {String } pattern The name of the pattern
85
- *
86
- * @return {Boolean } false if already exists, true if created
84
+ * @param {String } dir The directory to write.
85
+ * @param {String } type The pattern type: elements, components, objects.
86
+ * @param {String } pattern The name of the pattern.
87
87
*/
88
- const write = ( dir , filetype , callback ) => {
88
+ const write = async ( dir , filetype , callback ) => {
89
89
let file = parseVariables ( config . files [ filetype ] ) ;
90
90
91
91
if ( ! fs . existsSync ( `${ dir } /${ file } ` ) ) {
92
- let content = parseVariables ( config . templates [ filetype ] ) ;
92
+ let ext = config . files [ filetype ] . split ( '.' ) [ 1 ] ;
93
+ let templatePath = resolve ( `config/make/${ filetype } .${ ext } ` , false ) ;
94
+ let template = fs . readFileSync ( templatePath , 'utf8' ) ;
95
+
96
+ let content = parseVariables ( template ) ;
93
97
94
98
fs . writeFile ( `${ dir } /${ file } ` , content , err => {
95
99
if ( err ) {
@@ -108,11 +112,9 @@ const write = (dir, filetype, callback) => {
108
112
/**
109
113
* Delegate to create the pattern directory, if it exists, log message.
110
114
*
111
- * @param {String } type The pattern type
112
- * @param {String } dir The directory to write
113
- * @param {String } pattern The name of the pattern
114
- *
115
- * @return {Boolean } False if nothing is created
115
+ * @param {String } type The pattern type.
116
+ * @param {String } dir The directory to write.
117
+ * @param {String } pattern The name of the pattern.
116
118
*/
117
119
const defaults = ( type , pattern , callback ) => {
118
120
let relative = Path . join ( config . dirs . src , type ) ;
@@ -140,7 +142,7 @@ const defaults = (type, pattern, callback) => {
140
142
} ;
141
143
142
144
/**
143
- * Ask if we want to make the 'config' file .
145
+ * Ask if we want to make the optional files .
144
146
*
145
147
* @param {String } filetype The pattern type: elements, components, objects
146
148
* @param {String } pattern The name of the pattern
@@ -155,7 +157,7 @@ const optional = (filetype, pattern, prompt) => {
155
157
let absolute = Path . join ( config . dirs . base , relative ) ;
156
158
157
159
prompt . question (
158
- `${ alerts . question } Would you like to create a ${ alerts . str . string ( filetype ) } file for ${ alerts . str . string ( pattern ) } ? ( y/n) ` ,
160
+ `${ alerts . question } Make a ${ alerts . str . string ( filetype ) } file for ${ alerts . str . string ( pattern ) } ? y/n ↵ ` ,
159
161
( answer ) => {
160
162
if ( yes ( answer ) )
161
163
write ( absolute , filetype , ( success , file ) => {
@@ -191,7 +193,7 @@ const run = async () => {
191
193
192
194
// Make the standard files, then...
193
195
defaults ( TYPE , PATTERN , ( ) => {
194
- // .. ask to make the option files
196
+ // ... ask to make the option files
195
197
( async ( ) => {
196
198
await each ( config . optional , async ( type ) => {
197
199
await optional ( type , PATTERN , prompt ) ;
@@ -205,7 +207,7 @@ const run = async () => {
205
207
}
206
208
} ;
207
209
208
- /** @type {Object } Export our methods */
210
+ /** @type {Object } Export our methods */
209
211
module . exports = {
210
212
run : run ,
211
213
config : config
0 commit comments