@@ -16,11 +16,29 @@ const QUESTIONS = [
1616 return 'Project name may only include letters or numbers.' ;
1717 }
1818 }
19+ } ,
20+ {
21+ name : 'typescript' ,
22+ type : 'confirm' ,
23+ message : 'Do you want to attach TypeScript types?'
1924 }
2025] ;
2126
22- inquirer . prompt ( QUESTIONS ) . then ( async ( { componentmapper } ) => {
23- console . log ( 'Creating ' , componentmapper , '-component-mapper' ) ;
27+ inquirer . prompt ( QUESTIONS ) . then ( async ( { componentmapper, typescript } ) => {
28+ const successmessage = `Next steps:
29+
30+ 1. Update styles in "packages/${ componentmapper } -component-mapper/demo/index.html"
31+ 2. Add dependencies in "packages/${ componentmapper } -component-mapper/package.json",
32+ 3. Mark the dependencies as globals/external in "packages/${ componentmapper } -component-mapper/rollup.config.js"
33+ 4. (optional) Transform import to allow threeshake (bundle size optimization) in "packages/common/babel.config.js"
34+ 5. Have a fun and make some magic! :-)
35+
36+ Please visit https://data-driven-forms.org for more information.
37+
38+ (After your mapper is done, consider adding it to the documentation page.)
39+ ` ;
40+
41+ console . log ( 'Creating ' , componentmapper , '-component-mapper' , typescript ? ' with TypeScript' : '' ) ;
2442
2543 console . log ( 'Copying template' ) ;
2644 await ncp ( './templates/component-mapper' , `./packages/${ componentmapper } -component-mapper` , { } , async ( ) => {
@@ -43,18 +61,36 @@ inquirer.prompt(QUESTIONS).then(async ({ componentmapper }) => {
4361 console . error ( 'Error occurred:' , e ) ;
4462 }
4563
46- console . log ( `
47- Next steps:
48-
49- 1. Update styles in "packages/${ componentmapper } -component-mapper/demo/index.html"
50- 2. Add dependencies in "packages/${ componentmapper } -component-mapper/package.json",
51- 3. Mark the dependencies as globals/external in "packages/${ componentmapper } -component-mapper/rollup.config.js"
52- 4. (optional) Transform import to allow threeshake (bundle size optimization) in "packages/common/babel.config.js"
53- 5. Have a fun and make some magic! :-)
64+ const optionTypeScriptPath = {
65+ files : [ path . resolve ( __dirname , `../packages/${ componentmapper } -component-mapper/package.json` ) ] ,
66+ from : / \{ \{ t y p i n g s p a t h \} \} / g,
67+ to : typescript ? '\n "typings": "dist/cjs/index.d.ts",' : ''
68+ } ;
69+ const optionTypeScriptCommand = {
70+ files : [ path . resolve ( __dirname , `../packages/${ componentmapper } -component-mapper/package.json` ) ] ,
71+ from : / \{ \{ b u i l d t y p i n g s c m d \} \} / g,
72+ to : typescript ? ' && yarn build:typings' : ''
73+ } ;
74+ const optionTypeScriptScript = {
75+ files : [ path . resolve ( __dirname , `../packages/${ componentmapper } -component-mapper/package.json` ) ] ,
76+ from : / \{ \{ b u i l d t y p i n g s s c r i p t \} \} / g,
77+ to : typescript ? '\n "build:typings": "node ../../scripts/copy-files.js",' : ''
78+ } ;
5479
55- Please visit https://data-driven-forms.org for more information.
80+ try {
81+ await replace ( optionTypeScriptPath ) ;
82+ await replace ( optionTypeScriptCommand ) ;
83+ await replace ( optionTypeScriptScript ) ;
84+ } catch ( e ) {
85+ console . error ( 'Error occurred when replacing typescript variables:' , e ) ;
86+ }
5687
57- (After your mapper is done, consider adding it to the documentation page.)
58- ` ) ;
88+ if ( typescript ) {
89+ await ncp ( './templates/typings' , `./packages/${ componentmapper } -component-mapper` , { } , ( ) => {
90+ console . log ( successmessage ) ;
91+ } ) ;
92+ } else {
93+ console . log ( successmessage ) ;
94+ }
5995 } ) ;
6096} ) ;
0 commit comments