scripting-cli 1.0.4 → 1.0.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/dist/build.js +65 -14
- package/dist/config/webpack.config.js +82 -79
- package/dist/createApp.js +66 -64
- package/dist/index.js +0 -1
- package/dist/startDevServer.js +3 -2
- package/package.json +1 -1
- package/public/scripting.d.ts +791 -711
- package/src/build.ts +72 -21
- package/src/config/webpack.config.ts +87 -84
- package/src/createApp.ts +73 -66
- package/src/index.ts +0 -1
- package/src/startDevServer.ts +4 -1
package/dist/build.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -6,11 +29,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
29
|
exports.buildApp = void 0;
|
|
7
30
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
31
|
const webpack_1 = __importDefault(require("webpack"));
|
|
9
|
-
const webpack_config_1 = __importDefault(require("./config/webpack.config"));
|
|
10
32
|
const cross_zip_1 = require("cross-zip");
|
|
33
|
+
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
11
34
|
const node_path_1 = __importDefault(require("node:path"));
|
|
35
|
+
const node_http_1 = __importDefault(require("node:http"));
|
|
36
|
+
const express_1 = __importDefault(require("express"));
|
|
37
|
+
const webpack_config_1 = __importDefault(require("./config/webpack.config"));
|
|
38
|
+
const utils = __importStar(require("./utils"));
|
|
39
|
+
const minimist_1 = __importDefault(require("minimist"));
|
|
12
40
|
function buildApp() {
|
|
13
|
-
const
|
|
41
|
+
const webpackConfig = (0, webpack_config_1.default)();
|
|
42
|
+
const appName = Object.keys(webpackConfig.entry)[0];
|
|
43
|
+
const appFile = `${appName}.zip`;
|
|
44
|
+
const outputDir = node_path_1.default.resolve(process.cwd(), appName);
|
|
45
|
+
webpackConfig.output.path = outputDir;
|
|
46
|
+
const compiler = (0, webpack_1.default)(webpackConfig);
|
|
14
47
|
console.log('Start running build...\n'
|
|
15
48
|
// +
|
|
16
49
|
// chalk.green(
|
|
@@ -31,17 +64,35 @@ function buildApp() {
|
|
|
31
64
|
createAppFile();
|
|
32
65
|
}
|
|
33
66
|
});
|
|
67
|
+
function createAppFile() {
|
|
68
|
+
console.log(` ~ Creating ${appFile}....`);
|
|
69
|
+
(0, cross_zip_1.zip)(outputDir, node_path_1.default.resolve(outputDir, appFile), (error) => {
|
|
70
|
+
if (error != null) {
|
|
71
|
+
console.log(chalk_1.default.red('Error zipping app files: \n') + error);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.log(chalk_1.default.green(` ✔️ ${appFile} created.`));
|
|
75
|
+
startServer();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function startServer() {
|
|
80
|
+
const app = (0, express_1.default)();
|
|
81
|
+
const server = node_http_1.default.createServer(app);
|
|
82
|
+
const args = (0, minimist_1.default)(process.argv.slice(2));
|
|
83
|
+
const ipAddress = utils.getIpAddress();
|
|
84
|
+
const port = args['port'] || 8000;
|
|
85
|
+
app.all('*', function (req, res, next) {
|
|
86
|
+
res.header('Access-Control-Allow-Origin', '*');
|
|
87
|
+
res.header('Access-Control-Allow-Headers', '*');
|
|
88
|
+
res.header('Access-Control-Allow-Methods', 'GET, POST, PATCH, OPTIONS, PUT, DELETE');
|
|
89
|
+
next();
|
|
90
|
+
});
|
|
91
|
+
app.use('/', express_1.default.static(outputDir));
|
|
92
|
+
server.listen(port);
|
|
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 to install:`);
|
|
95
|
+
qrcode_terminal_1.default.generate(`http://${ipAddress}:${port}`, { small: true });
|
|
96
|
+
}
|
|
34
97
|
}
|
|
35
98
|
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
|
-
}
|
|
@@ -8,88 +8,91 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
|
|
10
10
|
const AppJsonPlugin_1 = __importDefault(require("./AppJsonPlugin"));
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
function getConfig() {
|
|
12
|
+
const baseDir = process.cwd();
|
|
13
|
+
const srcDir = node_path_1.default.resolve(baseDir, 'src');
|
|
14
|
+
const outputDir = node_path_1.default.resolve(baseDir, 'build');
|
|
15
|
+
const pkgPath = node_path_1.default.resolve(baseDir, 'package.json');
|
|
16
|
+
if (!node_fs_1.default.existsSync(pkgPath)) {
|
|
17
|
+
console.log(chalk_1.default.red('✖️ package.json not found.'));
|
|
18
|
+
process.exit(404);
|
|
19
|
+
}
|
|
20
|
+
const pkg = JSON.parse(node_fs_1.default.readFileSync(pkgPath, 'utf8'));
|
|
21
|
+
const entry = {
|
|
22
|
+
[pkg.name]: node_path_1.default.join(srcDir, 'index.tsx'),
|
|
23
|
+
};
|
|
24
|
+
const config = {
|
|
25
|
+
mode: 'production',
|
|
26
|
+
entry,
|
|
27
|
+
optimization: {
|
|
28
|
+
moduleIds: 'deterministic',
|
|
29
|
+
chunkIds: 'named',
|
|
30
|
+
minimizer: [
|
|
31
|
+
new terser_webpack_plugin_1.default({
|
|
32
|
+
extractComments: false,
|
|
33
|
+
terserOptions: {
|
|
34
|
+
format: {
|
|
35
|
+
comments: false,
|
|
36
|
+
},
|
|
35
37
|
},
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
module: {
|
|
42
|
+
rules: [
|
|
43
|
+
{
|
|
44
|
+
test: /\.tsx?$/,
|
|
45
|
+
use: 'ts-loader',
|
|
46
|
+
exclude: /node_modules/,
|
|
36
47
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// return url.replace(/src\/([^/]+)\//, '')
|
|
58
|
-
},
|
|
59
|
-
publicPath: (url, resourcePath, context) => {
|
|
60
|
-
// console.log([url, resourcePath])
|
|
61
|
-
// return url.replace(/.*src\/app\/(\w+\/)?/, '')
|
|
62
|
-
// if (url.startsWith('src/app/')) {
|
|
63
|
-
// return url.replace('src/app/', '')
|
|
64
|
-
// }
|
|
65
|
-
return url.replace('src/', '');
|
|
48
|
+
{
|
|
49
|
+
test: /\.(png|jpe?g|gif|svg)$/i,
|
|
50
|
+
loader: 'file-loader',
|
|
51
|
+
options: {
|
|
52
|
+
name: '[path][contenthash:8].[ext]',
|
|
53
|
+
outputPath: (url, resourcePath, context) => {
|
|
54
|
+
// if (url.startsWith('src/app/')) {
|
|
55
|
+
// return url.replace('src/app/', '')
|
|
56
|
+
// }
|
|
57
|
+
return url.replace('src/', '');
|
|
58
|
+
// return url.replace(/src\/([^/]+)\//, '')
|
|
59
|
+
},
|
|
60
|
+
publicPath: (url, resourcePath, context) => {
|
|
61
|
+
// console.log([url, resourcePath])
|
|
62
|
+
// return url.replace(/.*src\/app\/(\w+\/)?/, '')
|
|
63
|
+
// if (url.startsWith('src/app/')) {
|
|
64
|
+
// return url.replace('src/app/', '')
|
|
65
|
+
// }
|
|
66
|
+
return url.replace('src/', '');
|
|
67
|
+
},
|
|
66
68
|
},
|
|
67
69
|
},
|
|
68
|
-
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
resolve: {
|
|
73
|
+
extensions: ['.tsx', '.ts', '.js'],
|
|
74
|
+
modules: [
|
|
75
|
+
'node_modules',
|
|
76
|
+
srcDir,
|
|
77
|
+
],
|
|
78
|
+
alias: {
|
|
79
|
+
'@': srcDir,
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
output: {
|
|
83
|
+
filename: '[name]/[contenthash:8].js',
|
|
84
|
+
// filename: '[contenthash:8].js',
|
|
85
|
+
path: outputDir,
|
|
86
|
+
clean: true,
|
|
87
|
+
},
|
|
88
|
+
plugins: [
|
|
89
|
+
new AppJsonPlugin_1.default(),
|
|
69
90
|
],
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
modules: [
|
|
74
|
-
'node_modules',
|
|
75
|
-
srcDir,
|
|
76
|
-
],
|
|
77
|
-
alias: {
|
|
78
|
-
'@': srcDir,
|
|
91
|
+
devtool: false,
|
|
92
|
+
externals: {
|
|
93
|
+
'scripting': 'Scripting',
|
|
79
94
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
path: buildDir,
|
|
85
|
-
clean: true,
|
|
86
|
-
},
|
|
87
|
-
plugins: [
|
|
88
|
-
new AppJsonPlugin_1.default(),
|
|
89
|
-
],
|
|
90
|
-
devtool: false,
|
|
91
|
-
externals: {
|
|
92
|
-
'scripting': 'Scripting',
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
exports.default = config;
|
|
95
|
+
};
|
|
96
|
+
return config;
|
|
97
|
+
}
|
|
98
|
+
exports.default = getConfig;
|
package/dist/createApp.js
CHANGED
|
@@ -35,68 +35,68 @@ function createEntryFile(appName) {
|
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
36
|
console.log(` > Creating ${appName}/src/index.tsx ...`);
|
|
37
37
|
const filePath = node_path_1.default.join(getAppDir(appName), '/src/index.tsx');
|
|
38
|
-
yield (0, promises_1.writeFile)(filePath, `
|
|
38
|
+
yield (0, promises_1.writeFile)(filePath, `import { runApp, createElement, RouterProvider, Router, Column, CupertinoNavigationBar, CupertinoPageScaffold, Svg, Text, Container, useCupertinoColors } from 'scripting'
|
|
39
|
+
import Logo from './svgs/logo.svg'
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
<Text>${appName}</Text>
|
|
67
|
-
}
|
|
68
|
-
backgroundColor={backgroundColor}
|
|
69
|
-
/>
|
|
41
|
+
function ScriptingLogo() {
|
|
42
|
+
return (
|
|
43
|
+
<Container
|
|
44
|
+
clipBehavior={'hardEdge'}
|
|
45
|
+
width={80}
|
|
46
|
+
height={80}
|
|
47
|
+
margin={{
|
|
48
|
+
vertical: 100,
|
|
49
|
+
}}
|
|
50
|
+
borderRadius={16}
|
|
51
|
+
>
|
|
52
|
+
<Svg src={Logo} />
|
|
53
|
+
</Container>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function HomePage() {
|
|
58
|
+
const cupertinoColors = useCupertinoColors()
|
|
59
|
+
const backgroundColor = cupertinoColors.systemBackground
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<CupertinoPageScaffold
|
|
63
|
+
navigationBar={
|
|
64
|
+
<CupertinoNavigationBar
|
|
65
|
+
middle={
|
|
66
|
+
<Text>${appName}</Text>
|
|
70
67
|
}
|
|
68
|
+
backgroundColor={backgroundColor}
|
|
69
|
+
/>
|
|
70
|
+
}
|
|
71
|
+
>
|
|
72
|
+
<Container
|
|
73
|
+
width={'infinity'}
|
|
74
|
+
height={'infinity'}
|
|
75
|
+
color={backgroundColor}
|
|
76
|
+
>
|
|
77
|
+
<Column
|
|
78
|
+
crossAxisAlignment={'center'}
|
|
71
79
|
>
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
])
|
|
94
|
-
|
|
95
|
-
runApp(
|
|
96
|
-
<RouterProvider router={router} />
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
`, 'utf-8');
|
|
80
|
+
<ScriptingLogo />
|
|
81
|
+
<Text
|
|
82
|
+
color={cupertinoColors.label}
|
|
83
|
+
>Welcome to Scripting!</Text>
|
|
84
|
+
</Column>
|
|
85
|
+
</Container>
|
|
86
|
+
</CupertinoPageScaffold>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const router = new Router([
|
|
91
|
+
{
|
|
92
|
+
path: '/',
|
|
93
|
+
element: <HomePage />,
|
|
94
|
+
},
|
|
95
|
+
])
|
|
96
|
+
|
|
97
|
+
runApp(
|
|
98
|
+
<RouterProvider router={router} />
|
|
99
|
+
)`, 'utf-8');
|
|
100
100
|
console.log(chalk_1.default.green(` ✔️ Created ${appName}/src/index.tsx`));
|
|
101
101
|
});
|
|
102
102
|
}
|
|
@@ -185,16 +185,17 @@ function copyAssets(appName) {
|
|
|
185
185
|
}
|
|
186
186
|
function createVSCodeSettings(appName) {
|
|
187
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const destDir = node_path_1.default.join(
|
|
188
|
+
const destDir = node_path_1.default.join(getAppDir(appName), '.vscode');
|
|
189
189
|
if (!node_fs_1.default.existsSync(destDir)) {
|
|
190
|
-
yield (0, promises_1.mkdir)(destDir);
|
|
190
|
+
yield (0, promises_1.mkdir)(destDir, { recursive: true });
|
|
191
191
|
}
|
|
192
|
-
yield (0, promises_1.copyFile)(node_path_1.default.join(__dirname, '../.vscode/settings.json'), node_path_1.default.join(
|
|
192
|
+
yield (0, promises_1.copyFile)(node_path_1.default.join(__dirname, '../.vscode/settings.json'), node_path_1.default.join(destDir, 'settings.json'));
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
function installDeps(appName) {
|
|
196
|
+
console.log(` > cd ${appName} && npm i -D ts-loader typescript file-loader`);
|
|
196
197
|
(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)}
|
|
198
|
+
console.log(chalk_1.default.green(` ✔️ Scripting application ${chalk_1.default.bold(appName)} is ready!`));
|
|
198
199
|
}
|
|
199
200
|
function createApp(appName) {
|
|
200
201
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -202,6 +203,7 @@ function createApp(appName) {
|
|
|
202
203
|
console.log(chalk_1.default.red(`✖️ Invalid Scripting application name "${appName}"`));
|
|
203
204
|
return;
|
|
204
205
|
}
|
|
206
|
+
console.log(`Start creating ${appName} ...`);
|
|
205
207
|
try {
|
|
206
208
|
yield createAppDir(appName);
|
|
207
209
|
yield createPackageJson(appName);
|
|
@@ -211,7 +213,7 @@ function createApp(appName) {
|
|
|
211
213
|
yield copyAssets(appName);
|
|
212
214
|
yield createVSCodeSettings(appName);
|
|
213
215
|
installDeps(appName);
|
|
214
|
-
console.log(`
|
|
216
|
+
console.log(`All done! Run ${chalk_1.default.bold(chalk_1.default.green(`cd ${appName} && npm run dev`))} to start the dev server.`);
|
|
215
217
|
}
|
|
216
218
|
catch (e) {
|
|
217
219
|
console.log(chalk_1.default.red(`✖️ Create Scripting application failed: ${e.message}`));
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,6 @@ const build_1 = require("./build");
|
|
|
10
10
|
const createApp_1 = require("./createApp");
|
|
11
11
|
function run() {
|
|
12
12
|
const args = (0, minimist_1.default)(process.argv.slice(2));
|
|
13
|
-
// console.log(args)
|
|
14
13
|
if (args['create'] != null) {
|
|
15
14
|
(0, createApp_1.createApp)(args['create']);
|
|
16
15
|
}
|
package/dist/startDevServer.js
CHANGED
|
@@ -56,8 +56,9 @@ function startDevServer() {
|
|
|
56
56
|
const io = new socket_io_1.Server(server);
|
|
57
57
|
let isStarted = false;
|
|
58
58
|
let connectedSockets = [];
|
|
59
|
-
webpack_config_1.default
|
|
60
|
-
|
|
59
|
+
const webpackConfig = (0, webpack_config_1.default)();
|
|
60
|
+
webpackConfig.mode = 'development';
|
|
61
|
+
const compiler = (0, webpack_1.default)(webpackConfig);
|
|
61
62
|
console.log('Start running webpack compiler in watch mode...');
|
|
62
63
|
compiler.watch({}, (err, stats) => {
|
|
63
64
|
utils.clearConsole();
|