-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WARN: include sql change 😄 Follow unpkg router 😄 Auto sync files after package version add closes #452
- Loading branch information
Showing
31 changed files
with
1,470 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Dist } from './Dist'; | ||
import { Entity, EntityData } from './Entity'; | ||
import { EasyData, EntityUtil } from '../util/EntityUtil'; | ||
|
||
interface PackageVersionFileData extends EntityData { | ||
packageVersionFileId: string; | ||
packageVersionId: string; | ||
dist: Dist; | ||
directory: string; | ||
name: string; | ||
contentType: string; | ||
mtime: Date; | ||
} | ||
|
||
export class PackageVersionFile extends Entity { | ||
packageVersionFileId: string; | ||
packageVersionId: string; | ||
dist: Dist; | ||
directory: string; | ||
name: string; | ||
contentType: string; | ||
mtime: Date; | ||
|
||
constructor(data: PackageVersionFileData) { | ||
super(data); | ||
this.packageVersionFileId = data.packageVersionFileId; | ||
this.packageVersionId = data.packageVersionId; | ||
this.dist = data.dist; | ||
this.directory = data.directory; | ||
this.name = data.name; | ||
this.contentType = data.contentType; | ||
this.mtime = data.mtime; | ||
} | ||
|
||
get path() { | ||
return this.directory === '/' ? `/${this.name}` : `${this.directory}/${this.name}`; | ||
} | ||
|
||
static create(data: EasyData<PackageVersionFileData, 'packageVersionFileId'>): PackageVersionFile { | ||
const newData = EntityUtil.defaultData(data, 'packageVersionFileId'); | ||
return new PackageVersionFile(newData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Event, Inject } from '@eggjs/tegg'; | ||
import { | ||
EggAppConfig, | ||
} from 'egg'; | ||
import { PACKAGE_VERSION_ADDED } from './index'; | ||
import { getScopeAndName } from '../../common/PackageUtil'; | ||
import { PackageManagerService } from '../service/PackageManagerService'; | ||
import { PackageVersionFileService } from '../service/PackageVersionFileService'; | ||
|
||
class SyncPackageVersionFileEvent { | ||
@Inject() | ||
protected readonly config: EggAppConfig; | ||
@Inject() | ||
private readonly packageManagerService: PackageManagerService; | ||
@Inject() | ||
private readonly packageVersionFileService: PackageVersionFileService; | ||
|
||
protected async syncPackageVersionFile(fullname: string, version: string) { | ||
if (!this.config.cnpmcore.enableUnpkg) return; | ||
const [ scope, name ] = getScopeAndName(fullname); | ||
const { packageVersion } = await this.packageManagerService.showPackageVersionByVersionOrTag( | ||
scope, name, version); | ||
if (!packageVersion) return; | ||
await this.packageVersionFileService.syncPackageVersionFiles(packageVersion); | ||
} | ||
} | ||
|
||
@Event(PACKAGE_VERSION_ADDED) | ||
export class PackageVersionAdded extends SyncPackageVersionFileEvent { | ||
async handle(fullname: string, version: string) { | ||
await this.syncPackageVersionFile(fullname, version); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.