@shijiu/jsview 2.1.435 → 2.1.476-test.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.
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import {
7
+ askAndAnswer,
8
+ checkNodeVersion,
9
+ execCommand,
10
+ getNetworkIpv4Addresses,
11
+ getOptions,
12
+ parseArguments,
13
+ Logger,
14
+ } from './jsview-common.mjs';
15
+
16
+ function getDefaultPort() {
17
+ return 8098;
18
+ }
19
+
20
+ async function getExtraOptions(argv)
21
+ {
22
+ const options = getOptions(argv.framework);
23
+
24
+ options.hostIp = 'your-pc-ip';
25
+ const addresses = getNetworkIpv4Addresses();
26
+ if(addresses.length > 0) {
27
+ options.hostIp = addresses[0];
28
+ }
29
+ options.hostPort = argv.port ?? getDefaultPort();
30
+
31
+ if(process.platform == 'win32' && options.hostPort != getDefaultPort()) {
32
+ Logger.ErrorAndExit("Windows can't support to set custom port to Vue DevTools standalone application. please use default value.")
33
+ }
34
+
35
+ return options;
36
+ }
37
+
38
+ async function runVueDevtoolsStandalone(options)
39
+ {
40
+ const vuedtFilePath = options.modulesDir + '/.bin/vue-devtools';
41
+
42
+ var exportPrefix = 'export';
43
+ if(process.platform == 'win32') {
44
+ exportPrefix = 'set'
45
+ }
46
+
47
+ if (fs.existsSync(vuedtFilePath) == false
48
+ || fs.existsSync(options.modulesDir + '/electron') == false) {
49
+ Logger.ErrorNoException('Vue DevTools standalone application is not found.')
50
+ Logger.Info(' Do you want to install it thought "@vue/vue-devtools@6.5.1"?');
51
+ const answer = askAndAnswer('(y/N) ');
52
+ if (answer.substring(0, 1) != 'y' && answer.substring(0, 3) != 'yes') {
53
+ Logger.ErrorAndExitNoSilent('User cancelled.')
54
+ }
55
+
56
+ const exportElectronMirror = exportPrefix + ' ELECTRON_MIRROR=http://cdn.release.qcast.cn/RN_devtools/electron-env/'
57
+ let cmdline = exportElectronMirror + ' && npm install --package-lock-only --save-exact --save-dev electron@21.4.4 @vue/devtools@6.5.1'
58
+ execCommand(cmdline);
59
+ cmdline = exportElectronMirror + ' && npm ci'
60
+ execCommand(cmdline);
61
+
62
+ console.log()
63
+ console.log()
64
+ Logger.Tip(" *** NOTICE ***:")
65
+ Logger.Tip(" Don't forget to add the following code at the beginning of your source entry ['main.ts' or 'main.tsx']:")
66
+ console.log(" if (process.env.NODE_ENV === 'development') {")
67
+ console.log(" window.requestAnimationFrame = (callback) => setTimeout(callback, 0)")
68
+ console.log(" const devtools = await import('@vue/devtools')")
69
+ console.log(" devtools.connect('" + options.hostIp + "', " + options.hostPort + ")")
70
+ console.log(" console.warn('@vue/devtools has been ready.')")
71
+ console.log(" }")
72
+ console.log()
73
+ }
74
+
75
+ var cmdline = /* 不要添加 `node `,windows cmd执行出错 */ path.relative(options.projectDir, vuedtFilePath)
76
+ if(process.platform != 'win32') { // 在Window系统上设置port 会导致WebSocket连接失败。
77
+ cmdline = (exportPrefix + ' PORT=' + options.hostPort + ' && ' + cmdline);
78
+ }
79
+ execCommand(cmdline);
80
+ }
81
+
82
+ async function main(argv)
83
+ {
84
+ checkNodeVersion();
85
+
86
+ const options = await getExtraOptions(argv);
87
+
88
+ runVueDevtoolsStandalone(options);
89
+ }
90
+
91
+ const requiredUsages = {
92
+ };
93
+ const optionalUsages = {
94
+ '--port': 'Set vue devtools standalone server port. default is: ' + getDefaultPort(),
95
+ };
96
+ const argv = parseArguments(requiredUsages, optionalUsages, false);
97
+ main(argv)