scripting-cli 1.0.5 → 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/config/AppJsonPlugin.js +9 -9
- package/dist/config/webpack.config.js +5 -0
- package/dist/createScript.js +209 -0
- package/dist/index.js +6 -6
- package/dist/startDevServer.js +2 -2
- package/package.json +1 -1
- package/public/global.d.ts +256 -0
- package/public/scripting.d.ts +4223 -809
- package/src/config/AppJsonPlugin.ts +12 -10
- package/src/config/webpack.config.ts +4 -0
- package/src/createScript.ts +256 -0
- package/src/index.ts +6 -5
- package/src/startDevServer.ts +17 -22
- package/dist/createApp.js +0 -223
- package/src/createApp.ts +0 -282
package/src/createApp.ts
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
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 getAppDir(appName: string) {
|
|
8
|
-
return path.join(process.cwd(), appName)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async function createAppDir(appName: string) {
|
|
12
|
-
const appDir = getAppDir(appName)
|
|
13
|
-
|
|
14
|
-
if (fs.existsSync(appDir)) {
|
|
15
|
-
throw new Error(`Directory "./${appName}" already exists.`)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const dir = path.resolve(appDir, 'src/svgs')
|
|
19
|
-
await mkdir(dir, { recursive: true })
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function createEntryFile(appName: string) {
|
|
23
|
-
console.log(` > Creating ${appName}/src/index.tsx ...`)
|
|
24
|
-
|
|
25
|
-
const filePath = path.join(getAppDir(appName), '/src/index.tsx')
|
|
26
|
-
|
|
27
|
-
await writeFile(
|
|
28
|
-
filePath,
|
|
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>
|
|
58
|
-
}
|
|
59
|
-
backgroundColor={backgroundColor}
|
|
60
|
-
/>
|
|
61
|
-
}
|
|
62
|
-
>
|
|
63
|
-
<Container
|
|
64
|
-
width={'infinity'}
|
|
65
|
-
height={'infinity'}
|
|
66
|
-
color={backgroundColor}
|
|
67
|
-
>
|
|
68
|
-
<Column
|
|
69
|
-
crossAxisAlignment={'center'}
|
|
70
|
-
>
|
|
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
|
-
'utf-8'
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
console.log(
|
|
95
|
-
chalk.green(` ✔️ Created ${appName}/src/index.tsx`)
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function createPackageJson(appName: string) {
|
|
100
|
-
console.log(` > Creating ${appName}/package.json ...`)
|
|
101
|
-
|
|
102
|
-
const filePath = path.join(getAppDir(appName), 'package.json')
|
|
103
|
-
|
|
104
|
-
await writeFile(
|
|
105
|
-
filePath,
|
|
106
|
-
`{
|
|
107
|
-
"name": "${appName}",
|
|
108
|
-
"version": "0.0.1",
|
|
109
|
-
"private": true,
|
|
110
|
-
"scripts": {
|
|
111
|
-
"dev": "npx scripting-cli dev",
|
|
112
|
-
"build": "npx scripting-cli build"
|
|
113
|
-
}
|
|
114
|
-
}`,
|
|
115
|
-
'utf-8'
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
console.log(
|
|
119
|
-
chalk.green(` ✔️ Created ${appName}/package.json`)
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async function createReadme(appName: string) {
|
|
124
|
-
|
|
125
|
-
console.log(` > Creating ${appName}/README.md ...`)
|
|
126
|
-
|
|
127
|
-
const filePath = path.join(getAppDir(appName), 'README.md')
|
|
128
|
-
|
|
129
|
-
await writeFile(
|
|
130
|
-
filePath,
|
|
131
|
-
`# ${appName} - A Scripting application
|
|
132
|
-
|
|
133
|
-
## Start dev server
|
|
134
|
-
|
|
135
|
-
\`npm run dev\`
|
|
136
|
-
|
|
137
|
-
## Build App
|
|
138
|
-
|
|
139
|
-
\`npm run build\`
|
|
140
|
-
`,
|
|
141
|
-
'utf-8'
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
console.log(
|
|
145
|
-
chalk.green(` ✔️ Created ${appName}/README.md`)
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async function createTSConfig(appName: string) {
|
|
150
|
-
|
|
151
|
-
console.log(` > Creating ${appName}/tsconfig.json ...`)
|
|
152
|
-
|
|
153
|
-
const filePath = path.join(getAppDir(appName), 'tsconfig.json')
|
|
154
|
-
|
|
155
|
-
await writeFile(
|
|
156
|
-
filePath,
|
|
157
|
-
`{
|
|
158
|
-
"compilerOptions": {
|
|
159
|
-
"target": "es5",
|
|
160
|
-
"lib": [
|
|
161
|
-
"esnext",
|
|
162
|
-
],
|
|
163
|
-
"allowJs": false,
|
|
164
|
-
"skipLibCheck": true,
|
|
165
|
-
"esModuleInterop": true,
|
|
166
|
-
"allowSyntheticDefaultImports": true,
|
|
167
|
-
"strict": true,
|
|
168
|
-
"forceConsistentCasingInFileNames": true,
|
|
169
|
-
"noFallthroughCasesInSwitch": true,
|
|
170
|
-
"module": "esnext",
|
|
171
|
-
"moduleResolution": "node",
|
|
172
|
-
"resolveJsonModule": true,
|
|
173
|
-
"isolatedModules": true,
|
|
174
|
-
"jsx": "react",
|
|
175
|
-
"jsxFactory": "createElement",
|
|
176
|
-
"baseUrl": "src",
|
|
177
|
-
"paths": {
|
|
178
|
-
"@/*": [
|
|
179
|
-
"src/*"
|
|
180
|
-
]
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
"include": [
|
|
184
|
-
"src"
|
|
185
|
-
],
|
|
186
|
-
}`,
|
|
187
|
-
'utf-8'
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
console.log(
|
|
191
|
-
chalk.green(` ✔️ Created ${appName}/tsconfig.json`)
|
|
192
|
-
)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
async function copyAssets(appName: string) {
|
|
196
|
-
console.log(` > Creating ${appName}/src/scripting.d.ts ...`)
|
|
197
|
-
await copyFile(
|
|
198
|
-
path.join(__dirname, '../public/scripting.d.ts'),
|
|
199
|
-
path.join(getAppDir(appName), 'src/scripting.d.ts')
|
|
200
|
-
)
|
|
201
|
-
console.log(
|
|
202
|
-
chalk.green(` ✔️ Created ${appName}/src/scripting.d.ts`)
|
|
203
|
-
)
|
|
204
|
-
|
|
205
|
-
console.log(` > Creating ${appName}/src/assets.d.ts ...`)
|
|
206
|
-
await copyFile(
|
|
207
|
-
path.join(__dirname, '../public/assets.d.ts'),
|
|
208
|
-
path.join(getAppDir(appName), 'src/assets.d.ts')
|
|
209
|
-
)
|
|
210
|
-
console.log(
|
|
211
|
-
chalk.green(` ✔️ Created ${appName}/src/assets.d.ts`)
|
|
212
|
-
)
|
|
213
|
-
|
|
214
|
-
console.log(` > Creating ${appName}/src/svgs/logo.svg ...`)
|
|
215
|
-
await copyFile(
|
|
216
|
-
path.join(__dirname, '../public/logo.svg'),
|
|
217
|
-
path.join(getAppDir(appName), 'src/svgs/logo.svg')
|
|
218
|
-
)
|
|
219
|
-
console.log(
|
|
220
|
-
chalk.green(` ✔️ Created ${appName}/src/svgs/logo.svg`)
|
|
221
|
-
)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
async function createVSCodeSettings(appName: string) {
|
|
225
|
-
const destDir = path.join(getAppDir(appName), '.vscode')
|
|
226
|
-
|
|
227
|
-
if (!fs.existsSync(destDir)) {
|
|
228
|
-
await mkdir(destDir, { recursive: true })
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
await copyFile(
|
|
232
|
-
path.join(__dirname, '../.vscode/settings.json'),
|
|
233
|
-
path.join(destDir, 'settings.json')
|
|
234
|
-
)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function installDeps(appName: string) {
|
|
238
|
-
console.log(
|
|
239
|
-
` > cd ${appName} && npm i -D ts-loader typescript file-loader`
|
|
240
|
-
)
|
|
241
|
-
execSync(`cd ${appName} && npm i -D ts-loader typescript file-loader`)
|
|
242
|
-
|
|
243
|
-
console.log(
|
|
244
|
-
chalk.green(` ✔️ Scripting application ${chalk.bold(appName)} is ready!`)
|
|
245
|
-
)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export async function createApp(appName: string) {
|
|
249
|
-
if (!/^[a-zA-Z]+[a-zA-Z0-9-_]+$/.test(appName)) {
|
|
250
|
-
console.log(
|
|
251
|
-
chalk.red(`✖️ Invalid Scripting application name "${appName}"`)
|
|
252
|
-
)
|
|
253
|
-
return
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
console.log(
|
|
257
|
-
`Start creating ${appName} ...`
|
|
258
|
-
)
|
|
259
|
-
|
|
260
|
-
try {
|
|
261
|
-
await createAppDir(appName)
|
|
262
|
-
await createPackageJson(appName)
|
|
263
|
-
await createTSConfig(appName)
|
|
264
|
-
await createReadme(appName)
|
|
265
|
-
await createEntryFile(appName)
|
|
266
|
-
await copyAssets(appName)
|
|
267
|
-
await createVSCodeSettings(appName)
|
|
268
|
-
|
|
269
|
-
installDeps(appName)
|
|
270
|
-
|
|
271
|
-
console.log(
|
|
272
|
-
`All done! Run ${chalk.bold(
|
|
273
|
-
chalk.green(`cd ${appName} && npm run dev`)
|
|
274
|
-
)} to start the dev server.`
|
|
275
|
-
)
|
|
276
|
-
|
|
277
|
-
} catch (e: any) {
|
|
278
|
-
console.log(
|
|
279
|
-
chalk.red(`✖️ Create Scripting application failed: ${e.message}`)
|
|
280
|
-
)
|
|
281
|
-
}
|
|
282
|
-
}
|