scripting-cli 1.0.4 → 1.0.6
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/AppJsonPlugin.js +9 -9
- package/dist/config/webpack.config.js +87 -79
- package/dist/createScript.js +209 -0
- package/dist/index.js +6 -7
- package/dist/startDevServer.js +5 -4
- package/package.json +1 -1
- package/public/global.d.ts +256 -0
- package/public/scripting.d.ts +4347 -853
- package/src/build.ts +72 -21
- package/src/config/AppJsonPlugin.ts +12 -10
- package/src/config/webpack.config.ts +91 -84
- package/src/createScript.ts +256 -0
- package/src/index.ts +6 -6
- package/src/startDevServer.ts +21 -23
- package/dist/createApp.js +0 -221
- package/src/createApp.ts +0 -275
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
|
}
|
|
@@ -31,7 +31,7 @@ export default class AppJsonPlugin implements WebpackPluginInstance {
|
|
|
31
31
|
},
|
|
32
32
|
(assets) => {
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const scriptJson: {
|
|
35
35
|
name: string
|
|
36
36
|
index: string
|
|
37
37
|
hash: string
|
|
@@ -43,19 +43,21 @@ export default class AppJsonPlugin implements WebpackPluginInstance {
|
|
|
43
43
|
assets: Object.keys(assets),
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const indexJs =
|
|
46
|
+
const indexJs = scriptJson.assets.find(
|
|
47
|
+
filePath => filePath.match(/\.js$/i) != null
|
|
48
|
+
)
|
|
47
49
|
|
|
48
50
|
if (indexJs != null) {
|
|
49
51
|
const [appName, ...others] = indexJs.split('/')
|
|
50
52
|
const filePath = others[others.length - 1]
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
scriptJson.name = appName
|
|
54
|
+
scriptJson.index = filePath
|
|
55
|
+
scriptJson.hash = filePath.replace('.js', '')
|
|
54
56
|
|
|
55
57
|
const indexJsSource = assets[indexJs]
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
...
|
|
59
|
+
scriptJson.assets = [
|
|
60
|
+
...scriptJson.assets.filter(e => e !== indexJs),
|
|
59
61
|
filePath,
|
|
60
62
|
]
|
|
61
63
|
|
|
@@ -65,8 +67,8 @@ export default class AppJsonPlugin implements WebpackPluginInstance {
|
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
compilation.emitAsset(
|
|
68
|
-
'
|
|
69
|
-
new RawSource(JSON.stringify(
|
|
70
|
+
'script.json',
|
|
71
|
+
new RawSource(JSON.stringify(scriptJson, null, 2))
|
|
70
72
|
)
|
|
71
73
|
|
|
72
74
|
// const appMap: {
|
|
@@ -107,7 +109,7 @@ export default class AppJsonPlugin implements WebpackPluginInstance {
|
|
|
107
109
|
|
|
108
110
|
// Object.entries(appMap).forEach(([appName, content]) => {
|
|
109
111
|
// compilation.emitAsset(
|
|
110
|
-
// appName + '/
|
|
112
|
+
// appName + '/script.json',
|
|
111
113
|
// new RawSource(JSON.stringify(content, null, 2))
|
|
112
114
|
// )
|
|
113
115
|
// })
|
|
@@ -8,101 +8,108 @@ 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(),
|
|
103
|
+
new webpack.BannerPlugin({
|
|
104
|
+
banner: 'const Scripting = require("scripting");',
|
|
105
|
+
raw: true
|
|
106
|
+
}),
|
|
88
107
|
],
|
|
89
|
-
|
|
90
|
-
|
|
108
|
+
devtool: false,
|
|
109
|
+
externals: {
|
|
110
|
+
'scripting': 'Scripting',
|
|
91
111
|
}
|
|
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
112
|
}
|
|
106
|
-
}
|
|
107
113
|
|
|
108
|
-
|
|
114
|
+
return config
|
|
115
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { execSync } from 'node:child_process'
|
|
4
|
+
import fs from 'node:fs'
|
|
5
|
+
import { mkdir, writeFile, copyFile } from 'node:fs/promises'
|
|
6
|
+
|
|
7
|
+
function getScriptDir(scriptName: string) {
|
|
8
|
+
return path.join(process.cwd(), scriptName)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function createScriptDir(scriptName: string) {
|
|
12
|
+
const appDir = getScriptDir(scriptName)
|
|
13
|
+
|
|
14
|
+
if (fs.existsSync(appDir)) {
|
|
15
|
+
throw new Error(`Directory "./${scriptName}" already exists.`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// const dir = path.resolve(appDir, 'src/svgs')
|
|
19
|
+
const srcDir = path.resolve(appDir, 'src')
|
|
20
|
+
const typesDir = path.resolve(appDir, 'types')
|
|
21
|
+
await Promise.all([
|
|
22
|
+
mkdir(srcDir, { recursive: true }),
|
|
23
|
+
mkdir(typesDir, { recursive: true })
|
|
24
|
+
])
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function createEntryFile(scriptName: string) {
|
|
28
|
+
console.log(` > Creating ${scriptName}/src/index.tsx ...`)
|
|
29
|
+
|
|
30
|
+
const filePath = path.join(getScriptDir(scriptName), '/src/index.tsx')
|
|
31
|
+
|
|
32
|
+
await writeFile(
|
|
33
|
+
filePath,
|
|
34
|
+
`import { Column, CupertinoNavigationBar, CupertinoPageScaffold, Text, Container, useCupertinoColors, navigator, GestureDetector, Script, Center, CupertinoButton, } from 'scripting'
|
|
35
|
+
|
|
36
|
+
function App() {
|
|
37
|
+
const cupertinoColors = useCupertinoColors()
|
|
38
|
+
const backgroundColor = cupertinoColors.systemBackground
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<CupertinoPageScaffold
|
|
42
|
+
navigationBar={
|
|
43
|
+
<CupertinoNavigationBar
|
|
44
|
+
middle={
|
|
45
|
+
<Text>My Script</Text>
|
|
46
|
+
}
|
|
47
|
+
backgroundColor={backgroundColor}
|
|
48
|
+
/>
|
|
49
|
+
}
|
|
50
|
+
>
|
|
51
|
+
<Center>
|
|
52
|
+
<Text
|
|
53
|
+
color={cupertinoColors.label}
|
|
54
|
+
>Welcome to Scripting!</Text>
|
|
55
|
+
</Center>
|
|
56
|
+
</CupertinoPageScaffold>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function run() {
|
|
61
|
+
const result = await navigator.push({
|
|
62
|
+
element: <App />
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
Script.exit(result)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
run()
|
|
69
|
+
`,
|
|
70
|
+
'utf-8'
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
console.log(
|
|
74
|
+
chalk.green(` ✔️ Created ${scriptName}/src/index.tsx`)
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function createPackageJson(scriptName: string) {
|
|
79
|
+
console.log(` > Creating ${scriptName}/package.json ...`)
|
|
80
|
+
|
|
81
|
+
const filePath = path.join(getScriptDir(scriptName), 'package.json')
|
|
82
|
+
|
|
83
|
+
await writeFile(
|
|
84
|
+
filePath,
|
|
85
|
+
`{
|
|
86
|
+
"name": "${scriptName}",
|
|
87
|
+
"version": "0.0.1",
|
|
88
|
+
"private": true,
|
|
89
|
+
"scripts": {
|
|
90
|
+
"dev": "npx scripting-cli dev",
|
|
91
|
+
"build": "npx scripting-cli build"
|
|
92
|
+
}
|
|
93
|
+
}`,
|
|
94
|
+
'utf-8'
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
console.log(
|
|
98
|
+
chalk.green(` ✔️ Created ${scriptName}/package.json`)
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function createReadme(scriptName: string) {
|
|
103
|
+
|
|
104
|
+
console.log(` > Creating ${scriptName}/README.md ...`)
|
|
105
|
+
|
|
106
|
+
const filePath = path.join(getScriptDir(scriptName), 'README.md')
|
|
107
|
+
|
|
108
|
+
await writeFile(
|
|
109
|
+
filePath,
|
|
110
|
+
`# ${scriptName} - A Scripting script
|
|
111
|
+
|
|
112
|
+
## Start dev server
|
|
113
|
+
|
|
114
|
+
\`npm run dev\`
|
|
115
|
+
|
|
116
|
+
## Build App
|
|
117
|
+
|
|
118
|
+
\`npm run build\`
|
|
119
|
+
`,
|
|
120
|
+
'utf-8'
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
console.log(
|
|
124
|
+
chalk.green(` ✔️ Created ${scriptName}/README.md`)
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function createTSConfig(scriptName: string) {
|
|
129
|
+
|
|
130
|
+
console.log(` > Creating ${scriptName}/tsconfig.json ...`)
|
|
131
|
+
|
|
132
|
+
const filePath = path.join(getScriptDir(scriptName), 'tsconfig.json')
|
|
133
|
+
|
|
134
|
+
await writeFile(
|
|
135
|
+
filePath,
|
|
136
|
+
`{
|
|
137
|
+
"compilerOptions": {
|
|
138
|
+
"target": "ESNext",
|
|
139
|
+
"lib": [
|
|
140
|
+
"esnext"
|
|
141
|
+
],
|
|
142
|
+
"allowJs": true,
|
|
143
|
+
"strict": true,
|
|
144
|
+
"esModuleInterop": true,
|
|
145
|
+
"allowSyntheticDefaultImports": true,
|
|
146
|
+
"forceConsistentCasingInFileNames": true,
|
|
147
|
+
"noFallthroughCasesInSwitch": true,
|
|
148
|
+
"module": "CommonJS",
|
|
149
|
+
"skipLibCheck": true,
|
|
150
|
+
"jsx": "react",
|
|
151
|
+
"jsxFactory": "createElement",
|
|
152
|
+
"baseUrl": "src",
|
|
153
|
+
"typeRoots": ["./types"],
|
|
154
|
+
// "paths": {
|
|
155
|
+
// "@/*": [
|
|
156
|
+
// "src/*"
|
|
157
|
+
// ]
|
|
158
|
+
// }
|
|
159
|
+
},
|
|
160
|
+
"include": [
|
|
161
|
+
"src"
|
|
162
|
+
],
|
|
163
|
+
}`,
|
|
164
|
+
'utf-8'
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
console.log(
|
|
168
|
+
chalk.green(` ✔️ Created ${scriptName}/tsconfig.json`)
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function copyAsset(scriptName: string, fileName: string) {
|
|
173
|
+
console.log(` > Creating ${scriptName}/types/${fileName}.d.ts ...`)
|
|
174
|
+
await copyFile(
|
|
175
|
+
path.join(__dirname, `../public/${fileName}.d.ts`),
|
|
176
|
+
path.join(getScriptDir(scriptName), `types/${fileName}.d.ts`)
|
|
177
|
+
)
|
|
178
|
+
console.log(
|
|
179
|
+
chalk.green(` ✔️ Created ${scriptName}/types/${fileName}.d.ts`)
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function copyAssets(scriptName: string) {
|
|
184
|
+
await copyAsset(scriptName, 'scripting')
|
|
185
|
+
await copyAsset(scriptName, 'global')
|
|
186
|
+
await copyAsset(scriptName, 'assets')
|
|
187
|
+
|
|
188
|
+
// console.log(` > Creating ${scriptName}/src/svgs/logo.svg ...`)
|
|
189
|
+
// await copyFile(
|
|
190
|
+
// path.join(__dirname, '../public/logo.svg'),
|
|
191
|
+
// path.join(getScriptDir(scriptName), 'src/svgs/logo.svg')
|
|
192
|
+
// )
|
|
193
|
+
// console.log(
|
|
194
|
+
// chalk.green(` ✔️ Created ${scriptName}/src/svgs/logo.svg`)
|
|
195
|
+
// )
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function createVSCodeSettings(scriptName: string) {
|
|
199
|
+
const destDir = path.join(getScriptDir(scriptName), '.vscode')
|
|
200
|
+
|
|
201
|
+
if (!fs.existsSync(destDir)) {
|
|
202
|
+
await mkdir(destDir, { recursive: true })
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
await copyFile(
|
|
206
|
+
path.join(__dirname, '../.vscode/settings.json'),
|
|
207
|
+
path.join(destDir, 'settings.json')
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function installDeps(scriptName: string) {
|
|
212
|
+
console.log(
|
|
213
|
+
` > cd ${scriptName} && npm i -D ts-loader typescript file-loader`
|
|
214
|
+
)
|
|
215
|
+
execSync(`cd ${scriptName} && npm i -D ts-loader typescript file-loader`)
|
|
216
|
+
|
|
217
|
+
console.log(
|
|
218
|
+
chalk.green(` ✔️ Scripting script ${chalk.bold(scriptName)} is ready!`)
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export async function createScript(scriptName: string) {
|
|
223
|
+
if (!/^[a-zA-Z]+[a-zA-Z0-9-_]+$/.test(scriptName)) {
|
|
224
|
+
console.log(
|
|
225
|
+
chalk.red(`✖️ Invalid Scripting script name "${scriptName}"`)
|
|
226
|
+
)
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
console.log(
|
|
231
|
+
`Start creating ${scriptName} ...`
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
await createScriptDir(scriptName)
|
|
236
|
+
await createPackageJson(scriptName)
|
|
237
|
+
await createTSConfig(scriptName)
|
|
238
|
+
await createReadme(scriptName)
|
|
239
|
+
await createEntryFile(scriptName)
|
|
240
|
+
await copyAssets(scriptName)
|
|
241
|
+
await createVSCodeSettings(scriptName)
|
|
242
|
+
|
|
243
|
+
installDeps(scriptName)
|
|
244
|
+
|
|
245
|
+
console.log(
|
|
246
|
+
`All done! Run ${chalk.bold(
|
|
247
|
+
chalk.green(`cd ${scriptName} && npm run dev`)
|
|
248
|
+
)} to start the dev server.`
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
} catch (e: any) {
|
|
252
|
+
console.log(
|
|
253
|
+
chalk.red(`✖️ Create script failed: ${e.message}`)
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import minimist from "minimist"
|
|
4
4
|
import { startDevServer } from './startDevServer'
|
|
5
|
-
import { buildApp } from './build'
|
|
6
|
-
import {
|
|
5
|
+
// import { buildApp } from './build'
|
|
6
|
+
import { createScript } from './createScript'
|
|
7
7
|
|
|
8
8
|
function run() {
|
|
9
9
|
const args = minimist(process.argv.slice(2))
|
|
10
10
|
|
|
11
|
-
// console.log(args)
|
|
12
11
|
if (args['create'] != null) {
|
|
13
|
-
|
|
12
|
+
createScript(args['create'])
|
|
14
13
|
} else if (args._.includes('dev')) {
|
|
15
14
|
startDevServer()
|
|
16
|
-
} else if (args._.includes('build')) {
|
|
17
|
-
buildApp()
|
|
18
15
|
}
|
|
16
|
+
// else if (args._.includes('build')) {
|
|
17
|
+
// buildApp()
|
|
18
|
+
// }
|
|
19
19
|
|
|
20
20
|
}
|
|
21
21
|
|