@@ -9,53 +9,96 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
99 } ) ;
1010} ;
1111Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
12- exports . validateEslintPrint = exports . validateEslint = void 0 ;
12+ exports . validateEslintPrint = exports . validateEslint = exports . validateRecommendPrint = exports . validateRecommend = exports . validatePackagePrint = exports . validatePackage = exports . validateEnvPrint = exports . validateEnv = exports . validateConfigPrint = exports . validateConfig = void 0 ;
1313const path = require ( "path" ) ;
1414const eslint_1 = require ( "eslint" ) ;
1515const glob = require ( "glob" ) ;
1616const js_binding_1 = require ( "./js-binding" ) ;
1717exports . default = ( ctx ) => {
1818 ctx . registerCommand ( {
19- name : 'doctor ' ,
19+ name : 'dx ' ,
2020 fn ( ) {
2121 return __awaiter ( this , void 0 , void 0 , function * ( ) {
2222 const { appPath, nodeModulesPath, configPath } = ctx . paths ;
23- const { fs, chalk, getUserHomeDir , TARO_CONFIG_FOLDER , TARO_BASE_CONFIG , PROJECT_CONFIG } = ctx . helper ;
23+ const { fs, chalk, PROJECT_CONFIG } = ctx . helper ;
2424 if ( ! configPath || ! fs . existsSync ( configPath ) ) {
2525 console . log ( chalk . red ( `找不到项目配置文件${ PROJECT_CONFIG } ,请确定当前目录是 Taro 项目根目录!` ) ) ;
2626 process . exit ( 1 ) ;
2727 }
28- const configStr = JSON . stringify ( ctx . initialConfig , ( _ , v ) => {
29- if ( typeof v === 'function' ) {
30- return '__function__' ;
31- }
32- return v ;
33- } ) ;
34- let remoteConfigSchemaUrl = 'https://raw.githubusercontent.com/NervJS/taro-doctor/main/assets/config_schema.json' ;
35- let useRemoteConfigSchema = true ;
36- const homedir = getUserHomeDir ( ) ;
37- if ( homedir ) {
38- const taroConfigPath = path . join ( homedir , TARO_CONFIG_FOLDER ) ;
39- const taroConfig = path . join ( taroConfigPath , TARO_BASE_CONFIG ) ;
40- if ( fs . existsSync ( taroConfig ) ) {
41- const config = yield fs . readJSON ( taroConfig ) ;
42- remoteConfigSchemaUrl = config && config . remoteConfigSchemaUrl ? config . remoteConfigSchemaUrl : remoteConfigSchemaUrl ;
43- useRemoteConfigSchema = config && config . useRemoteConfigSchema ? config . useRemoteConfigSchema : useRemoteConfigSchema ;
44- }
45- else {
46- yield fs . createFile ( taroConfig ) ;
47- yield fs . writeJSON ( taroConfig , { remoteConfigSchemaUrl, useRemoteConfigSchema } ) ;
48- }
49- }
50- ( 0 , js_binding_1 . validateEnvPrint ) ( ) ;
51- yield ( 0 , js_binding_1 . validateConfigPrint ) ( configStr , remoteConfigSchemaUrl , useRemoteConfigSchema ) ;
52- ( 0 , js_binding_1 . validatePackagePrint ) ( appPath , nodeModulesPath ) ;
53- ( 0 , js_binding_1 . validateRecommendPrint ) ( appPath ) ;
28+ validateEnvPrint ( ) ;
29+ yield validateConfigPrint ( ctx . initialConfig , ctx . helper ) ;
30+ validatePackagePrint ( appPath , nodeModulesPath ) ;
31+ validateRecommendPrint ( appPath ) ;
5432 yield validateEslintPrint ( ctx . initialConfig , chalk ) ;
5533 } ) ;
5634 } ,
5735 } ) ;
5836} ;
37+ function getValidateConfigParams ( projectConfig , helper ) {
38+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
39+ const configStr = JSON . stringify ( projectConfig , ( _ , v ) => {
40+ if ( typeof v === 'function' ) {
41+ return '__function__' ;
42+ }
43+ return v ;
44+ } ) ;
45+ let remoteSchemaUrl = 'https://raw.githubusercontent.com/NervJS/taro-doctor/main/assets/config_schema.json' ;
46+ let useRemoteSchema = true ;
47+ const homedir = helper . getUserHomeDir ( ) ;
48+ if ( homedir ) {
49+ const taroConfigPath = path . join ( homedir , helper . TARO_CONFIG_FOLDER ) ;
50+ const taroConfig = path . join ( taroConfigPath , helper . TARO_BASE_CONFIG ) ;
51+ if ( helper . fs . existsSync ( taroConfig ) ) {
52+ const config = yield helper . fs . readJSON ( taroConfig ) ;
53+ remoteSchemaUrl = config && config . remoteConfigSchemaUrl ? config . remoteConfigSchemaUrl : remoteSchemaUrl ;
54+ useRemoteSchema = config && config . useRemoteConfigSchema ? config . useRemoteConfigSchema : useRemoteSchema ;
55+ }
56+ else {
57+ yield helper . fs . createFile ( taroConfig ) ;
58+ yield helper . fs . writeJSON ( taroConfig , { remoteSchemaUrl, useRemoteSchema } ) ;
59+ }
60+ }
61+ return { configStr, remoteSchemaUrl, useRemoteSchema } ;
62+ } ) ;
63+ }
64+ function validateConfig ( projectConfig , helper ) {
65+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
66+ const { configStr, remoteSchemaUrl, useRemoteSchema } = yield getValidateConfigParams ( projectConfig , helper ) ;
67+ return ( 0 , js_binding_1 . validateConfig ) ( configStr , remoteSchemaUrl , useRemoteSchema ) ;
68+ } ) ;
69+ }
70+ exports . validateConfig = validateConfig ;
71+ function validateConfigPrint ( projectConfig , helper ) {
72+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
73+ const { configStr, remoteSchemaUrl, useRemoteSchema } = yield getValidateConfigParams ( projectConfig , helper ) ;
74+ return ( 0 , js_binding_1 . validateConfigPrint ) ( configStr , remoteSchemaUrl , useRemoteSchema ) ;
75+ } ) ;
76+ }
77+ exports . validateConfigPrint = validateConfigPrint ;
78+ function validateEnv ( ) {
79+ return ( 0 , js_binding_1 . validateEnv ) ( ) ;
80+ }
81+ exports . validateEnv = validateEnv ;
82+ function validateEnvPrint ( ) {
83+ return ( 0 , js_binding_1 . validateEnvPrint ) ( ) ;
84+ }
85+ exports . validateEnvPrint = validateEnvPrint ;
86+ function validatePackage ( appPath , nodeModulesPath ) {
87+ return ( 0 , js_binding_1 . validatePackage ) ( appPath , nodeModulesPath ) ;
88+ }
89+ exports . validatePackage = validatePackage ;
90+ function validatePackagePrint ( appPath , nodeModulesPath ) {
91+ return ( 0 , js_binding_1 . validatePackagePrint ) ( appPath , nodeModulesPath ) ;
92+ }
93+ exports . validatePackagePrint = validatePackagePrint ;
94+ function validateRecommend ( appPath ) {
95+ return ( 0 , js_binding_1 . validateRecommend ) ( appPath ) ;
96+ }
97+ exports . validateRecommend = validateRecommend ;
98+ function validateRecommendPrint ( appPath ) {
99+ return ( 0 , js_binding_1 . validateRecommendPrint ) ( appPath ) ;
100+ }
101+ exports . validateRecommendPrint = validateRecommendPrint ;
59102function validateEslint ( projectConfig , chalk ) {
60103 return __awaiter ( this , void 0 , void 0 , function * ( ) {
61104 const result = yield validateEslintCore ( projectConfig , chalk ) ;
0 commit comments