@lynx-js/qrcode-rsbuild-plugin 0.3.3 → 0.3.5
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/CHANGELOG.md +12 -0
- package/README.md +2 -2
- package/dist/113.js +20 -0
- package/dist/517.js +1456 -0
- package/dist/640.js +939 -0
- package/dist/index.js +264 -0
- package/dist/shortcuts.js +221 -0
- package/dist/showQRCode.d.ts +1 -0
- package/package.json +22 -17
- package/lib/generateDevUrls.js +0 -28
- package/lib/index.js +0 -71
- package/lib/shortcuts.js +0 -102
- package/lib/showQRCode.d.ts +0 -1
- package/lib/showQRCode.js +0 -17
- /package/{lib → dist}/generateDevUrls.d.ts +0 -0
- /package/{lib → dist}/index.d.ts +0 -0
- /package/{lib → dist}/shortcuts.d.ts +0 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__ from "node:process";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_readline_91c31510__ from "node:readline";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_tty_c64aab7e__ from "node:tty";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__ from "node:util";
|
|
5
|
+
var __webpack_modules__ = {
|
|
6
|
+
"node:process": function(module) {
|
|
7
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__;
|
|
8
|
+
},
|
|
9
|
+
"node:readline": function(module) {
|
|
10
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_readline_91c31510__;
|
|
11
|
+
},
|
|
12
|
+
"node:tty": function(module) {
|
|
13
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_tty_c64aab7e__;
|
|
14
|
+
},
|
|
15
|
+
"node:util": function(module) {
|
|
16
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var __webpack_module_cache__ = {};
|
|
20
|
+
function __webpack_require__(moduleId) {
|
|
21
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
22
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
23
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
24
|
+
exports: {}
|
|
25
|
+
};
|
|
26
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
27
|
+
return module.exports;
|
|
28
|
+
}
|
|
29
|
+
__webpack_require__.m = __webpack_modules__;
|
|
30
|
+
(()=>{
|
|
31
|
+
__webpack_require__.n = (module)=>{
|
|
32
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
33
|
+
__webpack_require__.d(getter, {
|
|
34
|
+
a: getter
|
|
35
|
+
});
|
|
36
|
+
return getter;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
(()=>{
|
|
40
|
+
__webpack_require__.d = (exports, definition)=>{
|
|
41
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: definition[key]
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
(()=>{
|
|
48
|
+
__webpack_require__.f = {};
|
|
49
|
+
__webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>{
|
|
50
|
+
__webpack_require__.f[key](chunkId, promises);
|
|
51
|
+
return promises;
|
|
52
|
+
}, []));
|
|
53
|
+
})();
|
|
54
|
+
(()=>{
|
|
55
|
+
__webpack_require__.u = (chunkId)=>"" + chunkId + ".js";
|
|
56
|
+
})();
|
|
57
|
+
(()=>{
|
|
58
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
59
|
+
})();
|
|
60
|
+
(()=>{
|
|
61
|
+
__webpack_require__.r = (exports)=>{
|
|
62
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
|
|
63
|
+
value: 'Module'
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(exports, '__esModule', {
|
|
66
|
+
value: true
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
})();
|
|
70
|
+
(()=>{
|
|
71
|
+
var installedChunks = {
|
|
72
|
+
980: 0
|
|
73
|
+
};
|
|
74
|
+
var installChunk = (data)=>{
|
|
75
|
+
var __webpack_ids__ = data.__webpack_ids__;
|
|
76
|
+
var __webpack_modules__ = data.__webpack_modules__;
|
|
77
|
+
var __webpack_runtime__ = data.__webpack_runtime__;
|
|
78
|
+
var moduleId, chunkId, i = 0;
|
|
79
|
+
for(moduleId in __webpack_modules__)if (__webpack_require__.o(__webpack_modules__, moduleId)) __webpack_require__.m[moduleId] = __webpack_modules__[moduleId];
|
|
80
|
+
if (__webpack_runtime__) __webpack_runtime__(__webpack_require__);
|
|
81
|
+
for(; i < __webpack_ids__.length; i++){
|
|
82
|
+
chunkId = __webpack_ids__[i];
|
|
83
|
+
if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
|
|
84
|
+
installedChunks[__webpack_ids__[i]] = 0;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
__webpack_require__.f.j = function(chunkId, promises) {
|
|
88
|
+
var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
|
|
89
|
+
if (0 !== installedChunkData) if (installedChunkData) promises.push(installedChunkData[1]);
|
|
90
|
+
else {
|
|
91
|
+
var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, (e)=>{
|
|
92
|
+
if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0;
|
|
93
|
+
throw e;
|
|
94
|
+
});
|
|
95
|
+
var promise = Promise.race([
|
|
96
|
+
promise,
|
|
97
|
+
new Promise((resolve)=>{
|
|
98
|
+
installedChunkData = installedChunks[chunkId] = [
|
|
99
|
+
resolve
|
|
100
|
+
];
|
|
101
|
+
})
|
|
102
|
+
]);
|
|
103
|
+
promises.push(installedChunkData[1] = promise);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
})();
|
|
107
|
+
function generateDevUrls(api, entry, schemaFn, port) {
|
|
108
|
+
const { dev: { assetPrefix } } = api.getNormalizedConfig();
|
|
109
|
+
const { config } = api.useExposed(Symbol.for('rspeedy.api'));
|
|
110
|
+
if ('string' != typeof assetPrefix) {
|
|
111
|
+
const errorMsg = 'dev.assetPrefix is not string, skip printing QRCode';
|
|
112
|
+
throw new Error(errorMsg);
|
|
113
|
+
}
|
|
114
|
+
const defaultFilename = '[name].[platform].bundle';
|
|
115
|
+
const { filename } = config.output ?? {};
|
|
116
|
+
let name;
|
|
117
|
+
name = filename ? 'object' == typeof filename ? filename.bundle ?? filename.template ?? defaultFilename : filename : defaultFilename;
|
|
118
|
+
const customSchema = schemaFn(new URL(name.replace('[name]', entry).replace('[platform]', 'lynx'), assetPrefix.replaceAll('<port>', String(port))).toString());
|
|
119
|
+
return 'string' == typeof customSchema ? {
|
|
120
|
+
default: customSchema
|
|
121
|
+
} : customSchema;
|
|
122
|
+
}
|
|
123
|
+
const gExistingShortcuts = new WeakSet();
|
|
124
|
+
async function registerConsoleShortcuts(options) {
|
|
125
|
+
const [{ default: showQRCode }] = await Promise.all([
|
|
126
|
+
Promise.all([
|
|
127
|
+
__webpack_require__.e("517"),
|
|
128
|
+
__webpack_require__.e("640"),
|
|
129
|
+
__webpack_require__.e("113")
|
|
130
|
+
]).then(__webpack_require__.bind(__webpack_require__, "./src/showQRCode.ts"))
|
|
131
|
+
]);
|
|
132
|
+
const currentEntry = options.entries[0];
|
|
133
|
+
const devUrls = generateDevUrls(options.api, currentEntry, options.schema, options.port);
|
|
134
|
+
const value = Object.values(devUrls)[0];
|
|
135
|
+
await options.onPrint?.(value);
|
|
136
|
+
showQRCode(value);
|
|
137
|
+
gExistingShortcuts.add(options);
|
|
138
|
+
loop(options, value, devUrls);
|
|
139
|
+
function off() {
|
|
140
|
+
gExistingShortcuts.delete(options);
|
|
141
|
+
}
|
|
142
|
+
return off;
|
|
143
|
+
}
|
|
144
|
+
async function loop(options, value, devUrls) {
|
|
145
|
+
const [{ select, selectKey, isCancel, cancel }, { default: showQRCode }] = await Promise.all([
|
|
146
|
+
__webpack_require__.e("517").then(__webpack_require__.bind(__webpack_require__, "../../../node_modules/.pnpm/@clack+prompts@0.10.0/node_modules/@clack/prompts/dist/index.mjs")),
|
|
147
|
+
Promise.all([
|
|
148
|
+
__webpack_require__.e("517"),
|
|
149
|
+
__webpack_require__.e("640"),
|
|
150
|
+
__webpack_require__.e("113")
|
|
151
|
+
]).then(__webpack_require__.bind(__webpack_require__, "./src/showQRCode.ts"))
|
|
152
|
+
]);
|
|
153
|
+
let currentEntry = options.entries[0];
|
|
154
|
+
let currentSchema = Object.keys(devUrls)[0];
|
|
155
|
+
while(!isCancel(value)){
|
|
156
|
+
const name = await selectKey({
|
|
157
|
+
message: 'Usage',
|
|
158
|
+
options: [
|
|
159
|
+
{
|
|
160
|
+
value: 'r',
|
|
161
|
+
label: 'Switch entries'
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
value: 'a',
|
|
165
|
+
label: 'Switch schema'
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
value: 'h',
|
|
169
|
+
label: 'Help'
|
|
170
|
+
},
|
|
171
|
+
...Object.values(options.customShortcuts ?? {}),
|
|
172
|
+
{
|
|
173
|
+
value: 'q',
|
|
174
|
+
label: 'Quit'
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
initialValue: 'q'
|
|
178
|
+
});
|
|
179
|
+
if (isCancel(name) || 'q' === name || !gExistingShortcuts.has(options)) break;
|
|
180
|
+
if ('r' === name) {
|
|
181
|
+
const selection = await select({
|
|
182
|
+
message: 'Select entry',
|
|
183
|
+
options: options.entries.map((entry)=>({
|
|
184
|
+
value: entry,
|
|
185
|
+
label: entry,
|
|
186
|
+
hint: generateDevUrls(options.api, entry, options.schema, options.port)[currentSchema]
|
|
187
|
+
})),
|
|
188
|
+
initialValue: currentEntry
|
|
189
|
+
});
|
|
190
|
+
if (isCancel(selection)) break;
|
|
191
|
+
currentEntry = selection;
|
|
192
|
+
value = getCurrentUrl();
|
|
193
|
+
} else if ('a' === name) {
|
|
194
|
+
const devUrls = generateDevUrls(options.api, currentEntry, options.schema, options.port);
|
|
195
|
+
const selection = await select({
|
|
196
|
+
message: 'Select schema',
|
|
197
|
+
options: Object.entries(devUrls).map(([name, url])=>({
|
|
198
|
+
value: name,
|
|
199
|
+
label: name,
|
|
200
|
+
hint: url
|
|
201
|
+
})),
|
|
202
|
+
initialValue: currentSchema
|
|
203
|
+
});
|
|
204
|
+
if (isCancel(selection)) break;
|
|
205
|
+
currentSchema = selection;
|
|
206
|
+
value = getCurrentUrl();
|
|
207
|
+
} else if (options.customShortcuts?.[name]) await options.customShortcuts[name].action?.();
|
|
208
|
+
await options.onPrint?.(value);
|
|
209
|
+
showQRCode(value);
|
|
210
|
+
}
|
|
211
|
+
if (gExistingShortcuts.has(options)) await exit(1);
|
|
212
|
+
function getCurrentUrl() {
|
|
213
|
+
return generateDevUrls(options.api, currentEntry, options.schema, options.port)[currentSchema];
|
|
214
|
+
}
|
|
215
|
+
function exit(code) {
|
|
216
|
+
cancel('exiting...');
|
|
217
|
+
const { exit } = options.api.useExposed(Symbol.for('rspeedy.api'));
|
|
218
|
+
return exit(code);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function pluginQRCode(options) {
|
|
222
|
+
const defaultPluginOptions = {
|
|
223
|
+
schema: (url)=>({
|
|
224
|
+
http: url
|
|
225
|
+
})
|
|
226
|
+
};
|
|
227
|
+
const { schema } = Object.assign({}, defaultPluginOptions, options);
|
|
228
|
+
return {
|
|
229
|
+
name: 'lynx:rsbuild:qrcode',
|
|
230
|
+
pre: [
|
|
231
|
+
'lynx:rsbuild:api'
|
|
232
|
+
],
|
|
233
|
+
setup (api) {
|
|
234
|
+
api.onAfterStartProdServer(async ({ environments, port })=>{
|
|
235
|
+
await main(environments['lynx'], port);
|
|
236
|
+
});
|
|
237
|
+
api.onDevCompileDone(async ({ isFirstCompile, stats, environments })=>{
|
|
238
|
+
if (!api.context.devServer) return;
|
|
239
|
+
if (!isFirstCompile) return;
|
|
240
|
+
if (stats.hasErrors()) return;
|
|
241
|
+
await main(environments['lynx'], api.context.devServer.port);
|
|
242
|
+
});
|
|
243
|
+
api.modifyRsbuildConfig((config)=>{
|
|
244
|
+
const originalPrintUrl = config.server?.printUrls;
|
|
245
|
+
if (false === originalPrintUrl || 'function' == typeof originalPrintUrl) return;
|
|
246
|
+
config.server ??= {};
|
|
247
|
+
config.server.printUrls = false;
|
|
248
|
+
});
|
|
249
|
+
async function main(environmentContext, port) {
|
|
250
|
+
if (!environmentContext) return;
|
|
251
|
+
const entries = Object.keys(environmentContext.entry);
|
|
252
|
+
if (0 === entries.length) return;
|
|
253
|
+
const unregister = await registerConsoleShortcuts({
|
|
254
|
+
entries,
|
|
255
|
+
api,
|
|
256
|
+
port,
|
|
257
|
+
schema
|
|
258
|
+
});
|
|
259
|
+
api.onCloseDevServer(unregister);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
export { pluginQRCode };
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__ from "node:process";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_readline_91c31510__ from "node:readline";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_tty_c64aab7e__ from "node:tty";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__ from "node:util";
|
|
5
|
+
var __webpack_modules__ = {
|
|
6
|
+
"node:process": function(module) {
|
|
7
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__;
|
|
8
|
+
},
|
|
9
|
+
"node:readline": function(module) {
|
|
10
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_readline_91c31510__;
|
|
11
|
+
},
|
|
12
|
+
"node:tty": function(module) {
|
|
13
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_tty_c64aab7e__;
|
|
14
|
+
},
|
|
15
|
+
"node:util": function(module) {
|
|
16
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var __webpack_module_cache__ = {};
|
|
20
|
+
function __webpack_require__(moduleId) {
|
|
21
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
22
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
23
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
24
|
+
exports: {}
|
|
25
|
+
};
|
|
26
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
27
|
+
return module.exports;
|
|
28
|
+
}
|
|
29
|
+
__webpack_require__.m = __webpack_modules__;
|
|
30
|
+
(()=>{
|
|
31
|
+
__webpack_require__.n = (module)=>{
|
|
32
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
33
|
+
__webpack_require__.d(getter, {
|
|
34
|
+
a: getter
|
|
35
|
+
});
|
|
36
|
+
return getter;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
(()=>{
|
|
40
|
+
__webpack_require__.d = (exports, definition)=>{
|
|
41
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: definition[key]
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
(()=>{
|
|
48
|
+
__webpack_require__.f = {};
|
|
49
|
+
__webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>{
|
|
50
|
+
__webpack_require__.f[key](chunkId, promises);
|
|
51
|
+
return promises;
|
|
52
|
+
}, []));
|
|
53
|
+
})();
|
|
54
|
+
(()=>{
|
|
55
|
+
__webpack_require__.u = (chunkId)=>"" + chunkId + ".js";
|
|
56
|
+
})();
|
|
57
|
+
(()=>{
|
|
58
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
59
|
+
})();
|
|
60
|
+
(()=>{
|
|
61
|
+
__webpack_require__.r = (exports)=>{
|
|
62
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
|
|
63
|
+
value: 'Module'
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(exports, '__esModule', {
|
|
66
|
+
value: true
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
})();
|
|
70
|
+
(()=>{
|
|
71
|
+
var installedChunks = {
|
|
72
|
+
480: 0
|
|
73
|
+
};
|
|
74
|
+
var installChunk = (data)=>{
|
|
75
|
+
var __webpack_ids__ = data.__webpack_ids__;
|
|
76
|
+
var __webpack_modules__ = data.__webpack_modules__;
|
|
77
|
+
var __webpack_runtime__ = data.__webpack_runtime__;
|
|
78
|
+
var moduleId, chunkId, i = 0;
|
|
79
|
+
for(moduleId in __webpack_modules__)if (__webpack_require__.o(__webpack_modules__, moduleId)) __webpack_require__.m[moduleId] = __webpack_modules__[moduleId];
|
|
80
|
+
if (__webpack_runtime__) __webpack_runtime__(__webpack_require__);
|
|
81
|
+
for(; i < __webpack_ids__.length; i++){
|
|
82
|
+
chunkId = __webpack_ids__[i];
|
|
83
|
+
if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
|
|
84
|
+
installedChunks[__webpack_ids__[i]] = 0;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
__webpack_require__.f.j = function(chunkId, promises) {
|
|
88
|
+
var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
|
|
89
|
+
if (0 !== installedChunkData) if (installedChunkData) promises.push(installedChunkData[1]);
|
|
90
|
+
else {
|
|
91
|
+
var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, (e)=>{
|
|
92
|
+
if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0;
|
|
93
|
+
throw e;
|
|
94
|
+
});
|
|
95
|
+
var promise = Promise.race([
|
|
96
|
+
promise,
|
|
97
|
+
new Promise((resolve)=>{
|
|
98
|
+
installedChunkData = installedChunks[chunkId] = [
|
|
99
|
+
resolve
|
|
100
|
+
];
|
|
101
|
+
})
|
|
102
|
+
]);
|
|
103
|
+
promises.push(installedChunkData[1] = promise);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
})();
|
|
107
|
+
function generateDevUrls(api, entry, schemaFn, port) {
|
|
108
|
+
const { dev: { assetPrefix } } = api.getNormalizedConfig();
|
|
109
|
+
const { config } = api.useExposed(Symbol.for('rspeedy.api'));
|
|
110
|
+
if ('string' != typeof assetPrefix) {
|
|
111
|
+
const errorMsg = 'dev.assetPrefix is not string, skip printing QRCode';
|
|
112
|
+
throw new Error(errorMsg);
|
|
113
|
+
}
|
|
114
|
+
const defaultFilename = '[name].[platform].bundle';
|
|
115
|
+
const { filename } = config.output ?? {};
|
|
116
|
+
let name;
|
|
117
|
+
name = filename ? 'object' == typeof filename ? filename.bundle ?? filename.template ?? defaultFilename : filename : defaultFilename;
|
|
118
|
+
const customSchema = schemaFn(new URL(name.replace('[name]', entry).replace('[platform]', 'lynx'), assetPrefix.replaceAll('<port>', String(port))).toString());
|
|
119
|
+
return 'string' == typeof customSchema ? {
|
|
120
|
+
default: customSchema
|
|
121
|
+
} : customSchema;
|
|
122
|
+
}
|
|
123
|
+
const gExistingShortcuts = new WeakSet();
|
|
124
|
+
async function registerConsoleShortcuts(options) {
|
|
125
|
+
const [{ default: showQRCode }] = await Promise.all([
|
|
126
|
+
Promise.all([
|
|
127
|
+
__webpack_require__.e("517"),
|
|
128
|
+
__webpack_require__.e("640"),
|
|
129
|
+
__webpack_require__.e("113")
|
|
130
|
+
]).then(__webpack_require__.bind(__webpack_require__, "./src/showQRCode.ts"))
|
|
131
|
+
]);
|
|
132
|
+
const currentEntry = options.entries[0];
|
|
133
|
+
const devUrls = generateDevUrls(options.api, currentEntry, options.schema, options.port);
|
|
134
|
+
const value = Object.values(devUrls)[0];
|
|
135
|
+
await options.onPrint?.(value);
|
|
136
|
+
showQRCode(value);
|
|
137
|
+
gExistingShortcuts.add(options);
|
|
138
|
+
loop(options, value, devUrls);
|
|
139
|
+
function off() {
|
|
140
|
+
gExistingShortcuts.delete(options);
|
|
141
|
+
}
|
|
142
|
+
return off;
|
|
143
|
+
}
|
|
144
|
+
async function loop(options, value, devUrls) {
|
|
145
|
+
const [{ select, selectKey, isCancel, cancel }, { default: showQRCode }] = await Promise.all([
|
|
146
|
+
__webpack_require__.e("517").then(__webpack_require__.bind(__webpack_require__, "../../../node_modules/.pnpm/@clack+prompts@0.10.0/node_modules/@clack/prompts/dist/index.mjs")),
|
|
147
|
+
Promise.all([
|
|
148
|
+
__webpack_require__.e("517"),
|
|
149
|
+
__webpack_require__.e("640"),
|
|
150
|
+
__webpack_require__.e("113")
|
|
151
|
+
]).then(__webpack_require__.bind(__webpack_require__, "./src/showQRCode.ts"))
|
|
152
|
+
]);
|
|
153
|
+
let currentEntry = options.entries[0];
|
|
154
|
+
let currentSchema = Object.keys(devUrls)[0];
|
|
155
|
+
while(!isCancel(value)){
|
|
156
|
+
const name = await selectKey({
|
|
157
|
+
message: 'Usage',
|
|
158
|
+
options: [
|
|
159
|
+
{
|
|
160
|
+
value: 'r',
|
|
161
|
+
label: 'Switch entries'
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
value: 'a',
|
|
165
|
+
label: 'Switch schema'
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
value: 'h',
|
|
169
|
+
label: 'Help'
|
|
170
|
+
},
|
|
171
|
+
...Object.values(options.customShortcuts ?? {}),
|
|
172
|
+
{
|
|
173
|
+
value: 'q',
|
|
174
|
+
label: 'Quit'
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
initialValue: 'q'
|
|
178
|
+
});
|
|
179
|
+
if (isCancel(name) || 'q' === name || !gExistingShortcuts.has(options)) break;
|
|
180
|
+
if ('r' === name) {
|
|
181
|
+
const selection = await select({
|
|
182
|
+
message: 'Select entry',
|
|
183
|
+
options: options.entries.map((entry)=>({
|
|
184
|
+
value: entry,
|
|
185
|
+
label: entry,
|
|
186
|
+
hint: generateDevUrls(options.api, entry, options.schema, options.port)[currentSchema]
|
|
187
|
+
})),
|
|
188
|
+
initialValue: currentEntry
|
|
189
|
+
});
|
|
190
|
+
if (isCancel(selection)) break;
|
|
191
|
+
currentEntry = selection;
|
|
192
|
+
value = getCurrentUrl();
|
|
193
|
+
} else if ('a' === name) {
|
|
194
|
+
const devUrls = generateDevUrls(options.api, currentEntry, options.schema, options.port);
|
|
195
|
+
const selection = await select({
|
|
196
|
+
message: 'Select schema',
|
|
197
|
+
options: Object.entries(devUrls).map(([name, url])=>({
|
|
198
|
+
value: name,
|
|
199
|
+
label: name,
|
|
200
|
+
hint: url
|
|
201
|
+
})),
|
|
202
|
+
initialValue: currentSchema
|
|
203
|
+
});
|
|
204
|
+
if (isCancel(selection)) break;
|
|
205
|
+
currentSchema = selection;
|
|
206
|
+
value = getCurrentUrl();
|
|
207
|
+
} else if (options.customShortcuts?.[name]) await options.customShortcuts[name].action?.();
|
|
208
|
+
await options.onPrint?.(value);
|
|
209
|
+
showQRCode(value);
|
|
210
|
+
}
|
|
211
|
+
if (gExistingShortcuts.has(options)) await exit(1);
|
|
212
|
+
function getCurrentUrl() {
|
|
213
|
+
return generateDevUrls(options.api, currentEntry, options.schema, options.port)[currentSchema];
|
|
214
|
+
}
|
|
215
|
+
function exit(code) {
|
|
216
|
+
cancel('exiting...');
|
|
217
|
+
const { exit } = options.api.useExposed(Symbol.for('rspeedy.api'));
|
|
218
|
+
return exit(code);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
export { registerConsoleShortcuts };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function showQRCode(url: string): void;
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/qrcode-rsbuild-plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "A rsbuild plugin for printing QRCode in terminal",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rsbuild",
|
|
7
7
|
"Lynx",
|
|
8
8
|
"ReactLynx"
|
|
9
9
|
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/lynx-family/lynx-stack.git",
|
|
13
|
+
"directory": "packages/rspeedy/plugin-qrcode"
|
|
14
|
+
},
|
|
10
15
|
"license": "Apache-2.0",
|
|
11
16
|
"author": {
|
|
12
17
|
"name": "Qingyu Wang",
|
|
@@ -15,45 +20,45 @@
|
|
|
15
20
|
"type": "module",
|
|
16
21
|
"exports": {
|
|
17
22
|
".": {
|
|
18
|
-
"types": "./
|
|
19
|
-
"default": "./
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
20
25
|
},
|
|
21
26
|
"./shortcuts": {
|
|
22
|
-
"types": "./
|
|
23
|
-
"default": "./
|
|
27
|
+
"types": "./dist/shortcuts.d.ts",
|
|
28
|
+
"default": "./dist/shortcuts.js"
|
|
24
29
|
},
|
|
25
30
|
"./package.json": "./package.json"
|
|
26
31
|
},
|
|
27
|
-
"types": "./
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
28
33
|
"typesVersions": {
|
|
29
34
|
"*": {
|
|
30
35
|
"shortcuts": [
|
|
31
|
-
"
|
|
36
|
+
"dist/shortcuts.d.ts"
|
|
32
37
|
]
|
|
33
38
|
}
|
|
34
39
|
},
|
|
35
40
|
"files": [
|
|
36
|
-
"
|
|
37
|
-
"!lib/**/*.js.map",
|
|
41
|
+
"dist",
|
|
38
42
|
"CHANGELOG.md",
|
|
39
43
|
"README.md"
|
|
40
44
|
],
|
|
41
|
-
"
|
|
45
|
+
"devDependencies": {
|
|
42
46
|
"@clack/prompts": "^0.10.0",
|
|
47
|
+
"@microsoft/api-extractor": "7.52.2",
|
|
48
|
+
"@rsbuild/core": "1.3.2",
|
|
43
49
|
"picocolors": "^1.1.1",
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@microsoft/api-extractor": "7.51.0",
|
|
48
|
-
"@rsbuild/core": "1.2.11",
|
|
49
|
-
"@types/qrcode-terminal": "^0.12.2",
|
|
50
|
-
"@lynx-js/rspeedy": "0.8.2"
|
|
50
|
+
"uqr": "0.1.2",
|
|
51
|
+
"@lynx-js/rspeedy": "0.9.0"
|
|
51
52
|
},
|
|
52
53
|
"engines": {
|
|
53
54
|
"node": ">=18"
|
|
54
55
|
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
55
59
|
"scripts": {
|
|
56
60
|
"api-extractor": "api-extractor run --verbose",
|
|
61
|
+
"build": "rslib build",
|
|
57
62
|
"test": "pnpm -w run test --project rspeedy/qrcode"
|
|
58
63
|
}
|
|
59
64
|
}
|
package/lib/generateDevUrls.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export default function generateDevUrls(api, entry, schemaFn, port) {
|
|
2
|
-
const { dev: { assetPrefix } } = api.getNormalizedConfig();
|
|
3
|
-
const { config } = api.useExposed(Symbol.for('rspeedy.api'));
|
|
4
|
-
if (typeof assetPrefix !== 'string') {
|
|
5
|
-
const errorMsg = 'dev.assetPrefix is not string, skip printing QRCode';
|
|
6
|
-
// Rspeedy will normalized dev.assetPrefix to string
|
|
7
|
-
throw new Error(errorMsg);
|
|
8
|
-
}
|
|
9
|
-
const defaultFilename = '[name].[platform].bundle';
|
|
10
|
-
const { filename } = config.output ?? {};
|
|
11
|
-
let name;
|
|
12
|
-
if (!filename) {
|
|
13
|
-
name = defaultFilename;
|
|
14
|
-
}
|
|
15
|
-
else if (typeof filename === 'object') {
|
|
16
|
-
name = filename.bundle ?? filename.template ?? defaultFilename;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
name = filename;
|
|
20
|
-
}
|
|
21
|
-
const customSchema = schemaFn(new URL(name.replace('[name]', entry).replace('[platform]', 'lynx'),
|
|
22
|
-
// <port> is supported in `dev.assetPrefix`, we should replace it with the real port
|
|
23
|
-
assetPrefix.replaceAll('<port>', String(port))).toString());
|
|
24
|
-
return typeof customSchema === 'string'
|
|
25
|
-
? { default: customSchema }
|
|
26
|
-
: customSchema;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=generateDevUrls.js.map
|
package/lib/index.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { registerConsoleShortcuts } from './shortcuts.js';
|
|
5
|
-
/**
|
|
6
|
-
* Create a rsbuild plugin for printing QRCode.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* // rsbuild.config.ts
|
|
11
|
-
* import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin'
|
|
12
|
-
* export default {
|
|
13
|
-
* plugins: [pluginQRCode()],
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export function pluginQRCode(options) {
|
|
20
|
-
const defaultPluginOptions = {
|
|
21
|
-
schema: (url) => ({ http: url }),
|
|
22
|
-
};
|
|
23
|
-
const { schema } = Object.assign({}, defaultPluginOptions, options);
|
|
24
|
-
return {
|
|
25
|
-
name: 'lynx:rsbuild:qrcode',
|
|
26
|
-
pre: ['lynx:rsbuild:api'],
|
|
27
|
-
setup(api) {
|
|
28
|
-
api.onAfterStartProdServer(async ({ environments, port }) => {
|
|
29
|
-
await main(environments['lynx'], port);
|
|
30
|
-
});
|
|
31
|
-
api.onDevCompileDone(async ({ isFirstCompile, stats, environments }) => {
|
|
32
|
-
if (!api.context.devServer) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if (!isFirstCompile) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (stats.hasErrors()) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
await main(environments['lynx'], api.context.devServer.port);
|
|
42
|
-
});
|
|
43
|
-
api.modifyRsbuildConfig((config) => {
|
|
44
|
-
const originalPrintUrl = config.server?.printUrls;
|
|
45
|
-
if (originalPrintUrl === false || typeof originalPrintUrl === 'function') {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
config.server ??= {};
|
|
49
|
-
config.server.printUrls = false;
|
|
50
|
-
});
|
|
51
|
-
async function main(environmentContext, port) {
|
|
52
|
-
if (!environmentContext) {
|
|
53
|
-
// Not lynx environment, skip print QRCode
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const entries = Object.keys(environmentContext.entry);
|
|
57
|
-
if (entries.length === 0) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const unregister = await registerConsoleShortcuts({
|
|
61
|
-
entries,
|
|
62
|
-
api,
|
|
63
|
-
port,
|
|
64
|
-
schema,
|
|
65
|
-
});
|
|
66
|
-
api.onCloseDevServer(unregister);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=index.js.map
|