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/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)
|
|
@@ -34,28 +37,23 @@ export function startDevServer() {
|
|
|
34
37
|
'Start running webpack compiler in watch mode...'
|
|
35
38
|
)
|
|
36
39
|
|
|
37
|
-
compiler.watch(
|
|
38
|
-
|
|
40
|
+
compiler.watch({}, (err, stats) => {
|
|
41
|
+
utils.clearConsole()
|
|
42
|
+
if (err) {
|
|
43
|
+
console.log(
|
|
44
|
+
chalk.red(' ✖️ webpack compile error: \n') + err
|
|
45
|
+
)
|
|
46
|
+
} else {
|
|
47
|
+
console.log(stats?.toString({
|
|
48
|
+
chunks: false,
|
|
49
|
+
colors: true,
|
|
50
|
+
}))
|
|
39
51
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
utils.clearConsole()
|
|
43
|
-
if (err) {
|
|
44
|
-
console.log(
|
|
45
|
-
chalk.red(' ✖️ webpack compile error: \n') + err
|
|
46
|
-
)
|
|
47
|
-
} else {
|
|
48
|
-
console.log(stats?.toString({
|
|
49
|
-
chunks: false,
|
|
50
|
-
colors: true,
|
|
51
|
-
}))
|
|
52
|
-
|
|
53
|
-
if (stats?.toJson().errorsCount === 0) {
|
|
54
|
-
onCompileDone()
|
|
55
|
-
}
|
|
52
|
+
if (stats?.toJson().errorsCount === 0) {
|
|
53
|
+
onCompileDone()
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
|
-
)
|
|
56
|
+
})
|
|
59
57
|
|
|
60
58
|
async function onCompileDone() {
|
|
61
59
|
if (isStarted) {
|
|
@@ -65,16 +63,16 @@ export function startDevServer() {
|
|
|
65
63
|
chalk.gray(` ~ Sent update event to ${connectedSockets.length} client(s)`)
|
|
66
64
|
)
|
|
67
65
|
|
|
68
|
-
const
|
|
66
|
+
const scriptJson = await readFile(
|
|
69
67
|
path.resolve(
|
|
70
68
|
process.cwd(),
|
|
71
|
-
'build/
|
|
69
|
+
'build/script.json'
|
|
72
70
|
),
|
|
73
71
|
'utf-8'
|
|
74
72
|
)
|
|
75
73
|
|
|
76
74
|
for (const socket of connectedSockets) {
|
|
77
|
-
socket.emit('update',
|
|
75
|
+
socket.emit('update', scriptJson)
|
|
78
76
|
}
|
|
79
77
|
} else {
|
|
80
78
|
start()
|
package/dist/createApp.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.createApp = void 0;
|
|
16
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
18
|
-
const node_child_process_1 = require("node:child_process");
|
|
19
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
20
|
-
const promises_1 = require("node:fs/promises");
|
|
21
|
-
function getAppDir(appName) {
|
|
22
|
-
return node_path_1.default.join(process.cwd(), appName);
|
|
23
|
-
}
|
|
24
|
-
function createAppDir(appName) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const appDir = getAppDir(appName);
|
|
27
|
-
if (node_fs_1.default.existsSync(appDir)) {
|
|
28
|
-
throw new Error(`Directory "./${appName}" already exists.`);
|
|
29
|
-
}
|
|
30
|
-
const dir = node_path_1.default.resolve(appDir, 'src/svgs');
|
|
31
|
-
yield (0, promises_1.mkdir)(dir, { recursive: true });
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function createEntryFile(appName) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
console.log(` > Creating ${appName}/src/index.tsx ...`);
|
|
37
|
-
const filePath = node_path_1.default.join(getAppDir(appName), '/src/index.tsx');
|
|
38
|
-
yield (0, promises_1.writeFile)(filePath, `
|
|
39
|
-
|
|
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
|
-
/>
|
|
70
|
-
}
|
|
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
|
-
|
|
99
|
-
`, 'utf-8');
|
|
100
|
-
console.log(chalk_1.default.green(` ✔️ Created ${appName}/src/index.tsx`));
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
function createPackageJson(appName) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
console.log(` > Creating ${appName}/package.json ...`);
|
|
106
|
-
const filePath = node_path_1.default.join(getAppDir(appName), 'package.json');
|
|
107
|
-
yield (0, promises_1.writeFile)(filePath, `{
|
|
108
|
-
"name": "${appName}",
|
|
109
|
-
"version": "0.0.1",
|
|
110
|
-
"private": true,
|
|
111
|
-
"scripts": {
|
|
112
|
-
"dev": "npx scripting-cli dev",
|
|
113
|
-
"build": "npx scripting-cli build"
|
|
114
|
-
}
|
|
115
|
-
}`, 'utf-8');
|
|
116
|
-
console.log(chalk_1.default.green(` ✔️ Created ${appName}/package.json`));
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
function createReadme(appName) {
|
|
120
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
console.log(` > Creating ${appName}/README.md ...`);
|
|
122
|
-
const filePath = node_path_1.default.join(getAppDir(appName), 'README.md');
|
|
123
|
-
yield (0, promises_1.writeFile)(filePath, `# ${appName} - A Scripting application
|
|
124
|
-
|
|
125
|
-
## Start dev server
|
|
126
|
-
|
|
127
|
-
\`npm run dev\`
|
|
128
|
-
|
|
129
|
-
## Build App
|
|
130
|
-
|
|
131
|
-
\`npm run build\`
|
|
132
|
-
`, 'utf-8');
|
|
133
|
-
console.log(chalk_1.default.green(` ✔️ Created ${appName}/README.md`));
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
function createTSConfig(appName) {
|
|
137
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
console.log(` > Creating ${appName}/tsconfig.json ...`);
|
|
139
|
-
const filePath = node_path_1.default.join(getAppDir(appName), 'tsconfig.json');
|
|
140
|
-
yield (0, promises_1.writeFile)(filePath, `{
|
|
141
|
-
"compilerOptions": {
|
|
142
|
-
"target": "es5",
|
|
143
|
-
"lib": [
|
|
144
|
-
"esnext",
|
|
145
|
-
],
|
|
146
|
-
"allowJs": false,
|
|
147
|
-
"skipLibCheck": true,
|
|
148
|
-
"esModuleInterop": true,
|
|
149
|
-
"allowSyntheticDefaultImports": true,
|
|
150
|
-
"strict": true,
|
|
151
|
-
"forceConsistentCasingInFileNames": true,
|
|
152
|
-
"noFallthroughCasesInSwitch": true,
|
|
153
|
-
"module": "esnext",
|
|
154
|
-
"moduleResolution": "node",
|
|
155
|
-
"resolveJsonModule": true,
|
|
156
|
-
"isolatedModules": true,
|
|
157
|
-
"jsx": "react",
|
|
158
|
-
"jsxFactory": "createElement",
|
|
159
|
-
"baseUrl": "src",
|
|
160
|
-
"paths": {
|
|
161
|
-
"@/*": [
|
|
162
|
-
"src/*"
|
|
163
|
-
]
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
"include": [
|
|
167
|
-
"src"
|
|
168
|
-
],
|
|
169
|
-
}`, 'utf-8');
|
|
170
|
-
console.log(chalk_1.default.green(` ✔️ Created ${appName}/tsconfig.json`));
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
function copyAssets(appName) {
|
|
174
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
console.log(` > Creating ${appName}/src/scripting.d.ts ...`);
|
|
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'));
|
|
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`));
|
|
184
|
-
});
|
|
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
|
-
}
|
|
199
|
-
function createApp(appName) {
|
|
200
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
-
if (!/^[a-zA-Z]+[a-zA-Z0-9-_]+$/.test(appName)) {
|
|
202
|
-
console.log(chalk_1.default.red(`✖️ Invalid Scripting application name "${appName}"`));
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
try {
|
|
206
|
-
yield createAppDir(appName);
|
|
207
|
-
yield createPackageJson(appName);
|
|
208
|
-
yield createTSConfig(appName);
|
|
209
|
-
yield createReadme(appName);
|
|
210
|
-
yield createEntryFile(appName);
|
|
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.`);
|
|
215
|
-
}
|
|
216
|
-
catch (e) {
|
|
217
|
-
console.log(chalk_1.default.red(`✖️ Create Scripting application failed: ${e.message}`));
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
exports.createApp = createApp;
|
package/src/createApp.ts
DELETED
|
@@ -1,275 +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
|
-
`
|
|
30
|
-
|
|
31
|
-
import { runApp, createElement, RouterProvider, Router, Column, CupertinoNavigationBar, CupertinoPageScaffold, Svg, Text, Container, Color } from 'scripting'
|
|
32
|
-
import Logo from './svgs/logo.svg'
|
|
33
|
-
|
|
34
|
-
function ScriptingLogo() {
|
|
35
|
-
return (
|
|
36
|
-
<Container
|
|
37
|
-
clipBehavior={'hardEdge'}
|
|
38
|
-
width={80}
|
|
39
|
-
height={80}
|
|
40
|
-
margin={{
|
|
41
|
-
vertical: 100,
|
|
42
|
-
}}
|
|
43
|
-
borderRadius={16}
|
|
44
|
-
>
|
|
45
|
-
<Svg src={Logo} />
|
|
46
|
-
</Container>
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function HomePage() {
|
|
51
|
-
const backgroundColor: Color = '#ffffff'
|
|
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>Welcome to Scripting!</Text>
|
|
73
|
-
</Column>
|
|
74
|
-
</Container>
|
|
75
|
-
</CupertinoPageScaffold>
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const router = new Router([
|
|
80
|
-
{
|
|
81
|
-
path: '/',
|
|
82
|
-
element: <HomePage />,
|
|
83
|
-
},
|
|
84
|
-
])
|
|
85
|
-
|
|
86
|
-
runApp(
|
|
87
|
-
<RouterProvider router={router} />
|
|
88
|
-
)
|
|
89
|
-
|
|
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(process.cwd(), '.vscode')
|
|
226
|
-
|
|
227
|
-
if (!fs.existsSync(destDir)) {
|
|
228
|
-
await mkdir(destDir)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
await copyFile(
|
|
232
|
-
path.join(__dirname, '../.vscode/settings.json'),
|
|
233
|
-
path.join(getAppDir(appName), '.vscode/settings.json')
|
|
234
|
-
)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function installDeps(appName: string) {
|
|
238
|
-
execSync(`cd ${appName} && npm i -D ts-loader typescript file-loader`)
|
|
239
|
-
|
|
240
|
-
console.log(
|
|
241
|
-
chalk.green(` ✔️ Scripting application ${chalk.bold(appName)} created!`)
|
|
242
|
-
)
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export async function createApp(appName: string) {
|
|
246
|
-
if (!/^[a-zA-Z]+[a-zA-Z0-9-_]+$/.test(appName)) {
|
|
247
|
-
console.log(
|
|
248
|
-
chalk.red(`✖️ Invalid Scripting application name "${appName}"`)
|
|
249
|
-
)
|
|
250
|
-
return
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
try {
|
|
254
|
-
await createAppDir(appName)
|
|
255
|
-
await createPackageJson(appName)
|
|
256
|
-
await createTSConfig(appName)
|
|
257
|
-
await createReadme(appName)
|
|
258
|
-
await createEntryFile(appName)
|
|
259
|
-
await copyAssets(appName)
|
|
260
|
-
await createVSCodeSettings(appName)
|
|
261
|
-
|
|
262
|
-
installDeps(appName)
|
|
263
|
-
|
|
264
|
-
console.log(
|
|
265
|
-
` ✔️ All done! Run ${chalk.bold(
|
|
266
|
-
chalk.green('npm run dev')
|
|
267
|
-
)} to start the dev server.`
|
|
268
|
-
)
|
|
269
|
-
|
|
270
|
-
} catch (e: any) {
|
|
271
|
-
console.log(
|
|
272
|
-
chalk.red(`✖️ Create Scripting application failed: ${e.message}`)
|
|
273
|
-
)
|
|
274
|
-
}
|
|
275
|
-
}
|