1
- import fs from 'fs' ;
2
- import handlebars from ' handlebars' ;
3
- import mkdirp from ' mkdirp' ;
4
- import { sprintf } from ' sprintf-js' ;
5
- import urlapi from ' url' ;
1
+ import fs from "fs" ;
2
+ import handlebars from " handlebars" ;
3
+ import mkdirp from " mkdirp" ;
4
+ import { sprintf } from " sprintf-js" ;
5
+ import urlapi from " url" ;
6
6
7
7
export default class {
8
8
templates = { } ;
9
9
10
- constructor ( { hydraPrefix, templateDirectory} ) {
10
+ constructor ( { hydraPrefix, templateDirectory } ) {
11
11
this . hydraPrefix = hydraPrefix ;
12
12
this . templateDirectory = templateDirectory ;
13
13
14
- this . registerTemplates ( '' , [ ' _entrypoint.js' ] ) ;
14
+ this . registerTemplates ( "" , [ " _entrypoint.js" ] ) ;
15
15
}
16
16
17
17
registerTemplates ( basePath , paths ) {
18
18
for ( let path of paths ) {
19
- this . templates [ path ] = handlebars . compile ( fs . readFileSync ( `${ this . templateDirectory } /${ basePath } ${ path } ` ) . toString ( ) ) ;
19
+ this . templates [ path ] = handlebars . compile (
20
+ fs
21
+ . readFileSync ( `${ this . templateDirectory } /${ basePath } ${ path } ` )
22
+ . toString ( )
23
+ ) ;
20
24
}
21
25
}
22
26
@@ -31,7 +35,11 @@ export default class {
31
35
}
32
36
33
37
createFileFromPattern ( pattern , dir , lc , context ) {
34
- this . createFile ( sprintf ( pattern , 'foo' ) , sprintf ( `${ dir } /${ pattern } ` , lc ) , context ) ;
38
+ this . createFile (
39
+ sprintf ( pattern , "foo" ) ,
40
+ sprintf ( `${ dir } /${ pattern } ` , lc ) ,
41
+ context
42
+ ) ;
35
43
}
36
44
37
45
createFile ( template , dest , context = { } , warn = true ) {
@@ -46,41 +54,46 @@ export default class {
46
54
47
55
createEntrypoint ( apiEntry , dest ) {
48
56
const url = urlapi . parse ( apiEntry ) ;
49
- const { protocol, host, pathname} = url ;
50
-
51
- this . createFile ( '_entrypoint.js' , dest , { host : `${ protocol } //${ host } ` , path : pathname } , false ) ;
57
+ const { protocol, host, pathname } = url ;
58
+
59
+ this . createFile (
60
+ "_entrypoint.js" ,
61
+ dest ,
62
+ { host : `${ protocol } //${ host } ` , path : pathname } ,
63
+ false
64
+ ) ;
52
65
}
53
66
54
67
getHtmlInputTypeFromField ( field ) {
55
68
switch ( field . id ) {
56
- case ' http://schema.org/email' :
57
- return { type : ' email' } ;
69
+ case " http://schema.org/email" :
70
+ return { type : " email" } ;
58
71
59
- case ' http://schema.org/url' :
60
- return { type : ' url' } ;
72
+ case " http://schema.org/url" :
73
+ return { type : " url" } ;
61
74
}
62
75
63
76
switch ( field . range ) {
64
- case ' http://www.w3.org/2001/XMLSchema#integer' :
65
- return { type : ' number' } ;
77
+ case " http://www.w3.org/2001/XMLSchema#integer" :
78
+ return { type : " number" } ;
66
79
67
- case ' http://www.w3.org/2001/XMLSchema#decimal' :
68
- return { type : ' number' , step : ' 0.1' } ;
80
+ case " http://www.w3.org/2001/XMLSchema#decimal" :
81
+ return { type : " number" , step : " 0.1" } ;
69
82
70
- case ' http://www.w3.org/2001/XMLSchema#boolean' :
71
- return { type : ' checkbox' } ;
83
+ case " http://www.w3.org/2001/XMLSchema#boolean" :
84
+ return { type : " checkbox" } ;
72
85
73
- case ' http://www.w3.org/2001/XMLSchema#date' :
74
- return { type : ' date' } ;
86
+ case " http://www.w3.org/2001/XMLSchema#date" :
87
+ return { type : " date" } ;
75
88
76
- case ' http://www.w3.org/2001/XMLSchema#time' :
77
- return { type : ' time' } ;
89
+ case " http://www.w3.org/2001/XMLSchema#time" :
90
+ return { type : " time" } ;
78
91
79
- case ' http://www.w3.org/2001/XMLSchema#dateTime' :
80
- return { type : ' dateTime' } ;
92
+ case " http://www.w3.org/2001/XMLSchema#dateTime" :
93
+ return { type : " dateTime" } ;
81
94
82
95
default :
83
- return { type : ' text' } ;
96
+ return { type : " text" } ;
84
97
}
85
98
}
86
99
@@ -92,7 +105,7 @@ export default class {
92
105
field . name = apiField . name ;
93
106
field . description = apiField . description . replace ( / " / g, "'" ) ; // fix for Form placeholder description
94
107
95
- fields . push ( field )
108
+ fields . push ( field ) ;
96
109
}
97
110
98
111
return fields ;
0 commit comments