11import { createModel } from '@rematch/core' ;
22import { RootModel } from './' ;
33import { getDirectoryTrees , getFileContent } from '../servers/unpkg' ;
4- import { dataFilesSort } from '../utils/utils' ;
4+ import { dataFilesSort } from '../utils/utils' ;
55
66export interface Files {
77 path : string ;
@@ -14,33 +14,35 @@ export interface Files {
1414}
1515
1616export interface PackageJSON {
17- name : string ;
18- version : string ;
19- description : string ;
20- author : string ;
21- homepage ?: string ;
22- repository ?: {
23- type ?: string ;
24- url ?: string ;
25- } | string ;
26- license : string ;
27- main : string ;
28- module : string ;
29- files : string [ ] ;
30- publishConfig ?: {
31- [ key : string ] : any ;
32- }
33- keywords : string [ ] ;
34- peerDependencies ?: {
35- [ key : string ] : string ;
36- }
37- dependencies ?: {
38- [ key : string ] : string ;
39- }
40- devDependencies ?: {
41- [ key : string ] : string ;
42- }
43- gitHead ?: string ;
17+ name : string ;
18+ version : string ;
19+ description : string ;
20+ author : string ;
21+ homepage ?: string ;
22+ repository ?:
23+ | {
24+ type ?: string ;
25+ url ?: string ;
26+ }
27+ | string ;
28+ license : string ;
29+ main : string ;
30+ module : string ;
31+ files : string [ ] ;
32+ publishConfig ?: {
33+ [ key : string ] : any ;
34+ } ;
35+ keywords : string [ ] ;
36+ peerDependencies ?: {
37+ [ key : string ] : string ;
38+ } ;
39+ dependencies ?: {
40+ [ key : string ] : string ;
41+ } ;
42+ devDependencies ?: {
43+ [ key : string ] : string ;
44+ } ;
45+ gitHead ?: string ;
4446}
4547
4648export interface GlobalState {
@@ -59,7 +61,7 @@ export type Params = {
5961 name ?: string ;
6062 filename ?: string ;
6163 '*' ?: string ;
62- }
64+ } ;
6365
6466export const global = createModel < RootModel > ( ) ( {
6567 state : {
@@ -78,8 +80,8 @@ export const global = createModel<RootModel>()({
7880 ...payload ,
7981 } ) ,
8082 } ,
81- effects : ( dispatch ) => {
82- const { global } = dispatch
83+ effects : ( dispatch ) => {
84+ const { global } = dispatch ;
8385 return {
8486 async setPkgname ( params : Params ) {
8587 const { name, org } = params || { } ;
@@ -106,7 +108,7 @@ export const global = createModel<RootModel>()({
106108 async getPackageJSON ( _ , state ) {
107109 const data : PackageJSON = await getFileContent ( `${ state . global . pkgname } /package.json` ) ;
108110 if ( data && typeof data === 'object' ) {
109- global . update ( { package : { ...data } , notFindPkg : false } ) ;
111+ global . update ( { package : { ...data } , notFindPkg : false } ) ;
110112 } else {
111113 global . update ( {
112114 package : undefined ,
@@ -118,15 +120,15 @@ export const global = createModel<RootModel>()({
118120 if ( ! filepath ) {
119121 dispatch . global . update ( { content : '' , extname : '' } ) ;
120122 return ;
121- } ;
122- const type = filepath . replace ( / .+ \. / , '' ) ;
123+ }
124+ const type = filepath . replace ( / .+ \. / , '' ) ;
123125 const data : PackageJSON = await getFileContent ( `${ state . global . pkgname } /${ filepath } ` ) ;
124126 if ( typeof data === 'string' || ! data ) {
125127 dispatch . global . update ( { content : data , extname : type } ) ;
126128 } else if ( data && / \. ( j s o n | m a p ) $ / . test ( filepath ) ) {
127129 dispatch . global . update ( { content : JSON . stringify ( data , null , 2 ) , extname : type } ) ;
128130 }
129131 } ,
130- }
131- }
132+ } ;
133+ } ,
132134} ) ;
0 commit comments