@any-listen/extension-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +151 -0
- package/dist/bin.js +17 -0
- package/dist/bin.js.map +1 -0
- package/dist/build-CUKFiHZ-.js +142 -0
- package/dist/build-CUKFiHZ-.js.map +1 -0
- package/dist/publish-BUpufhVY.js +40 -0
- package/dist/publish-BUpufhVY.js.map +1 -0
- package/dist/utils-BN85b34y.js +92 -0
- package/dist/utils-BN85b34y.js.map +1 -0
- package/eslint/eslint.config.js +123 -0
- package/package.json +81 -0
- package/src/build.ts +17 -0
- package/src/constants.ts +8 -0
- package/src/cpResources.ts +16 -0
- package/src/index.ts +24 -0
- package/src/mainifest.ts +27 -0
- package/src/pack.ts +80 -0
- package/src/publish.ts +43 -0
- package/src/state.ts +10 -0
- package/src/types/build.d.ts +24 -0
- package/src/types/extension_config.d.ts +125 -0
- package/src/utils.ts +78 -0
- package/src/vite.config.ts +52 -0
- package/tsconfigs/tsconfig.app.json +9 -0
- package/tsconfigs/tsconfig.base.json +15 -0
- package/tsconfigs/tsconfig.isolate.json +18 -0
- package/tsconfigs/tsconfig.node.json +9 -0
- package/types/app/api.d.ts +1127 -0
- package/types/app/global.d.ts +10 -0
- package/types/app/index.d.ts +2 -0
- package/types/build.d.ts +1 -0
- package/types/isolate.d.ts +11 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
type Grant = 'internet' | 'player' | 'music_list' | 'isolate_context'
|
|
2
|
+
type ResourceAction =
|
|
3
|
+
| 'tipSearch'
|
|
4
|
+
| 'hotSearch'
|
|
5
|
+
| 'musicSearch'
|
|
6
|
+
| 'musicPic'
|
|
7
|
+
| 'musicLyric'
|
|
8
|
+
| 'musicUrl'
|
|
9
|
+
| 'songlistSearch'
|
|
10
|
+
| 'songlist'
|
|
11
|
+
| 'leaderboard'
|
|
12
|
+
| 'albumSearch'
|
|
13
|
+
| 'album'
|
|
14
|
+
| 'singerSearch'
|
|
15
|
+
| 'singer'
|
|
16
|
+
| 'musicPicSearch'
|
|
17
|
+
| 'lyricSearch'
|
|
18
|
+
| 'lyricDetail'
|
|
19
|
+
|
|
20
|
+
interface FormBase {
|
|
21
|
+
field: string
|
|
22
|
+
name: string
|
|
23
|
+
description: string
|
|
24
|
+
}
|
|
25
|
+
interface FormInput extends FormBase {
|
|
26
|
+
type: 'input'
|
|
27
|
+
textarea?: boolean
|
|
28
|
+
default?: string
|
|
29
|
+
}
|
|
30
|
+
interface FormBoolean extends FormBase {
|
|
31
|
+
type: 'boolean'
|
|
32
|
+
default?: boolean
|
|
33
|
+
}
|
|
34
|
+
interface FormSelection extends FormBase {
|
|
35
|
+
type: 'selection'
|
|
36
|
+
default?: string
|
|
37
|
+
enum: string[]
|
|
38
|
+
enumName: string[]
|
|
39
|
+
}
|
|
40
|
+
interface FormConfigCheckbox extends FormBase {
|
|
41
|
+
type: 'configCheckbox'
|
|
42
|
+
default?: string
|
|
43
|
+
enumConfigFiled: string
|
|
44
|
+
enumFiled: string
|
|
45
|
+
enumNameFiled: string
|
|
46
|
+
enumDescriptionFiled?: string
|
|
47
|
+
removeable?: boolean
|
|
48
|
+
actionCommands?: string[]
|
|
49
|
+
actionCommandNames?: string[]
|
|
50
|
+
}
|
|
51
|
+
interface FormConfigCheckboxMultiple extends FormBase {
|
|
52
|
+
type: 'configCheckboxMultiple'
|
|
53
|
+
default?: string[]
|
|
54
|
+
enumConfigFiled: string
|
|
55
|
+
enumFiled: string
|
|
56
|
+
enumNameFiled: string
|
|
57
|
+
enumDescriptionFiled?: string
|
|
58
|
+
max?: number
|
|
59
|
+
removeable?: boolean
|
|
60
|
+
actionCommands?: string[]
|
|
61
|
+
actionCommandNames?: string[]
|
|
62
|
+
}
|
|
63
|
+
interface FormLazzyParseMeta {
|
|
64
|
+
type: 'lazzyParseMeta'
|
|
65
|
+
default?: boolean
|
|
66
|
+
}
|
|
67
|
+
type FormValue<T extends FormItems> = T & { value?: T['default'] }
|
|
68
|
+
type FormConfigValue<T extends FormConfigCheckbox | FormConfigCheckboxMultiple> = T & {
|
|
69
|
+
enum: ConfigEnum[]
|
|
70
|
+
value?: T['default']
|
|
71
|
+
}
|
|
72
|
+
interface ConfigEnum {
|
|
73
|
+
value: string
|
|
74
|
+
name: string
|
|
75
|
+
raw: unknown
|
|
76
|
+
description?: string
|
|
77
|
+
}
|
|
78
|
+
type FormValueItem =
|
|
79
|
+
| FormValue<FormInput>
|
|
80
|
+
| FormValue<FormBoolean>
|
|
81
|
+
| FormValue<FormSelection>
|
|
82
|
+
| FormConfigValue<FormConfigCheckbox>
|
|
83
|
+
| FormConfigValue<FormConfigCheckboxMultiple>
|
|
84
|
+
type FormItems = FormInput | FormBoolean | FormSelection | FormConfigCheckbox | FormConfigCheckboxMultiple
|
|
85
|
+
type ListProviderFormValueItem = FormValueItem | (FormLazzyParseMeta & { value?: boolean })
|
|
86
|
+
type ListProviderFormItems = FormItems | FormLazzyParseMeta
|
|
87
|
+
interface ListProvider {
|
|
88
|
+
id: string
|
|
89
|
+
name: string
|
|
90
|
+
description: string
|
|
91
|
+
fileSortable?: boolean
|
|
92
|
+
form: ListProviderFormItems[]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
interface Command {
|
|
96
|
+
command: string
|
|
97
|
+
name: string
|
|
98
|
+
description?: string
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface Manifest {
|
|
102
|
+
id: string
|
|
103
|
+
name: string
|
|
104
|
+
description?: string
|
|
105
|
+
icon?: string
|
|
106
|
+
version: string
|
|
107
|
+
target_engine?: string
|
|
108
|
+
author?: string
|
|
109
|
+
homepage?: string
|
|
110
|
+
license?: string
|
|
111
|
+
categories?: string[]
|
|
112
|
+
tags?: string[]
|
|
113
|
+
grant?: Grant[]
|
|
114
|
+
contributes?: {
|
|
115
|
+
resource?: Array<{
|
|
116
|
+
id: string
|
|
117
|
+
name: string
|
|
118
|
+
resource: ResourceAction[]
|
|
119
|
+
}>
|
|
120
|
+
listProviders?: ListProvider[]
|
|
121
|
+
settings?: FormItems[]
|
|
122
|
+
commands?: Command[]
|
|
123
|
+
}
|
|
124
|
+
download_url_template?: string
|
|
125
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { build as viteBuild, type UserConfig } from 'vite'
|
|
5
|
+
|
|
6
|
+
import { EXTENSION } from './constants'
|
|
7
|
+
import { state } from './state'
|
|
8
|
+
import type { ExtensionConfig } from './types/build'
|
|
9
|
+
|
|
10
|
+
export const ROOT_DIR = path.join(import.meta.dirname.split('node_modules')[0])
|
|
11
|
+
|
|
12
|
+
const buildPath = (subPath: string) => {
|
|
13
|
+
if (path.isAbsolute(subPath)) return subPath
|
|
14
|
+
return path.join(ROOT_DIR, subPath)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getConfig = async () => {
|
|
18
|
+
const configPath = path.join(ROOT_DIR, 'config.ts')
|
|
19
|
+
await fs.access(configPath, fs.constants.F_OK)
|
|
20
|
+
const config = ((await import(`file://${configPath}`)) as { default: ExtensionConfig }).default
|
|
21
|
+
|
|
22
|
+
state.srcDir = buildPath(config.buildConfig?.srcDir || 'src')
|
|
23
|
+
state.distDir = buildPath(config.buildConfig?.distDir || 'dist')
|
|
24
|
+
state.outputDir = buildPath(config.buildConfig?.outputDir || 'build')
|
|
25
|
+
state.i18nDir = buildPath(config.buildConfig?.i18nDir || 'i18n')
|
|
26
|
+
state.resourcesDir = buildPath(config.buildConfig?.resourcesDir || 'resources')
|
|
27
|
+
state.isIsolateMode = config.buildConfig?.isIsolateMode || false
|
|
28
|
+
if (state.isIsolateMode) {
|
|
29
|
+
state.mainEntry = buildPath(config.buildConfig?.mainEntry || path.join(state.srcDir, 'main/index.ts'))
|
|
30
|
+
state.isolatePreloadEntry = buildPath(
|
|
31
|
+
config.buildConfig?.isolatePreloadEntry || path.join(state.srcDir, 'isolate-preload/index.ts')
|
|
32
|
+
)
|
|
33
|
+
} else {
|
|
34
|
+
state.mainEntry = buildPath(config.buildConfig?.mainEntry || path.join(state.srcDir, 'index.ts'))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return config
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const loadEnvFile = async () => {
|
|
41
|
+
const envPath = path.join(ROOT_DIR, '.env')
|
|
42
|
+
let envContent: string
|
|
43
|
+
try {
|
|
44
|
+
await fs.access(envPath, fs.constants.F_OK)
|
|
45
|
+
envContent = (await fs.readFile(envPath, 'utf-8')).trim()
|
|
46
|
+
} catch {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
if (!envContent) return
|
|
50
|
+
const lines = envContent.split('\n')
|
|
51
|
+
for (const line of lines) {
|
|
52
|
+
let [key, ...rest] = line.split('=')
|
|
53
|
+
key = key.trim()
|
|
54
|
+
if (key.startsWith('#') || key === '') continue
|
|
55
|
+
process.env[key] = rest.join('=').trim()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const buildPackageName = (config: ExtensionConfig) => {
|
|
60
|
+
return `${config.id}_v${config.version}.${EXTENSION.pkgExtName}`
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* build code
|
|
65
|
+
*/
|
|
66
|
+
export const build = async (config: UserConfig) => {
|
|
67
|
+
if (config.build) config.build.watch = null
|
|
68
|
+
return viteBuild({ ...config, configFile: false })
|
|
69
|
+
.then(() => {
|
|
70
|
+
// output
|
|
71
|
+
// console.log(output)
|
|
72
|
+
return true
|
|
73
|
+
})
|
|
74
|
+
.catch((error) => {
|
|
75
|
+
console.log(error)
|
|
76
|
+
return false
|
|
77
|
+
})
|
|
78
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
|
|
3
|
+
import { EXTENSION } from './constants'
|
|
4
|
+
import { state } from './state'
|
|
5
|
+
|
|
6
|
+
const isProd = process.env.NODE_ENV == 'production'
|
|
7
|
+
|
|
8
|
+
const createBuildConfig = (name: string, filePath: string) => {
|
|
9
|
+
return defineConfig({
|
|
10
|
+
base: './',
|
|
11
|
+
mode: process.env.NODE_ENV,
|
|
12
|
+
publicDir: false,
|
|
13
|
+
resolve: {
|
|
14
|
+
alias: {
|
|
15
|
+
'@': state.srcDir,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
build: {
|
|
19
|
+
target: 'esnext',
|
|
20
|
+
emptyOutDir: true,
|
|
21
|
+
minify: false,
|
|
22
|
+
watch: isProd
|
|
23
|
+
? null
|
|
24
|
+
: {
|
|
25
|
+
buildDelay: 500,
|
|
26
|
+
},
|
|
27
|
+
outDir: state.distDir,
|
|
28
|
+
rolldownOptions: {
|
|
29
|
+
external: ['any-listen'],
|
|
30
|
+
input: {
|
|
31
|
+
[name]: filePath,
|
|
32
|
+
},
|
|
33
|
+
output: {
|
|
34
|
+
entryFileNames: '[name]',
|
|
35
|
+
format: 'iife',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default (isIsolateMode?: boolean) => {
|
|
43
|
+
const inputs = isIsolateMode
|
|
44
|
+
? {
|
|
45
|
+
[EXTENSION.entryFileName]: state.mainEntry,
|
|
46
|
+
'resources/isolate-preload.js': state.isolatePreloadEntry,
|
|
47
|
+
}
|
|
48
|
+
: {
|
|
49
|
+
[EXTENSION.entryFileName]: state.mainEntry,
|
|
50
|
+
}
|
|
51
|
+
return Object.entries(inputs).map(([name, filePath]) => createBuildConfig(name, filePath))
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"strict": true,
|
|
5
|
+
"skipLibCheck": false,
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"isolatedModules": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"allowSyntheticDefaultImports": true,
|
|
12
|
+
"useDefineForClassFields": true,
|
|
13
|
+
"checkJs": true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"lib": ["ESNext"],
|
|
7
|
+
"outDir": "./dist/isolate"
|
|
8
|
+
// "typeRoots": ["./src/types", "./src/isolate-preload/types"]
|
|
9
|
+
}
|
|
10
|
+
// "include": [
|
|
11
|
+
// "./src/isolate-preload/**/*.d.ts",
|
|
12
|
+
// "./src/isolate-preload/**/*.ts",
|
|
13
|
+
// "./src/isolate-preload/**/*.js",
|
|
14
|
+
// "./src/isolate-preload/**/*.mjs",
|
|
15
|
+
// "./src/types/**/*.d.ts"
|
|
16
|
+
// ],
|
|
17
|
+
// "exclude": ["node_modules", "dist"]
|
|
18
|
+
}
|