1
1
'use strict' ;
2
2
3
- var fs = require ( 'fs' ) ;
4
- var path = require ( 'path' ) ;
5
- var log = require ( 'db-migrate-shared' ) . log ;
6
- var inflection = require ( 'inflection' ) ;
7
- var Promise = require ( 'bluebird' ) ;
8
- var lpad = require ( 'db-migrate-shared' ) . util . lpad ;
3
+ const fs = require ( 'fs' ) ;
4
+ const path = require ( 'path' ) ;
5
+ const log = require ( 'db-migrate-shared' ) . log ;
6
+ const inflection = require ( 'inflection' ) ;
7
+ const Promise = require ( 'bluebird' ) ;
8
+ const lpad = require ( 'db-migrate-shared' ) . util . lpad ;
9
9
10
10
function formatPath ( dir , name ) {
11
11
return path . join ( dir , name ) ;
@@ -31,8 +31,8 @@ function formatTitle (title) {
31
31
}
32
32
33
33
function parseDate ( name ) {
34
- var date = new Date ( ) ;
35
- var match = name . match ( / ( \d { 4 } ) ( \d { 2 } ) ( \d { 2 } ) ( \d { 2 } ) ( \d { 2 } ) ( \d { 2 } ) - [ ^ . ] + / ) ;
34
+ let date = new Date ( ) ;
35
+ const match = name . match ( / ( \d { 4 } ) ( \d { 2 } ) ( \d { 2 } ) ( \d { 2 } ) ( \d { 2 } ) ( \d { 2 } ) - [ ^ . ] + / ) ;
36
36
date . setUTCFullYear ( match [ 1 ] ) ;
37
37
date . setUTCDate ( match [ 3 ] ) ;
38
38
date . setUTCMonth ( match [ 2 ] - 1 ) ;
@@ -43,38 +43,41 @@ function parseDate (name) {
43
43
}
44
44
45
45
function parseTitle ( name ) {
46
- var match = name . match ( / \d { 14 } - ( [ ^ . ] + ) / ) ;
47
- var dashed = match [ 1 ] ;
48
- return inflection . humanize ( dashed , true ) ;
46
+ const match = name . match ( / \d { 14 } - ( [ ^ . ] + ) / ) ;
47
+ return inflection . humanize ( match [ 1 ] , true ) ;
49
48
}
50
49
51
- var filesRegEx = / \. j s $ / ;
52
-
53
- var File = {
54
- init : function ( ) {
55
- if ( arguments . length >= 3 ) {
56
- this . title = arguments [ 0 ] ;
57
- this . date = arguments [ 2 ] ;
58
- this . name = this . formatName ( this . title , this . date ) ;
59
- this . path = this . formatPath ( arguments [ 1 ] , this . name ) ;
60
- this . templateType = arguments [ 3 ] ;
61
- this . internals = arguments [ 4 ] ;
62
- } else if ( arguments . length === 2 ) {
63
- this . path = arguments [ 0 ] ;
64
- this . name = this . parseName ( this . path ) ;
65
- this . date = this . parseDate ( this . name ) ;
66
- this . title = this . parseTitle ( this . name ) ;
67
- this . internals = arguments [ 1 ] ;
68
- }
69
-
70
- this . _super ( this . internals ) ;
71
- } ,
50
+ const filesRegEx = / \. j s $ / ;
51
+
52
+ const File = function ( ) {
53
+ if ( arguments . length >= 3 ) {
54
+ this . title = arguments [ 0 ] ;
55
+ this . date = arguments [ 2 ] ;
56
+ this . name = this . formatName ( this . title , this . date ) ;
57
+ this . path = this . formatPath ( arguments [ 1 ] , this . name ) ;
58
+ this . templateType = arguments [ 3 ] ;
59
+ this . internals = arguments [ 4 ] ;
60
+ } else if ( arguments . length === 2 ) {
61
+ this . path = arguments [ 0 ] ;
62
+ this . name = this . parseName ( this . path ) ;
63
+ this . date = this . parseDate ( this . name ) ;
64
+ this . title = this . parseTitle ( this . name ) ;
65
+ this . internals = arguments [ 1 ] ;
66
+ }
67
+
68
+ this . _super ( this . internals ) ;
69
+ } ;
72
70
71
+ File . protoype = {
73
72
parseName : function ( path ) {
74
- var match = path . match ( / ( \d { 14 } - [ ^ . ] + ) (?: \. * ?) ? / ) ;
73
+ const match = path . match ( / ( \d { 14 } - [ ^ . ] + ) (?: \. * ?) ? / ) ;
75
74
return match [ 1 ] ;
76
75
} ,
77
76
77
+ get : function ( ) {
78
+ return this . _required || ( this . _required = require ( this . path ) ) ;
79
+ } ,
80
+
78
81
parseTitle : parseTitle ,
79
82
parseDate : parseDate ,
80
83
formatTitle : formatTitle ,
@@ -83,7 +86,7 @@ var File = {
83
86
} ;
84
87
85
88
File . registerHook = function ( Plugin , prefix , internals ) {
86
- var plugin = Plugin . hook ( prefix + ':hook:require' ) ;
89
+ const plugin = Plugin . hook ( prefix + ':hook:require' ) ;
87
90
internals . parser = internals . parser || {
88
91
filesRegEx : filesRegEx ,
89
92
extensions : 'js'
0 commit comments