1
1
import { Command } from "@tauri-apps/api/shell"
2
- import { readTextFile , writeTextFile , removeFile , readDir } from "@tauri-apps/api/fs"
2
+ import { readTextFile , writeTextFile , removeFile , createDir , readDir } from "@tauri-apps/api/fs"
3
3
import { ReactiveController , ReactiveControllerHost } from "lit"
4
4
import { property } from "lit/decorators/property.js"
5
5
import type { IPackageJson } from "package-json-type"
@@ -38,13 +38,17 @@ export class Packager {
38
38
}
39
39
40
40
async initialize ( inAppDir = true ) {
41
- this . appDir = ( await appDir ( ) ) . slice ( 0 , - 1 )
41
+ this . appDir = await appDir ( )
42
+ try {
43
+ await readDir ( this . appDir )
44
+ }
45
+ catch ( err ) {
46
+ await createDir ( this . appDir )
47
+ }
42
48
const list = await this . ls ( ) as any
43
49
if ( ! list ?. name ) {
44
- await this . npm ( "init" , [ "--yes" ] , false , true )
45
- // const packageJsonPath = await join(this.appDir, "package.json")
46
- // await (new Command(`"${DEFAULT_PACKAGE_JSON}" > "${packageJsonPath}"`)).execute()
47
- return this . install ( Packager . corePackages )
50
+ await this . npm ( "init" , [ "--yes" ] , false , inAppDir )
51
+ return this . install ( Packager . corePackages , true , false )
48
52
}
49
53
50
54
}
@@ -194,6 +198,7 @@ export class PackagerController extends Packager implements ReactiveController {
194
198
}
195
199
196
200
async fetchInstalledPackages ( loading = true , importPackages = false ) {
201
+ console . trace ( "fetchInstalledPackages" )
197
202
this . loading = loading
198
203
await this . initialized
199
204
this . host . requestUpdate ( )
@@ -219,6 +224,7 @@ export class PackagerController extends Packager implements ReactiveController {
219
224
}
220
225
221
226
async fetchAllPackages ( from = 0 , append = true , loading = true ) {
227
+ console . trace ( "fetchAllPackages" )
222
228
this . loading = loading
223
229
await this . initialized
224
230
this . host . requestUpdate ( )
@@ -229,9 +235,9 @@ export class PackagerController extends Packager implements ReactiveController {
229
235
this . host . requestUpdate ( )
230
236
}
231
237
232
- async install ( args : string [ ] = [ ] , importPackages = true ) {
238
+ async install ( args : string [ ] = [ ] , importPackages = true , fetchInstalled = true ) {
233
239
const result = await super . install ( args )
234
- await this . fetchInstalledPackages ( )
240
+ fetchInstalled ? await this . fetchInstalledPackages ( ) : null
235
241
importPackages ? await super . writeBundle ( this . installedPackages ) : null
236
242
importPackages ? await super . importBundle ( this . installedPackages ) : null
237
243
this . host . requestUpdate ( )
0 commit comments