@@ -3,7 +3,6 @@ import fsOperation from "fileSystem";
33import JSZip from "jszip" ;
44import Url from "utils/Url" ;
55import constants from "./constants" ;
6- import InstallState from "./installState" ;
76import loadPlugin from "./loadPlugin" ;
87
98/**
@@ -71,8 +70,6 @@ export default async function installPlugin(id, name, purchaseToken) {
7170 pluginDir = Url . join ( PLUGIN_DIR , id ) ;
7271 }
7372
74- const state = await InstallState . new ( id ) ;
75-
7673 if ( ! ( await fsOperation ( pluginDir ) . exists ( ) ) ) {
7774 await fsOperation ( PLUGIN_DIR ) . createDirectory ( id ) ;
7875 }
@@ -84,7 +81,7 @@ export default async function installPlugin(id, name, purchaseToken) {
8481 }
8582
8683 const fileUrl = Url . join ( pluginDir , correctFile ) ;
87- if ( ! state . exists ( correctFile ) ) {
84+ if ( ! ( await fsOperation ( fileUrl ) . exists ( ) ) ) {
8885 await createFileRecursive ( pluginDir , correctFile ) ;
8986 }
9087
@@ -96,18 +93,11 @@ export default async function installPlugin(id, name, purchaseToken) {
9693 data = JSON . stringify ( pluginJson ) ;
9794 }
9895
99- if ( ! ( await state . isUpdated ( correctFile , data ) ) ) {
100- return ;
101- }
102-
10396 await fsOperation ( fileUrl ) . writeFile ( data ) ;
104- return ;
10597 } ) ;
10698
10799 await Promise . all ( promises ) ;
108100 await loadPlugin ( id , true ) ;
109- await state . save ( ) ;
110- deleteRedundantFiles ( pluginDir , state ) ;
111101 }
112102 } catch ( err ) {
113103 try {
@@ -149,34 +139,3 @@ async function createFileRecursive(parent, dir) {
149139 await createFileRecursive ( newParent , dir ) ;
150140 }
151141}
152- /**
153- *
154- * @param {string } dir
155- * @param {Array<string> } files
156- */
157- async function listFileRecursive ( dir , files ) {
158- for ( const child of await fsOperation ( dir ) . lsDir ( ) ) {
159- const fileUrl = Url . join ( dir , child . name ) ;
160- if ( child . isDirectory ) {
161- await listFileRecursive ( fileUrl , files ) ;
162- } else {
163- files . push ( fileUrl ) ;
164- }
165- }
166- }
167-
168- /**
169- *
170- * @param {Record<string, boolean> } files
171- */
172- async function deleteRedundantFiles ( pluginDir , state ) {
173- /** @type string[] */
174- let files = [ ] ;
175- await listFileRecursive ( pluginDir , files ) ;
176-
177- for ( const file of files ) {
178- if ( ! state . exists ( file . replace ( `${ pluginDir } /` , "" ) ) ) {
179- fsOperation ( file ) . delete ( ) ;
180- }
181- }
182- }
0 commit comments