11const path = require ( 'path' )
22const { execSync } = require ( 'child_process' )
33const fs = require ( 'fs-extra' )
4- const { templatePath } = require ( 'crd-utils' )
4+ const { templatePath, resolveApp } = require ( 'crd-utils' )
55const copyTemplate = require ( 'copy-template-dir' )
66const paths = require ( '../conf/path' )
77
@@ -28,19 +28,24 @@ module.exports = function (params) {
2828 if ( ! fs . pathExistsSync ( defaultTemplatePath ) ) {
2929 execSync ( 'mkdir temp && cd temp && yarn add crd-templates -D' )
3030 }
31- copyTemplate ( defaultTemplatePath , outDir , {
32- name : projectName ,
33- crdVersion : CRD_VERSION ,
34- } , ( err , createdFiles ) => {
35- if ( err ) return log ( `Copy Tamplate Error: ${ err } !!!` . red )
36- createdFiles . sort ( ) . forEach ( ( createdFile ) => {
37- log ( ` ${ 'create' . green } ${ createdFile . replace ( paths . projectPath , '' ) } ` )
31+ const templatePathInTemp = resolveApp ( 'temp/node_modules/crd-templates/default' )
32+ if ( fs . pathExistsSync ( templatePathInTemp ) ) {
33+ copyTemplate ( templatePathInTemp , outDir , {
34+ name : projectName ,
35+ crdVersion : CRD_VERSION ,
36+ } , ( err , createdFiles ) => {
37+ if ( err ) return log ( `Copy Tamplate Error: ${ err } !!!` . red )
38+ createdFiles . sort ( ) . forEach ( ( createdFile ) => {
39+ log ( ` ${ 'create' . green } ${ createdFile . replace ( paths . projectPath , '' ) } ` )
40+ } )
41+ // to hack https://github.com/yoshuawuyts/copy-template-dir/issues/16
42+ execSync ( `cp -r ${ templatePathInTemp } /.github ${ outDir } ` )
43+ execSync ( 'rm -rf temp' )
44+ log ( '\n initialization finished!\n' . green )
45+ const cmdstr = `cd ${ projectName } && yarn && yarn start` . cyan
46+ log ( ` Run the ${ cmdstr } to start the website.\n\n` )
3847 } )
39- // this is to hack https://github.com/yoshuawuyts/copy-template-dir/issues/16
40- execSync ( `cp -r ${ defaultTemplatePath } /.github ${ outDir } ` )
41- execSync ( 'rm -rf temp' )
42- log ( '\n initialization finished!\n' . green )
43- const cmdstr = `cd ${ projectName } && yarn && yarn start` . cyan
44- log ( ` Run the ${ cmdstr } to start the website.\n\n` )
45- } )
48+ } else {
49+ log ( ` ❎ crd-templates install fail.\n\n` )
50+ }
4651}
0 commit comments