scripting-cli 1.0.2 → 1.0.4
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/build.js +15 -0
- package/dist/config/AppJsonPlugin.js +57 -26
- package/dist/config/webpack.config.js +24 -8
- package/dist/createApp.js +90 -47
- package/dist/startDevServer.js +31 -16
- package/package.json +8 -8
- package/public/assets.d.ts +40 -0
- package/public/logo.svg +4 -0
- package/public/scripting.d.ts +123 -410
- package/src/build.ts +28 -0
- package/src/config/AppJsonPlugin.ts +80 -39
- package/src/config/webpack.config.ts +34 -6
- package/src/createApp.ts +120 -51
- package/src/startDevServer.ts +24 -11
package/dist/build.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.buildApp = void 0;
|
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const webpack_1 = __importDefault(require("webpack"));
|
|
9
9
|
const webpack_config_1 = __importDefault(require("./config/webpack.config"));
|
|
10
|
+
const cross_zip_1 = require("cross-zip");
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
12
|
function buildApp() {
|
|
11
13
|
const compiler = (0, webpack_1.default)(webpack_config_1.default);
|
|
12
14
|
console.log('Start running build...\n'
|
|
@@ -26,7 +28,20 @@ function buildApp() {
|
|
|
26
28
|
chunks: false,
|
|
27
29
|
colors: false,
|
|
28
30
|
}));
|
|
31
|
+
createAppFile();
|
|
29
32
|
}
|
|
30
33
|
});
|
|
31
34
|
}
|
|
32
35
|
exports.buildApp = buildApp;
|
|
36
|
+
function createAppFile() {
|
|
37
|
+
const appFile = `${Object.keys(webpack_config_1.default.entry)[0]}.zip`;
|
|
38
|
+
console.log(` ~ Creating ${appFile}....`);
|
|
39
|
+
(0, cross_zip_1.zip)(node_path_1.default.resolve(process.cwd(), './build'), node_path_1.default.resolve(process.cwd(), `./build/${appFile}`), (error) => {
|
|
40
|
+
if (error != null) {
|
|
41
|
+
console.log(chalk_1.default.red('Error zipping app files: \n') + error);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.log(chalk_1.default.green(` ✔️ ${appFile} created.`));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -22,33 +22,64 @@ class AppJsonPlugin {
|
|
|
22
22
|
// 确保所有资源已被插件添加到 compilation
|
|
23
23
|
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,
|
|
24
24
|
}, (assets) => {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const appJson = {
|
|
26
|
+
name: '',
|
|
27
|
+
index: '',
|
|
28
|
+
hash: '',
|
|
29
|
+
assets: Object.keys(assets),
|
|
30
|
+
};
|
|
31
|
+
const indexJs = appJson.assets.find(filePath => filePath.match(/\.js$/i) != null);
|
|
32
|
+
if (indexJs != null) {
|
|
33
|
+
const [appName, ...others] = indexJs.split('/');
|
|
28
34
|
const filePath = others[others.length - 1];
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
appJson.name = appName;
|
|
36
|
+
appJson.index = filePath;
|
|
37
|
+
appJson.hash = filePath.replace('.js', '');
|
|
38
|
+
const indexJsSource = assets[indexJs];
|
|
39
|
+
appJson.assets = [
|
|
40
|
+
...appJson.assets.filter(e => e !== indexJs),
|
|
41
|
+
filePath,
|
|
42
|
+
];
|
|
43
|
+
compilation.deleteAsset(indexJs);
|
|
44
|
+
compilation.emitAsset(filePath, indexJsSource);
|
|
45
|
+
}
|
|
46
|
+
compilation.emitAsset('app.json', new RawSource(JSON.stringify(appJson, null, 2)));
|
|
47
|
+
// const appMap: {
|
|
48
|
+
// [appName: string]: {
|
|
49
|
+
// appName: string
|
|
50
|
+
// index: string
|
|
51
|
+
// hash: string
|
|
52
|
+
// }
|
|
53
|
+
// } = {}
|
|
54
|
+
// Object.keys(assets).forEach(path => {
|
|
55
|
+
// const [appName, ...others] = path.split('/')
|
|
56
|
+
// const filePath = others[others.length - 1]
|
|
57
|
+
// // console.log(appName, filePath)
|
|
58
|
+
// // if (appMap[appName] == null) {
|
|
59
|
+
// // appMap[appName] = {
|
|
60
|
+
// // appName,
|
|
61
|
+
// // // assets: [],
|
|
62
|
+
// // }
|
|
63
|
+
// // }
|
|
64
|
+
// if (filePath.match(/\.js$/i)) {
|
|
65
|
+
// appMap[appName] = {
|
|
66
|
+
// appName,
|
|
67
|
+
// index: filePath,
|
|
68
|
+
// hash: filePath.replace('.js', '')
|
|
69
|
+
// }
|
|
70
|
+
// // appMap[appName].index = filePath
|
|
71
|
+
// // appMap[appName].hash = filePath.replace('.js', '')
|
|
72
|
+
// }
|
|
73
|
+
// // else if (filePath.match(/\.(png|jpe?g|gif|svg)$/i)) {
|
|
74
|
+
// // appMap[appName].assets.push(path.replace(appName + '/', ''))
|
|
75
|
+
// // }
|
|
76
|
+
// })
|
|
77
|
+
// Object.entries(appMap).forEach(([appName, content]) => {
|
|
78
|
+
// compilation.emitAsset(
|
|
79
|
+
// appName + '/app.json',
|
|
80
|
+
// new RawSource(JSON.stringify(content, null, 2))
|
|
81
|
+
// )
|
|
82
|
+
// })
|
|
52
83
|
// "assets" 是一个包含 compilation 中所有资源(assets)的对象。
|
|
53
84
|
// 该对象的键是资源的路径,
|
|
54
85
|
// 值是文件的源码
|
|
@@ -3,15 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
9
|
const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
|
|
8
10
|
const AppJsonPlugin_1 = __importDefault(require("./AppJsonPlugin"));
|
|
9
|
-
const baseDir =
|
|
10
|
-
const srcDir =
|
|
11
|
-
const buildDir =
|
|
11
|
+
const baseDir = process.cwd();
|
|
12
|
+
const srcDir = node_path_1.default.resolve(baseDir, 'src');
|
|
13
|
+
const buildDir = node_path_1.default.resolve(baseDir, 'build');
|
|
14
|
+
const pkgPath = node_path_1.default.resolve(baseDir, 'package.json');
|
|
15
|
+
if (!node_fs_1.default.existsSync(pkgPath)) {
|
|
16
|
+
console.log(chalk_1.default.red('✖️ package.json not found.'));
|
|
17
|
+
process.exit(404);
|
|
18
|
+
}
|
|
19
|
+
const pkg = JSON.parse(node_fs_1.default.readFileSync(pkgPath, 'utf8'));
|
|
20
|
+
const entry = {
|
|
21
|
+
[pkg.name]: node_path_1.default.join(srcDir, 'index.tsx'),
|
|
22
|
+
};
|
|
12
23
|
const config = {
|
|
13
24
|
mode: 'production',
|
|
14
|
-
entry
|
|
25
|
+
entry,
|
|
15
26
|
optimization: {
|
|
16
27
|
moduleIds: 'deterministic',
|
|
17
28
|
chunkIds: 'named',
|
|
@@ -59,15 +70,17 @@ const config = {
|
|
|
59
70
|
},
|
|
60
71
|
resolve: {
|
|
61
72
|
extensions: ['.tsx', '.ts', '.js'],
|
|
62
|
-
modules: [
|
|
73
|
+
modules: [
|
|
74
|
+
'node_modules',
|
|
75
|
+
srcDir,
|
|
76
|
+
],
|
|
63
77
|
alias: {
|
|
64
78
|
'@': srcDir,
|
|
65
79
|
}
|
|
66
80
|
},
|
|
67
81
|
output: {
|
|
68
|
-
// filename: 'index.js',
|
|
69
|
-
// filename: '[name]/index.js',
|
|
70
82
|
filename: '[name]/[contenthash:8].js',
|
|
83
|
+
// filename: '[contenthash:8].js',
|
|
71
84
|
path: buildDir,
|
|
72
85
|
clean: true,
|
|
73
86
|
},
|
|
@@ -75,5 +88,8 @@ const config = {
|
|
|
75
88
|
new AppJsonPlugin_1.default(),
|
|
76
89
|
],
|
|
77
90
|
devtool: false,
|
|
91
|
+
externals: {
|
|
92
|
+
'scripting': 'Scripting',
|
|
93
|
+
}
|
|
78
94
|
};
|
|
79
95
|
exports.default = config;
|
package/dist/createApp.js
CHANGED
|
@@ -15,18 +15,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.createApp = void 0;
|
|
16
16
|
const chalk_1 = __importDefault(require("chalk"));
|
|
17
17
|
const node_path_1 = __importDefault(require("node:path"));
|
|
18
|
+
const node_child_process_1 = require("node:child_process");
|
|
18
19
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
19
20
|
const promises_1 = require("node:fs/promises");
|
|
20
|
-
console.log(__dirname);
|
|
21
21
|
function getAppDir(appName) {
|
|
22
|
-
return node_path_1.default.join(
|
|
22
|
+
return node_path_1.default.join(process.cwd(), appName);
|
|
23
23
|
}
|
|
24
24
|
function createAppDir(appName) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const
|
|
27
|
-
if (node_fs_1.default.existsSync(
|
|
26
|
+
const appDir = getAppDir(appName);
|
|
27
|
+
if (node_fs_1.default.existsSync(appDir)) {
|
|
28
28
|
throw new Error(`Directory "./${appName}" already exists.`);
|
|
29
29
|
}
|
|
30
|
+
const dir = node_path_1.default.resolve(appDir, 'src/svgs');
|
|
30
31
|
yield (0, promises_1.mkdir)(dir, { recursive: true });
|
|
31
32
|
});
|
|
32
33
|
}
|
|
@@ -35,37 +36,66 @@ function createEntryFile(appName) {
|
|
|
35
36
|
console.log(` > Creating ${appName}/src/index.tsx ...`);
|
|
36
37
|
const filePath = node_path_1.default.join(getAppDir(appName), '/src/index.tsx');
|
|
37
38
|
yield (0, promises_1.writeFile)(filePath, `
|
|
38
|
-
const { runApp, createElement, RouterProvider, Router, } = Scripting
|
|
39
|
-
const { Center, Text, CupertinoPageScaffold, CupertinoNavigationBar, } = Scripting.Widgets
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
import { runApp, createElement, RouterProvider, Router, Column, CupertinoNavigationBar, CupertinoPageScaffold, Svg, Text, Container, Color } from 'scripting'
|
|
41
|
+
import Logo from './svgs/logo.svg'
|
|
42
|
+
|
|
43
|
+
function ScriptingLogo() {
|
|
44
|
+
return (
|
|
45
|
+
<Container
|
|
46
|
+
clipBehavior={'hardEdge'}
|
|
47
|
+
width={80}
|
|
48
|
+
height={80}
|
|
49
|
+
margin={{
|
|
50
|
+
vertical: 100,
|
|
51
|
+
}}
|
|
52
|
+
borderRadius={16}
|
|
53
|
+
>
|
|
54
|
+
<Svg src={Logo} />
|
|
55
|
+
</Container>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function HomePage() {
|
|
60
|
+
const backgroundColor: Color = '#ffffff'
|
|
61
|
+
return (
|
|
62
|
+
<CupertinoPageScaffold
|
|
63
|
+
navigationBar={
|
|
64
|
+
<CupertinoNavigationBar
|
|
65
|
+
middle={
|
|
66
|
+
<Text>${appName}</Text>
|
|
67
|
+
}
|
|
68
|
+
backgroundColor={backgroundColor}
|
|
69
|
+
/>
|
|
48
70
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
>
|
|
72
|
+
<Container
|
|
73
|
+
width={'infinity'}
|
|
74
|
+
height={'infinity'}
|
|
75
|
+
color={backgroundColor}
|
|
76
|
+
>
|
|
77
|
+
<Column
|
|
78
|
+
crossAxisAlignment={'center'}
|
|
79
|
+
>
|
|
80
|
+
<ScriptingLogo />
|
|
81
|
+
<Text>Welcome to Scripting!</Text>
|
|
82
|
+
</Column>
|
|
83
|
+
</Container>
|
|
84
|
+
</CupertinoPageScaffold>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const router = new Router([
|
|
89
|
+
{
|
|
90
|
+
path: '/',
|
|
91
|
+
element: <HomePage />,
|
|
92
|
+
},
|
|
93
|
+
])
|
|
94
|
+
|
|
95
|
+
runApp(
|
|
96
|
+
<RouterProvider router={router} />
|
|
97
|
+
)
|
|
98
|
+
|
|
69
99
|
`, 'utf-8');
|
|
70
100
|
console.log(chalk_1.default.green(` ✔️ Created ${appName}/src/index.tsx`));
|
|
71
101
|
});
|
|
@@ -92,17 +122,11 @@ function createReadme(appName) {
|
|
|
92
122
|
const filePath = node_path_1.default.join(getAppDir(appName), 'README.md');
|
|
93
123
|
yield (0, promises_1.writeFile)(filePath, `# ${appName} - A Scripting application
|
|
94
124
|
|
|
95
|
-
##
|
|
96
|
-
|
|
97
|
-
### Installation
|
|
98
|
-
|
|
99
|
-
\`npm install\`
|
|
100
|
-
|
|
101
|
-
### Start dev server
|
|
125
|
+
## Start dev server
|
|
102
126
|
|
|
103
127
|
\`npm run dev\`
|
|
104
128
|
|
|
105
|
-
|
|
129
|
+
## Build App
|
|
106
130
|
|
|
107
131
|
\`npm run build\`
|
|
108
132
|
`, 'utf-8');
|
|
@@ -146,15 +170,32 @@ function createTSConfig(appName) {
|
|
|
146
170
|
console.log(chalk_1.default.green(` ✔️ Created ${appName}/tsconfig.json`));
|
|
147
171
|
});
|
|
148
172
|
}
|
|
149
|
-
function
|
|
173
|
+
function copyAssets(appName) {
|
|
150
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
175
|
console.log(` > Creating ${appName}/src/scripting.d.ts ...`);
|
|
152
|
-
|
|
153
|
-
const destPath = node_path_1.default.join(getAppDir(appName), 'src/scripting.d.ts');
|
|
154
|
-
yield (0, promises_1.copyFile)(srcPath, destPath);
|
|
176
|
+
yield (0, promises_1.copyFile)(node_path_1.default.join(__dirname, '../public/scripting.d.ts'), node_path_1.default.join(getAppDir(appName), 'src/scripting.d.ts'));
|
|
155
177
|
console.log(chalk_1.default.green(` ✔️ Created ${appName}/src/scripting.d.ts`));
|
|
178
|
+
console.log(` > Creating ${appName}/src/assets.d.ts ...`);
|
|
179
|
+
yield (0, promises_1.copyFile)(node_path_1.default.join(__dirname, '../public/assets.d.ts'), node_path_1.default.join(getAppDir(appName), 'src/assets.d.ts'));
|
|
180
|
+
console.log(chalk_1.default.green(` ✔️ Created ${appName}/src/assets.d.ts`));
|
|
181
|
+
console.log(` > Creating ${appName}/src/svgs/logo.svg ...`);
|
|
182
|
+
yield (0, promises_1.copyFile)(node_path_1.default.join(__dirname, '../public/logo.svg'), node_path_1.default.join(getAppDir(appName), 'src/svgs/logo.svg'));
|
|
183
|
+
console.log(chalk_1.default.green(` ✔️ Created ${appName}/src/svgs/logo.svg`));
|
|
156
184
|
});
|
|
157
185
|
}
|
|
186
|
+
function createVSCodeSettings(appName) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const destDir = node_path_1.default.join(process.cwd(), '.vscode');
|
|
189
|
+
if (!node_fs_1.default.existsSync(destDir)) {
|
|
190
|
+
yield (0, promises_1.mkdir)(destDir);
|
|
191
|
+
}
|
|
192
|
+
yield (0, promises_1.copyFile)(node_path_1.default.join(__dirname, '../.vscode/settings.json'), node_path_1.default.join(getAppDir(appName), '.vscode/settings.json'));
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
function installDeps(appName) {
|
|
196
|
+
(0, node_child_process_1.execSync)(`cd ${appName} && npm i -D ts-loader typescript file-loader`);
|
|
197
|
+
console.log(chalk_1.default.green(` ✔️ Scripting application ${chalk_1.default.bold(appName)} created!`));
|
|
198
|
+
}
|
|
158
199
|
function createApp(appName) {
|
|
159
200
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
201
|
if (!/^[a-zA-Z]+[a-zA-Z0-9-_]+$/.test(appName)) {
|
|
@@ -167,8 +208,10 @@ function createApp(appName) {
|
|
|
167
208
|
yield createTSConfig(appName);
|
|
168
209
|
yield createReadme(appName);
|
|
169
210
|
yield createEntryFile(appName);
|
|
170
|
-
yield
|
|
171
|
-
|
|
211
|
+
yield copyAssets(appName);
|
|
212
|
+
yield createVSCodeSettings(appName);
|
|
213
|
+
installDeps(appName);
|
|
214
|
+
console.log(` ✔️ All done! Run ${chalk_1.default.bold(chalk_1.default.green('npm run dev'))} to start the dev server.`);
|
|
172
215
|
}
|
|
173
216
|
catch (e) {
|
|
174
217
|
console.log(chalk_1.default.red(`✖️ Create Scripting application failed: ${e.message}`));
|
package/dist/startDevServer.js
CHANGED
|
@@ -22,6 +22,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
25
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
36
|
};
|
|
@@ -29,9 +38,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
38
|
exports.startDevServer = void 0;
|
|
30
39
|
const node_http_1 = __importDefault(require("node:http"));
|
|
31
40
|
const node_path_1 = __importDefault(require("node:path"));
|
|
41
|
+
const promises_1 = require("node:fs/promises");
|
|
32
42
|
const chalk_1 = __importDefault(require("chalk"));
|
|
33
43
|
const express_1 = __importDefault(require("express"));
|
|
34
44
|
const minimist_1 = __importDefault(require("minimist"));
|
|
45
|
+
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
35
46
|
const socket_io_1 = require("socket.io");
|
|
36
47
|
const utils = __importStar(require("./utils"));
|
|
37
48
|
const webpack_1 = __importDefault(require("webpack"));
|
|
@@ -51,7 +62,7 @@ function startDevServer() {
|
|
|
51
62
|
compiler.watch({}, (err, stats) => {
|
|
52
63
|
utils.clearConsole();
|
|
53
64
|
if (err) {
|
|
54
|
-
console.log(chalk_1.default.red('
|
|
65
|
+
console.log(chalk_1.default.red(' ✖️ webpack compile error: \n') + err);
|
|
55
66
|
}
|
|
56
67
|
else {
|
|
57
68
|
console.log(stats === null || stats === void 0 ? void 0 : stats.toString({
|
|
@@ -64,19 +75,24 @@ function startDevServer() {
|
|
|
64
75
|
}
|
|
65
76
|
});
|
|
66
77
|
function onCompileDone() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
if (isStarted) {
|
|
80
|
+
printDevServerAddress();
|
|
81
|
+
console.log(chalk_1.default.gray(` ~ Sent update event to ${connectedSockets.length} client(s)`));
|
|
82
|
+
const appJson = yield (0, promises_1.readFile)(node_path_1.default.resolve(process.cwd(), 'build/app.json'), 'utf-8');
|
|
83
|
+
for (const socket of connectedSockets) {
|
|
84
|
+
socket.emit('update', appJson);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
start();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
77
91
|
}
|
|
78
92
|
function printDevServerAddress() {
|
|
79
93
|
console.log(`Server running at ${chalk_1.default.bold(chalk_1.default.green(`http://${ipAddress}:${port}`))}`);
|
|
94
|
+
console.log(`Use the Scripting app to scan the QR code below:`);
|
|
95
|
+
qrcode_terminal_1.default.generate(`http://${ipAddress}:${port}`, { small: true });
|
|
80
96
|
}
|
|
81
97
|
function start() {
|
|
82
98
|
if (isStarted) {
|
|
@@ -85,23 +101,22 @@ function startDevServer() {
|
|
|
85
101
|
app.all('*', function (req, res, next) {
|
|
86
102
|
res.header('Access-Control-Allow-Origin', '*');
|
|
87
103
|
res.header('Access-Control-Allow-Headers', '*');
|
|
88
|
-
// res.header('Content-Type', 'application/jsoncharset=utf-8')
|
|
89
104
|
res.header('Access-Control-Allow-Methods', 'GET, POST, PATCH, OPTIONS, PUT, DELETE');
|
|
90
105
|
next();
|
|
91
106
|
});
|
|
92
|
-
app.use('/', express_1.default.static(node_path_1.default.resolve(
|
|
107
|
+
app.use('/', express_1.default.static(node_path_1.default.resolve(process.cwd(), 'build')));
|
|
93
108
|
//有新的客户端连接时触发
|
|
94
109
|
io.on('connection', function (socket) {
|
|
95
|
-
console.log(chalk_1.default.green(
|
|
110
|
+
console.log(chalk_1.default.green(` + A client(${socket.id}) connected.`));
|
|
96
111
|
connectedSockets.push(socket);
|
|
97
112
|
socket.on('error', function (err) {
|
|
98
|
-
console.log(chalk_1.default.red('
|
|
113
|
+
console.log(chalk_1.default.red(' ✖️ Server Error: ', err));
|
|
99
114
|
});
|
|
100
115
|
socket.on('disconnect', function () {
|
|
101
116
|
var index = connectedSockets.indexOf(socket);
|
|
102
117
|
if (index > -1) {
|
|
103
118
|
connectedSockets.splice(index, 1);
|
|
104
|
-
console.log(chalk_1.default.gray(
|
|
119
|
+
console.log(chalk_1.default.gray(` - A client(${socket.id}) disconnected.`));
|
|
105
120
|
}
|
|
106
121
|
});
|
|
107
122
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scripting-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "This plugin include all the commands for developing scripting-js apps.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"homepage": "https://github.com/thomfang/scripting-cli#readme",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"chalk": "^4.1.2",
|
|
30
|
+
"cross-zip": "^4.0.1",
|
|
30
31
|
"express": "^4.18.2",
|
|
31
|
-
"file-loader": "^6.2.0",
|
|
32
32
|
"minimist": "^1.2.8",
|
|
33
|
+
"qrcode-terminal": "^0.12.0",
|
|
33
34
|
"socket.io": "^4.7.5",
|
|
34
|
-
"
|
|
35
|
-
"typescript": "^5.1.6",
|
|
36
|
-
"webpack": "^5.88.2",
|
|
37
|
-
"webpack-cli": "^5.1.4"
|
|
35
|
+
"webpack": "^5.88.2"
|
|
38
36
|
},
|
|
39
37
|
"devDependencies": {
|
|
38
|
+
"@types/cross-zip": "^4.0.2",
|
|
40
39
|
"@types/express": "^4.17.21",
|
|
41
|
-
"@types/minimist": "^1.2.5"
|
|
40
|
+
"@types/minimist": "^1.2.5",
|
|
41
|
+
"@types/qrcode-terminal": "^0.12.2"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
declare module '*.avif' {
|
|
3
|
+
const src: string;
|
|
4
|
+
export default src;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare module '*.bmp' {
|
|
8
|
+
const src: string;
|
|
9
|
+
export default src;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module '*.gif' {
|
|
13
|
+
const src: string;
|
|
14
|
+
export default src;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module '*.jpg' {
|
|
18
|
+
const src: string;
|
|
19
|
+
export default src;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare module '*.jpeg' {
|
|
23
|
+
const src: string;
|
|
24
|
+
export default src;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare module '*.png' {
|
|
28
|
+
const src: string;
|
|
29
|
+
export default src;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare module '*.webp' {
|
|
33
|
+
const src: string;
|
|
34
|
+
export default src;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare module '*.svg' {
|
|
38
|
+
const src: string;
|
|
39
|
+
export default src;
|
|
40
|
+
}
|
package/public/logo.svg
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<rect width="512" height="512" fill="#1E1E1E"/>
|
|
3
|
+
<path d="M153.613 333L75 256L153.636 179H184.355L105.718 256L184.355 333H153.613ZM357.34 333H326.645L405.282 256L326.645 179H357.364L436 256L357.34 333ZM305.954 179L230.456 333H204.999L280.497 179H305.954Z" fill="white"/>
|
|
4
|
+
</svg>
|