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/src/build.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
import Webpack from "webpack"
|
|
3
|
-
import webpackConfig from './config/webpack.config'
|
|
4
3
|
import { zip } from 'cross-zip'
|
|
4
|
+
import qrcode from 'qrcode-terminal'
|
|
5
|
+
|
|
5
6
|
import path from 'node:path'
|
|
7
|
+
import http from 'node:http'
|
|
8
|
+
import express from 'express'
|
|
9
|
+
|
|
10
|
+
import getConfig from './config/webpack.config'
|
|
11
|
+
import * as utils from './utils'
|
|
12
|
+
import minimist from 'minimist'
|
|
6
13
|
|
|
7
14
|
export function buildApp() {
|
|
15
|
+
const webpackConfig = getConfig()
|
|
16
|
+
|
|
17
|
+
const appName = Object.keys(webpackConfig.entry as any)[0]
|
|
18
|
+
const appFile = `${appName}.zip`
|
|
19
|
+
|
|
20
|
+
const outputDir = path.resolve(process.cwd(), appName)
|
|
21
|
+
|
|
22
|
+
webpackConfig.output!.path = outputDir
|
|
23
|
+
|
|
8
24
|
const compiler = Webpack(webpackConfig)
|
|
9
25
|
|
|
10
26
|
console.log(
|
|
@@ -32,28 +48,63 @@ export function buildApp() {
|
|
|
32
48
|
}
|
|
33
49
|
})
|
|
34
50
|
|
|
35
|
-
}
|
|
36
51
|
|
|
37
|
-
function createAppFile() {
|
|
38
|
-
const appFile = `${Object.keys(webpackConfig.entry as any)[0]}.zip`
|
|
39
52
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
function createAppFile() {
|
|
54
|
+
console.log(
|
|
55
|
+
` ~ Creating ${appFile}....`
|
|
56
|
+
)
|
|
43
57
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
zip(
|
|
59
|
+
outputDir,
|
|
60
|
+
path.resolve(outputDir, appFile),
|
|
61
|
+
(error) => {
|
|
62
|
+
if (error != null) {
|
|
63
|
+
console.log(
|
|
64
|
+
chalk.red('Error zipping app files: \n') + error
|
|
65
|
+
)
|
|
66
|
+
} else {
|
|
67
|
+
console.log(
|
|
68
|
+
chalk.green(` ✔️ ${appFile} created.`)
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
startServer()
|
|
72
|
+
}
|
|
56
73
|
}
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function startServer() {
|
|
78
|
+
const app = express()
|
|
79
|
+
const server = http.createServer(app)
|
|
80
|
+
|
|
81
|
+
const args = minimist(process.argv.slice(2))
|
|
82
|
+
const ipAddress = utils.getIpAddress()
|
|
83
|
+
const port = args['port'] || 8000
|
|
84
|
+
|
|
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
|
+
|
|
92
|
+
app.use(
|
|
93
|
+
'/',
|
|
94
|
+
express.static(
|
|
95
|
+
outputDir
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
server.listen(port)
|
|
100
|
+
|
|
101
|
+
console.log(`Server running at ${chalk.bold(
|
|
102
|
+
chalk.green(
|
|
103
|
+
`http://${ipAddress}:${port}`
|
|
104
|
+
),
|
|
105
|
+
)}`)
|
|
106
|
+
console.log(`Use the Scripting app to scan the QR code below to install:`)
|
|
107
|
+
qrcode.generate(`http://${ipAddress}:${port}`, { small: true })
|
|
108
|
+
}
|
|
109
|
+
|
|
59
110
|
}
|
|
@@ -8,101 +8,104 @@ import webpack from 'webpack'
|
|
|
8
8
|
|
|
9
9
|
import AppJsonPlugin from './AppJsonPlugin'
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
const srcDir = path.resolve(baseDir, 'src')
|
|
13
|
-
const buildDir = path.resolve(baseDir, 'build')
|
|
11
|
+
export default function getConfig() {
|
|
14
12
|
|
|
15
|
-
const
|
|
13
|
+
const baseDir = process.cwd()
|
|
14
|
+
const srcDir = path.resolve(baseDir, 'src')
|
|
15
|
+
const outputDir = path.resolve(baseDir, 'build')
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
const pkgPath = path.resolve(baseDir, 'package.json')
|
|
18
|
+
|
|
19
|
+
if (!fs.existsSync(pkgPath)) {
|
|
20
|
+
console.log(
|
|
21
|
+
chalk.red('✖️ package.json not found.')
|
|
22
|
+
)
|
|
23
|
+
process.exit(404)
|
|
24
|
+
}
|
|
23
25
|
|
|
24
|
-
const pkg = JSON.parse(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const pkg = JSON.parse(
|
|
27
|
+
fs.readFileSync(
|
|
28
|
+
pkgPath,
|
|
29
|
+
'utf8'
|
|
30
|
+
)
|
|
28
31
|
)
|
|
29
|
-
)
|
|
30
32
|
|
|
31
|
-
const entry = {
|
|
32
|
-
|
|
33
|
-
}
|
|
33
|
+
const entry = {
|
|
34
|
+
[pkg.name]: path.join(srcDir, 'index.tsx'),
|
|
35
|
+
}
|
|
34
36
|
|
|
35
|
-
const config: webpack.Configuration = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
const config: webpack.Configuration = {
|
|
38
|
+
mode: 'production',
|
|
39
|
+
entry,
|
|
40
|
+
optimization: {
|
|
41
|
+
moduleIds: 'deterministic',
|
|
42
|
+
chunkIds: 'named',
|
|
43
|
+
minimizer: [
|
|
44
|
+
new TerserPlugin({
|
|
45
|
+
extractComments: false,
|
|
46
|
+
terserOptions: {
|
|
47
|
+
format: {
|
|
48
|
+
comments: false,
|
|
49
|
+
},
|
|
47
50
|
},
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
module: {
|
|
55
|
+
rules: [
|
|
56
|
+
{
|
|
57
|
+
test: /\.tsx?$/,
|
|
58
|
+
use: 'ts-loader',
|
|
59
|
+
exclude: /node_modules/,
|
|
48
60
|
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// return url.replace(/src\/([^/]+)\//, '')
|
|
70
|
-
},
|
|
71
|
-
publicPath: (url: string, resourcePath: string, context: any) => {
|
|
72
|
-
// console.log([url, resourcePath])
|
|
73
|
-
// return url.replace(/.*src\/app\/(\w+\/)?/, '')
|
|
74
|
-
// if (url.startsWith('src/app/')) {
|
|
75
|
-
// return url.replace('src/app/', '')
|
|
76
|
-
// }
|
|
77
|
-
return url.replace('src/', '')
|
|
61
|
+
{
|
|
62
|
+
test: /\.(png|jpe?g|gif|svg)$/i,
|
|
63
|
+
loader: 'file-loader',
|
|
64
|
+
options: {
|
|
65
|
+
name: '[path][contenthash:8].[ext]',
|
|
66
|
+
outputPath: (url: string, resourcePath: string, context: any) => {
|
|
67
|
+
// if (url.startsWith('src/app/')) {
|
|
68
|
+
// return url.replace('src/app/', '')
|
|
69
|
+
// }
|
|
70
|
+
return url.replace('src/', '')
|
|
71
|
+
// return url.replace(/src\/([^/]+)\//, '')
|
|
72
|
+
},
|
|
73
|
+
publicPath: (url: string, resourcePath: string, context: any) => {
|
|
74
|
+
// console.log([url, resourcePath])
|
|
75
|
+
// return url.replace(/.*src\/app\/(\w+\/)?/, '')
|
|
76
|
+
// if (url.startsWith('src/app/')) {
|
|
77
|
+
// return url.replace('src/app/', '')
|
|
78
|
+
// }
|
|
79
|
+
return url.replace('src/', '')
|
|
80
|
+
},
|
|
78
81
|
},
|
|
79
82
|
},
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
resolve: {
|
|
86
|
+
extensions: ['.tsx', '.ts', '.js'],
|
|
87
|
+
modules: [
|
|
88
|
+
'node_modules',
|
|
89
|
+
srcDir,
|
|
90
|
+
],
|
|
91
|
+
alias: {
|
|
92
|
+
'@': srcDir,
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
output: {
|
|
96
|
+
filename: '[name]/[contenthash:8].js',
|
|
97
|
+
// filename: '[contenthash:8].js',
|
|
98
|
+
path: outputDir,
|
|
99
|
+
clean: true,
|
|
100
|
+
},
|
|
101
|
+
plugins: [
|
|
102
|
+
new AppJsonPlugin(),
|
|
88
103
|
],
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
devtool: false,
|
|
105
|
+
externals: {
|
|
106
|
+
'scripting': 'Scripting',
|
|
91
107
|
}
|
|
92
|
-
},
|
|
93
|
-
output: {
|
|
94
|
-
filename: '[name]/[contenthash:8].js',
|
|
95
|
-
// filename: '[contenthash:8].js',
|
|
96
|
-
path: buildDir,
|
|
97
|
-
clean: true,
|
|
98
|
-
},
|
|
99
|
-
plugins: [
|
|
100
|
-
new AppJsonPlugin(),
|
|
101
|
-
],
|
|
102
|
-
devtool: false,
|
|
103
|
-
externals: {
|
|
104
|
-
'scripting': 'Scripting',
|
|
105
108
|
}
|
|
106
|
-
}
|
|
107
109
|
|
|
108
|
-
|
|
110
|
+
return config
|
|
111
|
+
}
|
package/src/createApp.ts
CHANGED
|
@@ -26,68 +26,68 @@ async function createEntryFile(appName: string) {
|
|
|
26
26
|
|
|
27
27
|
await writeFile(
|
|
28
28
|
filePath,
|
|
29
|
-
`
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
backgroundColor={backgroundColor}
|
|
60
|
-
/>
|
|
29
|
+
`import { runApp, createElement, RouterProvider, Router, Column, CupertinoNavigationBar, CupertinoPageScaffold, Svg, Text, Container, useCupertinoColors } from 'scripting'
|
|
30
|
+
import Logo from './svgs/logo.svg'
|
|
31
|
+
|
|
32
|
+
function ScriptingLogo() {
|
|
33
|
+
return (
|
|
34
|
+
<Container
|
|
35
|
+
clipBehavior={'hardEdge'}
|
|
36
|
+
width={80}
|
|
37
|
+
height={80}
|
|
38
|
+
margin={{
|
|
39
|
+
vertical: 100,
|
|
40
|
+
}}
|
|
41
|
+
borderRadius={16}
|
|
42
|
+
>
|
|
43
|
+
<Svg src={Logo} />
|
|
44
|
+
</Container>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function HomePage() {
|
|
49
|
+
const cupertinoColors = useCupertinoColors()
|
|
50
|
+
const backgroundColor = cupertinoColors.systemBackground
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<CupertinoPageScaffold
|
|
54
|
+
navigationBar={
|
|
55
|
+
<CupertinoNavigationBar
|
|
56
|
+
middle={
|
|
57
|
+
<Text>${appName}</Text>
|
|
61
58
|
}
|
|
59
|
+
backgroundColor={backgroundColor}
|
|
60
|
+
/>
|
|
61
|
+
}
|
|
62
|
+
>
|
|
63
|
+
<Container
|
|
64
|
+
width={'infinity'}
|
|
65
|
+
height={'infinity'}
|
|
66
|
+
color={backgroundColor}
|
|
67
|
+
>
|
|
68
|
+
<Column
|
|
69
|
+
crossAxisAlignment={'center'}
|
|
62
70
|
>
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
])
|
|
85
|
-
|
|
86
|
-
runApp(
|
|
87
|
-
<RouterProvider router={router} />
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
`,
|
|
71
|
+
<ScriptingLogo />
|
|
72
|
+
<Text
|
|
73
|
+
color={cupertinoColors.label}
|
|
74
|
+
>Welcome to Scripting!</Text>
|
|
75
|
+
</Column>
|
|
76
|
+
</Container>
|
|
77
|
+
</CupertinoPageScaffold>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const router = new Router([
|
|
82
|
+
{
|
|
83
|
+
path: '/',
|
|
84
|
+
element: <HomePage />,
|
|
85
|
+
},
|
|
86
|
+
])
|
|
87
|
+
|
|
88
|
+
runApp(
|
|
89
|
+
<RouterProvider router={router} />
|
|
90
|
+
)`,
|
|
91
91
|
'utf-8'
|
|
92
92
|
)
|
|
93
93
|
|
|
@@ -222,23 +222,26 @@ async function copyAssets(appName: string) {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
async function createVSCodeSettings(appName: string) {
|
|
225
|
-
const destDir = path.join(
|
|
225
|
+
const destDir = path.join(getAppDir(appName), '.vscode')
|
|
226
226
|
|
|
227
227
|
if (!fs.existsSync(destDir)) {
|
|
228
|
-
await mkdir(destDir)
|
|
228
|
+
await mkdir(destDir, { recursive: true })
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
await copyFile(
|
|
232
232
|
path.join(__dirname, '../.vscode/settings.json'),
|
|
233
|
-
path.join(
|
|
233
|
+
path.join(destDir, 'settings.json')
|
|
234
234
|
)
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
function installDeps(appName: string) {
|
|
238
|
+
console.log(
|
|
239
|
+
` > cd ${appName} && npm i -D ts-loader typescript file-loader`
|
|
240
|
+
)
|
|
238
241
|
execSync(`cd ${appName} && npm i -D ts-loader typescript file-loader`)
|
|
239
242
|
|
|
240
243
|
console.log(
|
|
241
|
-
chalk.green(` ✔️ Scripting application ${chalk.bold(appName)}
|
|
244
|
+
chalk.green(` ✔️ Scripting application ${chalk.bold(appName)} is ready!`)
|
|
242
245
|
)
|
|
243
246
|
}
|
|
244
247
|
|
|
@@ -250,6 +253,10 @@ export async function createApp(appName: string) {
|
|
|
250
253
|
return
|
|
251
254
|
}
|
|
252
255
|
|
|
256
|
+
console.log(
|
|
257
|
+
`Start creating ${appName} ...`
|
|
258
|
+
)
|
|
259
|
+
|
|
253
260
|
try {
|
|
254
261
|
await createAppDir(appName)
|
|
255
262
|
await createPackageJson(appName)
|
|
@@ -262,8 +269,8 @@ export async function createApp(appName: string) {
|
|
|
262
269
|
installDeps(appName)
|
|
263
270
|
|
|
264
271
|
console.log(
|
|
265
|
-
`
|
|
266
|
-
chalk.green(
|
|
272
|
+
`All done! Run ${chalk.bold(
|
|
273
|
+
chalk.green(`cd ${appName} && npm run dev`)
|
|
267
274
|
)} to start the dev server.`
|
|
268
275
|
)
|
|
269
276
|
|
package/src/index.ts
CHANGED
package/src/startDevServer.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { Server, Socket } from 'socket.io'
|
|
|
11
11
|
import * as utils from './utils'
|
|
12
12
|
|
|
13
13
|
import Webpack from "webpack"
|
|
14
|
-
import
|
|
14
|
+
import getConfig from './config/webpack.config'
|
|
15
15
|
|
|
16
16
|
export function startDevServer() {
|
|
17
17
|
const args = minimist(process.argv.slice(2))
|
|
@@ -23,9 +23,12 @@ export function startDevServer() {
|
|
|
23
23
|
const server = http.createServer(app)
|
|
24
24
|
const io = new Server(server)
|
|
25
25
|
|
|
26
|
+
|
|
26
27
|
let isStarted = false
|
|
27
28
|
let connectedSockets: Socket[] = []
|
|
28
29
|
|
|
30
|
+
const webpackConfig = getConfig()
|
|
31
|
+
|
|
29
32
|
webpackConfig.mode = 'development'
|
|
30
33
|
|
|
31
34
|
const compiler = Webpack(webpackConfig)
|