@mingxy/ocosay 1.1.18 → 1.1.20
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/dist/package.json +1 -1
- package/dist/plugin.js +79 -52
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/plugin.js
CHANGED
|
@@ -10062,6 +10062,14 @@ async function ensureNaudiodonCompiled() {
|
|
|
10062
10062
|
}
|
|
10063
10063
|
}
|
|
10064
10064
|
}
|
|
10065
|
+
function isModuleInstalled(moduleName) {
|
|
10066
|
+
try {
|
|
10067
|
+
require2.resolve(moduleName);
|
|
10068
|
+
return true;
|
|
10069
|
+
} catch {
|
|
10070
|
+
return false;
|
|
10071
|
+
}
|
|
10072
|
+
}
|
|
10065
10073
|
async function verifyModuleLoad(dep) {
|
|
10066
10074
|
try {
|
|
10067
10075
|
require2(dep);
|
|
@@ -10072,90 +10080,109 @@ async function verifyModuleLoad(dep) {
|
|
|
10072
10080
|
return false;
|
|
10073
10081
|
}
|
|
10074
10082
|
}
|
|
10075
|
-
async function
|
|
10083
|
+
async function ensureSpeakerCompiled(maxRetries = 5) {
|
|
10084
|
+
const dep = "speaker";
|
|
10085
|
+
const basePath = dirname2(require2.resolve("./package.json"));
|
|
10086
|
+
if (isModuleInstalled(dep)) {
|
|
10087
|
+
logger8.info("speaker already installed");
|
|
10088
|
+
if (await verifyModuleLoad(dep)) {
|
|
10089
|
+
return;
|
|
10090
|
+
}
|
|
10091
|
+
logger8.info("speaker installed but not loadable, rebuilding");
|
|
10092
|
+
notificationService.info("\u6B63\u5728\u7F16\u8BD1 speaker...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
|
|
10093
|
+
try {
|
|
10094
|
+
execSync2("npm rebuild speaker", {
|
|
10095
|
+
cwd: basePath,
|
|
10096
|
+
stdio: "inherit"
|
|
10097
|
+
});
|
|
10098
|
+
logger8.info("speaker rebuilt");
|
|
10099
|
+
} catch (err) {
|
|
10100
|
+
logger8.warn({ err }, "speaker rebuild failed");
|
|
10101
|
+
}
|
|
10102
|
+
if (await verifyModuleLoad(dep)) {
|
|
10103
|
+
notificationService.success("speaker \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
|
|
10104
|
+
return;
|
|
10105
|
+
}
|
|
10106
|
+
} else {
|
|
10107
|
+
logger8.info("speaker not found, installing");
|
|
10108
|
+
notificationService.info("\u6B63\u5728\u5B89\u88C5 speaker...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
|
|
10109
|
+
try {
|
|
10110
|
+
execSync2("npm install speaker", {
|
|
10111
|
+
cwd: basePath,
|
|
10112
|
+
stdio: "inherit"
|
|
10113
|
+
});
|
|
10114
|
+
logger8.info("speaker installed");
|
|
10115
|
+
} catch (err) {
|
|
10116
|
+
logger8.warn({ err }, "speaker install failed");
|
|
10117
|
+
}
|
|
10118
|
+
}
|
|
10076
10119
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
10077
10120
|
if (await verifyModuleLoad(dep)) {
|
|
10078
|
-
|
|
10121
|
+
notificationService.success("speaker \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
|
|
10122
|
+
return;
|
|
10079
10123
|
}
|
|
10080
|
-
logger8.info({ attempt, dep }, "
|
|
10081
|
-
notificationService.info(`\u6B63\u5728\u7F16\u8BD1
|
|
10124
|
+
logger8.info({ attempt, dep }, "speaker not loadable, trying rebuild");
|
|
10125
|
+
notificationService.info(`\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 speaker (${attempt + 1}/${maxRetries})...`, "Ocosay", 3e3);
|
|
10082
10126
|
try {
|
|
10083
|
-
execSync2("npm rebuild", {
|
|
10084
|
-
cwd:
|
|
10127
|
+
execSync2("npm rebuild speaker", {
|
|
10128
|
+
cwd: basePath,
|
|
10085
10129
|
stdio: "inherit"
|
|
10086
10130
|
});
|
|
10087
|
-
logger8.info(
|
|
10131
|
+
logger8.info("speaker rebuilt");
|
|
10088
10132
|
} catch (err) {
|
|
10089
|
-
logger8.warn({ err },
|
|
10133
|
+
logger8.warn({ err }, "speaker rebuild failed");
|
|
10090
10134
|
}
|
|
10091
10135
|
if (await verifyModuleLoad(dep)) {
|
|
10092
|
-
|
|
10136
|
+
notificationService.success("speaker \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
|
|
10137
|
+
return;
|
|
10138
|
+
}
|
|
10139
|
+
if (attempt < maxRetries - 1) {
|
|
10140
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
10093
10141
|
}
|
|
10094
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
10095
10142
|
}
|
|
10096
|
-
|
|
10143
|
+
logger8.error({ dep }, "speaker could not be compiled");
|
|
10144
|
+
notificationService.error("speaker \u7F16\u8BD1\u5931\u8D25", "\u8BF7\u624B\u52A8\u8FD0\u884C: npm install speaker && npm rebuild speaker", 8e3);
|
|
10097
10145
|
}
|
|
10098
|
-
async function
|
|
10099
|
-
const
|
|
10100
|
-
const missingDeps = [];
|
|
10146
|
+
async function ensurePlaySoundInstalled() {
|
|
10147
|
+
const dep = "play-sound";
|
|
10101
10148
|
const basePath = dirname2(require2.resolve("./package.json"));
|
|
10102
|
-
|
|
10149
|
+
if (isModuleInstalled(dep)) {
|
|
10150
|
+
logger8.info("play-sound already installed");
|
|
10103
10151
|
if (await verifyModuleLoad(dep)) {
|
|
10104
|
-
|
|
10152
|
+
return;
|
|
10105
10153
|
}
|
|
10106
|
-
missingDeps.push(dep);
|
|
10107
10154
|
}
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
}
|
|
10111
|
-
notificationService.info(
|
|
10112
|
-
`\u6B63\u5728\u5B89\u88C5\u53EF\u9009\u4F9D\u8D56: ${missingDeps.join(", ")}...`,
|
|
10113
|
-
"Ocosay \u97F3\u9891\u540E\u7AEF",
|
|
10114
|
-
5e3
|
|
10115
|
-
);
|
|
10155
|
+
logger8.info("play-sound not found, installing");
|
|
10156
|
+
notificationService.info("\u6B63\u5728\u5B89\u88C5 play-sound...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
|
|
10116
10157
|
try {
|
|
10117
|
-
|
|
10118
|
-
logger8.info({ deps: depsStr }, "installing optional dependencies");
|
|
10119
|
-
execSync2(`npm install ${depsStr}`, {
|
|
10158
|
+
execSync2("npm install play-sound", {
|
|
10120
10159
|
cwd: basePath,
|
|
10121
10160
|
stdio: "inherit"
|
|
10122
10161
|
});
|
|
10123
|
-
logger8.info("
|
|
10162
|
+
logger8.info("play-sound installed");
|
|
10124
10163
|
} catch (err) {
|
|
10125
|
-
logger8.warn({ err }, "
|
|
10164
|
+
logger8.warn({ err }, "play-sound install failed");
|
|
10126
10165
|
notificationService.warning(
|
|
10127
|
-
"\
|
|
10128
|
-
|
|
10166
|
+
"play-sound \u5B89\u88C5\u5931\u8D25",
|
|
10167
|
+
"\u8BF7\u624B\u52A8\u8FD0\u884C: npm install play-sound",
|
|
10129
10168
|
8e3
|
|
10130
10169
|
);
|
|
10131
10170
|
return;
|
|
10132
10171
|
}
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
const depPath = dirname2(require2.resolve(dep, { paths: [basePath] }));
|
|
10136
|
-
if (await verifyModuleLoad(dep)) {
|
|
10137
|
-
continue;
|
|
10138
|
-
}
|
|
10139
|
-
notificationService.warning(`${dep} \u52A0\u8F7D\u5931\u8D25\uFF0C\u6B63\u5728\u5C1D\u8BD5\u7F16\u8BD1...`, "Ocosay", 5e3);
|
|
10140
|
-
const fixed = await fixOptionalDep(dep, depPath);
|
|
10141
|
-
if (!fixed) {
|
|
10142
|
-
allLoaded = false;
|
|
10143
|
-
}
|
|
10144
|
-
}
|
|
10145
|
-
if (allLoaded) {
|
|
10146
|
-
notificationService.success(
|
|
10147
|
-
"\u53EF\u9009\u4F9D\u8D56\u5B89\u88C5\u6210\u529F",
|
|
10148
|
-
"play-sound & speaker \u5DF2\u5C31\u7EEA",
|
|
10149
|
-
5e3
|
|
10150
|
-
);
|
|
10172
|
+
if (await verifyModuleLoad(dep)) {
|
|
10173
|
+
notificationService.success("play-sound \u5B89\u88C5\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
|
|
10151
10174
|
} else {
|
|
10152
10175
|
notificationService.warning(
|
|
10153
|
-
"\
|
|
10154
|
-
|
|
10176
|
+
"play-sound \u5B89\u88C5\u5931\u8D25",
|
|
10177
|
+
"\u8BF7\u624B\u52A8\u8FD0\u884C: npm install play-sound",
|
|
10155
10178
|
8e3
|
|
10156
10179
|
);
|
|
10157
10180
|
}
|
|
10158
10181
|
}
|
|
10182
|
+
async function ensureOptionalDepsInstalled() {
|
|
10183
|
+
await ensureSpeakerCompiled();
|
|
10184
|
+
await ensurePlaySoundInstalled();
|
|
10185
|
+
}
|
|
10159
10186
|
function execCmd2(cmd) {
|
|
10160
10187
|
try {
|
|
10161
10188
|
const output = execSync2(cmd, { stdio: "pipe", encoding: "utf8" });
|