proteum 1.0.3 → 2.0.0
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/AGENTS.md +92 -0
- package/agents/codex/AGENTS.md +95 -0
- package/agents/codex/CODING_STYLE.md +71 -0
- package/agents/codex/agents.md.zip +0 -0
- package/agents/codex/client/AGENTS.md +102 -0
- package/agents/codex/client/pages/AGENTS.md +35 -0
- package/agents/codex/server/routes/AGENTS.md +12 -0
- package/agents/codex/server/services/AGENTS.md +137 -0
- package/agents/codex/tests/AGENTS.md +8 -0
- package/cli/app/config.ts +12 -17
- package/cli/app/index.ts +59 -99
- package/cli/bin.js +1 -1
- package/cli/commands/build.ts +23 -12
- package/cli/commands/check.ts +19 -0
- package/cli/commands/deploy/app.ts +4 -8
- package/cli/commands/deploy/web.ts +16 -20
- package/cli/commands/dev.ts +185 -75
- package/cli/commands/devEvents.ts +106 -0
- package/cli/commands/init.ts +63 -57
- package/cli/commands/lint.ts +21 -0
- package/cli/commands/refresh.ts +6 -6
- package/cli/commands/typecheck.ts +18 -0
- package/cli/compiler/client/identite.ts +79 -49
- package/cli/compiler/client/index.ts +132 -214
- package/cli/compiler/common/bundleAnalysis.ts +94 -0
- package/cli/compiler/common/clientManifest.ts +67 -0
- package/cli/compiler/common/controllers.ts +288 -0
- package/cli/compiler/common/files/autres.ts +7 -18
- package/cli/compiler/common/files/images.ts +40 -37
- package/cli/compiler/common/files/style.ts +12 -25
- package/cli/compiler/common/generatedRouteModules.ts +368 -0
- package/cli/compiler/common/index.ts +29 -68
- package/cli/compiler/common/loaders/forbid-ssr-import.js +13 -0
- package/cli/compiler/common/rspackAliases.ts +13 -0
- package/cli/compiler/common/scripts.ts +37 -0
- package/cli/compiler/index.ts +764 -234
- package/cli/compiler/server/index.ts +52 -77
- package/cli/compiler/writeIfChanged.ts +21 -0
- package/cli/index.ts +65 -90
- package/cli/paths.ts +51 -57
- package/cli/print.ts +17 -11
- package/cli/tsconfig.json +5 -4
- package/cli/utils/agents.ts +100 -0
- package/cli/utils/check.ts +71 -0
- package/cli/utils/index.ts +1 -3
- package/cli/utils/keyboard.ts +8 -25
- package/cli/utils/runProcess.ts +30 -0
- package/client/app/component.tsx +29 -29
- package/client/app/index.ts +36 -57
- package/client/app/service.ts +7 -12
- package/client/app.tsconfig.json +2 -2
- package/client/components/Dialog/Manager.ssr.tsx +40 -0
- package/client/components/Dialog/Manager.tsx +119 -150
- package/client/components/Dialog/status.tsx +3 -3
- package/client/components/index.ts +1 -1
- package/client/components/types.d.ts +1 -3
- package/client/dev/hmr.ts +65 -0
- package/client/global.d.ts +2 -2
- package/client/hooks.ts +6 -9
- package/client/index.ts +2 -1
- package/client/islands/index.ts +7 -0
- package/client/islands/useDeferredModule.ts +199 -0
- package/client/pages/_layout/index.tsx +4 -12
- package/client/pages/useHeader.tsx +14 -21
- package/client/router.ts +27 -0
- package/client/services/router/components/Link.tsx +34 -27
- package/client/services/router/components/Page.tsx +6 -14
- package/client/services/router/components/router.ssr.tsx +36 -0
- package/client/services/router/components/router.tsx +63 -83
- package/client/services/router/index.tsx +185 -220
- package/client/services/router/request/api.ts +97 -119
- package/client/services/router/request/history.ts +2 -2
- package/client/services/router/request/index.ts +13 -12
- package/client/services/router/request/multipart.ts +72 -62
- package/client/services/router/response/index.tsx +68 -61
- package/client/services/router/response/page.ts +28 -32
- package/client/utils/dom.ts +17 -33
- package/common/app/index.ts +3 -3
- package/common/data/chaines/index.ts +22 -23
- package/common/data/dates.ts +35 -70
- package/common/data/markdown.ts +42 -39
- package/common/dev/serverHotReload.ts +26 -0
- package/common/errors/index.tsx +110 -142
- package/common/router/contracts.ts +29 -0
- package/common/router/index.ts +89 -108
- package/common/router/layouts.ts +34 -47
- package/common/router/pageSetup.ts +50 -0
- package/common/router/register.ts +53 -24
- package/common/router/request/api.ts +30 -36
- package/common/router/request/index.ts +2 -8
- package/common/router/response/index.ts +8 -15
- package/common/router/response/page.ts +70 -58
- package/common/utils.ts +1 -1
- package/eslint.js +62 -0
- package/package.json +12 -45
- package/prettier.config.cjs +9 -0
- package/scripts/cleanup-generated-controllers.ts +62 -0
- package/scripts/fix-reference-app-typing.ts +490 -0
- package/scripts/refactor-client-app-imports.ts +244 -0
- package/scripts/refactor-client-pages.ts +587 -0
- package/scripts/refactor-server-controllers.ts +470 -0
- package/scripts/refactor-server-runtime-aliases.ts +360 -0
- package/scripts/restore-client-app-import-files.ts +41 -0
- package/scripts/restore-files-from-git-head.ts +20 -0
- package/scripts/update-codex-agents.ts +35 -0
- package/server/app/commands.ts +35 -64
- package/server/app/container/config.ts +39 -69
- package/server/app/container/console/index.ts +202 -248
- package/server/app/container/index.ts +33 -71
- package/server/app/controller/index.ts +61 -0
- package/server/app/index.ts +39 -105
- package/server/app/service/container.ts +41 -42
- package/server/app/service/index.ts +120 -147
- package/server/context.ts +1 -1
- package/server/index.ts +25 -1
- package/server/services/auth/index.ts +75 -115
- package/server/services/auth/router/index.ts +31 -32
- package/server/services/auth/router/request.ts +14 -16
- package/server/services/cron/CronTask.ts +13 -26
- package/server/services/cron/index.ts +14 -36
- package/server/services/disks/driver.ts +40 -58
- package/server/services/disks/drivers/local/index.ts +79 -90
- package/server/services/disks/drivers/s3/index.ts +116 -163
- package/server/services/disks/index.ts +23 -38
- package/server/services/email/index.ts +45 -104
- package/server/services/email/utils.ts +14 -27
- package/server/services/fetch/index.ts +53 -85
- package/server/services/prisma/Facet.ts +39 -91
- package/server/services/prisma/index.ts +74 -110
- package/server/services/router/generatedRuntime.ts +29 -0
- package/server/services/router/http/index.ts +77 -72
- package/server/services/router/http/multipart.ts +19 -42
- package/server/services/router/index.ts +378 -365
- package/server/services/router/request/api.ts +26 -25
- package/server/services/router/request/index.ts +44 -51
- package/server/services/router/request/service.ts +7 -11
- package/server/services/router/request/validation/zod.ts +111 -148
- package/server/services/router/response/index.ts +110 -125
- package/server/services/router/response/mask/Filter.ts +31 -72
- package/server/services/router/response/mask/index.ts +8 -15
- package/server/services/router/response/mask/selecteurs.ts +11 -25
- package/server/services/router/response/page/clientManifest.ts +25 -0
- package/server/services/router/response/page/document.tsx +199 -127
- package/server/services/router/response/page/index.tsx +89 -94
- package/server/services/router/service.ts +13 -15
- package/server/services/schema/index.ts +17 -26
- package/server/services/schema/request.ts +19 -33
- package/server/services/schema/router/index.ts +8 -11
- package/server/services/security/encrypt/aes/index.ts +15 -35
- package/server/utils/slug.ts +29 -32
- package/skills/clean-project-code/SKILL.md +63 -0
- package/skills/clean-project-code/agents/openai.yaml +4 -0
- package/tsconfig.common.json +4 -3
- package/tsconfig.json +4 -1
- package/types/aliases.d.ts +17 -21
- package/types/controller-input.test.ts +48 -0
- package/types/express-extra.d.ts +6 -0
- package/types/global/constants.d.ts +1 -0
- package/types/global/express-extra.d.ts +6 -0
- package/types/global/modules.d.ts +13 -16
- package/types/global/utils.d.ts +17 -49
- package/types/global/vendors.d.ts +62 -0
- package/types/icons.d.ts +65 -1
- package/types/uuid.d.ts +3 -0
- package/types/vendors.d.ts +62 -0
- package/cli/compiler/common/babel/index.ts +0 -173
- package/cli/compiler/common/babel/plugins/index.ts +0 -0
- package/cli/compiler/common/babel/plugins/services.ts +0 -586
- package/cli/compiler/common/babel/routes/imports.ts +0 -127
- package/cli/compiler/common/babel/routes/routes.ts +0 -1170
- package/client/services/captcha/index.ts +0 -67
- package/client/services/socket/index.ts +0 -147
- package/common/data/rte/nodes.ts +0 -83
- package/common/data/stats.ts +0 -90
- package/common/utils/rte.ts +0 -183
- package/server/services/auth/old.ts +0 -277
- package/server/services/cache/commands.ts +0 -41
- package/server/services/cache/index.ts +0 -297
- package/server/services/cache/service.json +0 -6
- package/server/services/socket/index.ts +0 -162
- package/server/services/socket/scope.ts +0 -226
- package/server/services/socket/service.json +0 -6
- package/server/services_old/SocketClient.ts +0 -92
- package/server/services_old/Token.old.ts +0 -97
|
@@ -3,16 +3,12 @@
|
|
|
3
3
|
----------------------------------*/
|
|
4
4
|
|
|
5
5
|
// Npm
|
|
6
|
-
import
|
|
7
|
-
import fs from 'fs-extra';
|
|
8
|
-
|
|
9
|
-
// Minimizers
|
|
10
|
-
const TerserPlugin = require("terser-webpack-plugin");
|
|
11
|
-
//var VirtualModulesPlugin = require('webpack-virtual-modules');
|
|
6
|
+
import { type Configuration } from '@rspack/core';
|
|
12
7
|
|
|
13
8
|
// Core
|
|
14
9
|
import cli from '@cli';
|
|
15
10
|
import createCommonConfig, { TCompileMode, TCompileOutputTarget, regex } from '../common';
|
|
11
|
+
import { toRspackAliases } from '../common/rspackAliases';
|
|
16
12
|
|
|
17
13
|
// Type
|
|
18
14
|
import type { App } from '../../app';
|
|
@@ -35,6 +31,12 @@ import type { App } from '../../app';
|
|
|
35
31
|
}*/
|
|
36
32
|
|
|
37
33
|
const debug = false;
|
|
34
|
+
const ssrScriptExtensions = ['.ssr.ts', '.ssr.tsx'];
|
|
35
|
+
|
|
36
|
+
const getDevGeneratedRuntimeEntries = (app: App) => ({
|
|
37
|
+
__proteum_dev_routes: [app.paths.server.generated + '/routes.ts'],
|
|
38
|
+
__proteum_dev_controllers: [app.paths.server.generated + '/controllers.ts'],
|
|
39
|
+
});
|
|
38
40
|
|
|
39
41
|
/*----------------------------------
|
|
40
42
|
- CONFIG
|
|
@@ -42,39 +44,39 @@ const debug = false;
|
|
|
42
44
|
export default function createCompiler(
|
|
43
45
|
app: App,
|
|
44
46
|
mode: TCompileMode,
|
|
45
|
-
outputTarget: TCompileOutputTarget = mode === 'dev' ? 'dev' : 'bin'
|
|
46
|
-
):
|
|
47
|
-
|
|
47
|
+
outputTarget: TCompileOutputTarget = mode === 'dev' ? 'dev' : 'bin',
|
|
48
|
+
): Configuration {
|
|
48
49
|
debug && console.info(`Creating compiler for server (${mode}).`);
|
|
49
50
|
const dev = mode === 'dev';
|
|
50
|
-
const buildDev = dev && outputTarget === 'bin';
|
|
51
51
|
const outputPath = app.outputPath(outputTarget);
|
|
52
52
|
|
|
53
53
|
const commonConfig = createCommonConfig(app, 'server', mode, outputTarget);
|
|
54
|
-
const { aliases } = app.aliases.server.forWebpack({
|
|
55
|
-
modulesPath: app.paths.root + '/node_modules'
|
|
56
|
-
});
|
|
54
|
+
const { aliases } = app.aliases.server.forWebpack({ modulesPath: app.paths.root + '/node_modules' });
|
|
57
55
|
|
|
58
56
|
// We're not supposed in any case to import client services from server
|
|
59
|
-
delete aliases[
|
|
60
|
-
delete aliases[
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
delete aliases['@client/services'];
|
|
58
|
+
delete aliases['@/client/services'];
|
|
59
|
+
const rspackAliases = toRspackAliases(aliases);
|
|
60
|
+
rspackAliases['@/client/router$'] = cli.paths.core.root + '/client/router.ts';
|
|
61
|
+
|
|
62
|
+
debug &&
|
|
63
|
+
console.log(
|
|
64
|
+
`[${mode}] node_modules dirs:`,
|
|
65
|
+
commonConfig.resolveLoader?.modules,
|
|
66
|
+
'\nModule aliases for rspack:',
|
|
67
|
+
rspackAliases,
|
|
68
|
+
);
|
|
69
|
+
const config: Configuration = {
|
|
66
70
|
...commonConfig,
|
|
67
71
|
|
|
68
72
|
name: 'server',
|
|
69
73
|
target: 'node',
|
|
70
74
|
entry: {
|
|
71
|
-
server: [
|
|
72
|
-
|
|
73
|
-
],
|
|
75
|
+
server: [cli.paths.coreRoot + '/server/index.ts'],
|
|
76
|
+
...(dev ? getDevGeneratedRuntimeEntries(app) : {}),
|
|
74
77
|
},
|
|
75
78
|
|
|
76
79
|
output: {
|
|
77
|
-
|
|
78
80
|
pathinfo: dev,
|
|
79
81
|
|
|
80
82
|
libraryTarget: 'commonjs2',
|
|
@@ -88,39 +90,32 @@ export default function createCompiler(
|
|
|
88
90
|
// HMR
|
|
89
91
|
hotUpdateMainFilename: 'updates/[fullhash].hot-update.json',
|
|
90
92
|
hotUpdateChunkFilename: 'updates/[id].[fullhash].hot-update.js',
|
|
91
|
-
|
|
92
93
|
},
|
|
93
94
|
|
|
94
95
|
externalsPresets: { node: true }, // in order to ignore built-in modules like path, fs, etc.
|
|
95
96
|
externals: [
|
|
96
|
-
|
|
97
|
-
'./chunk-manifest.json',
|
|
98
|
-
'./asset-manifest.json',
|
|
97
|
+
'./client-manifest.json',
|
|
99
98
|
|
|
100
99
|
// node_modules
|
|
101
100
|
function ({ request }, callback) {
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
const shouldCompile =
|
|
102
|
+
request !== undefined &&
|
|
104
103
|
// Local files
|
|
105
|
-
request[0] === '.' ||
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
request.startsWith('react-number-format') ||
|
|
117
|
-
request.startsWith('@floating-ui')
|
|
118
|
-
)
|
|
104
|
+
(request[0] === '.' ||
|
|
105
|
+
request[0] === '/' ||
|
|
106
|
+
// Aliased modules
|
|
107
|
+
app.aliases.server.containsAlias(request) ||
|
|
108
|
+
// TODO: proteum.conf: compile: include
|
|
109
|
+
// Compile proteum modules
|
|
110
|
+
request.startsWith('proteum') ||
|
|
111
|
+
// Compile 5HTP modules
|
|
112
|
+
request.startsWith('@mantine/') ||
|
|
113
|
+
request.startsWith('react-number-format') ||
|
|
114
|
+
request.startsWith('@floating-ui'));
|
|
119
115
|
|
|
120
116
|
//console.log('isNodeModule', request, isNodeModule);
|
|
121
117
|
|
|
122
118
|
if (!shouldCompile) {
|
|
123
|
-
|
|
124
119
|
// Externalize to a commonjs module using the request path
|
|
125
120
|
return callback(undefined, 'commonjs ' + request);
|
|
126
121
|
}
|
|
@@ -131,12 +126,12 @@ export default function createCompiler(
|
|
|
131
126
|
],
|
|
132
127
|
|
|
133
128
|
resolve: {
|
|
134
|
-
|
|
135
129
|
...commonConfig.resolve,
|
|
136
130
|
|
|
137
|
-
alias:
|
|
131
|
+
alias: rspackAliases,
|
|
138
132
|
|
|
139
|
-
|
|
133
|
+
// Prefer SSR-specific variants on the server when imports stay extensionless.
|
|
134
|
+
extensions: [...ssrScriptExtensions, '.ts', '.tsx', '.json', '.sql', '.js'],
|
|
140
135
|
},
|
|
141
136
|
|
|
142
137
|
module: {
|
|
@@ -147,7 +142,6 @@ export default function createCompiler(
|
|
|
147
142
|
{
|
|
148
143
|
test: regex.scripts,
|
|
149
144
|
include: [
|
|
150
|
-
|
|
151
145
|
app.paths.root + '/client',
|
|
152
146
|
cli.paths.core.root + '/client',
|
|
153
147
|
|
|
@@ -162,15 +156,12 @@ export default function createCompiler(
|
|
|
162
156
|
// Temp disabled because compile issue on vercel
|
|
163
157
|
//...getCorePluginsList(app)
|
|
164
158
|
],
|
|
165
|
-
rules: require('../common/
|
|
166
|
-
},
|
|
159
|
+
rules: require('../common/scripts')({ app, side: 'server', dev }),
|
|
160
|
+
},
|
|
167
161
|
|
|
168
162
|
// Les pages étan tà la fois compilées dans le bundle client et serveur
|
|
169
163
|
// On ne compile les ressources (css) qu'une seule fois (coté client)
|
|
170
|
-
{
|
|
171
|
-
test: regex.style,
|
|
172
|
-
loader: 'null-loader'
|
|
173
|
-
},
|
|
164
|
+
{ test: regex.style, loader: 'null-loader' },
|
|
174
165
|
|
|
175
166
|
...require('../common/files/images')(app, dev, false),
|
|
176
167
|
|
|
@@ -186,35 +177,19 @@ export default function createCompiler(
|
|
|
186
177
|
],
|
|
187
178
|
},
|
|
188
179
|
|
|
189
|
-
plugins: [
|
|
190
|
-
|
|
191
|
-
...(commonConfig.plugins || [])
|
|
192
|
-
],
|
|
180
|
+
plugins: [...(commonConfig.plugins || [])],
|
|
193
181
|
|
|
194
|
-
optimization: {
|
|
195
|
-
minimizer: dev ? [] : [
|
|
196
|
-
new TerserPlugin({
|
|
197
|
-
terserOptions: {
|
|
198
|
-
// Consere les classnames
|
|
199
|
-
//keep_classnames: true,
|
|
200
|
-
//keep_fnames: true,
|
|
201
|
-
}
|
|
202
|
-
}),
|
|
203
|
-
]
|
|
204
|
-
},
|
|
182
|
+
optimization: { minimizer: [] },
|
|
205
183
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
? false
|
|
209
|
-
: dev
|
|
210
|
-
? 'eval-source-map' // Recommended choice for development builds with high quality SourceMaps.
|
|
184
|
+
devtool: dev
|
|
185
|
+
? 'eval-cheap-module-source-map' // Cheaper than eval-source-map while keeping usable module-level stack traces.
|
|
211
186
|
: 'source-map', // Recommended choice for production builds with high quality SourceMaps.
|
|
212
187
|
|
|
213
|
-
|
|
188
|
+
// eval-source-map n'est pas précis
|
|
214
189
|
/*devServer: {
|
|
215
190
|
hot: true,
|
|
216
191
|
},*/
|
|
217
192
|
};
|
|
218
193
|
|
|
219
194
|
return config;
|
|
220
|
-
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
|
|
4
|
+
const toBuffer = (content: string | Buffer) => (typeof content === 'string' ? Buffer.from(content) : content);
|
|
5
|
+
|
|
6
|
+
export default function writeIfChanged(filepath: string, content: string | Buffer) {
|
|
7
|
+
const nextContent = toBuffer(content);
|
|
8
|
+
const dirpath = path.dirname(filepath);
|
|
9
|
+
|
|
10
|
+
fs.ensureDirSync(dirpath);
|
|
11
|
+
|
|
12
|
+
if (fs.existsSync(filepath)) {
|
|
13
|
+
const currentContent = fs.readFileSync(filepath);
|
|
14
|
+
|
|
15
|
+
if (currentContent.equals(nextContent)) return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
fs.writeFileSync(filepath, nextContent);
|
|
19
|
+
|
|
20
|
+
return true;
|
|
21
|
+
}
|
package/cli/index.ts
CHANGED
|
@@ -17,13 +17,9 @@ import Paths from './paths';
|
|
|
17
17
|
- TYPES
|
|
18
18
|
----------------------------------*/
|
|
19
19
|
|
|
20
|
-
type TCliCommand = () => Promise<{
|
|
21
|
-
run: () => Promise<void>
|
|
22
|
-
}>
|
|
20
|
+
type TCliCommand = () => Promise<{ run: () => Promise<void> }>;
|
|
23
21
|
|
|
24
|
-
type TArgsObject = {
|
|
25
|
-
[key: string]: string | boolean | string[]
|
|
26
|
-
}
|
|
22
|
+
type TArgsObject = { [key: string]: string | boolean | string[] };
|
|
27
23
|
|
|
28
24
|
/*----------------------------------
|
|
29
25
|
- CLASSE
|
|
@@ -32,30 +28,20 @@ type TArgsObject = {
|
|
|
32
28
|
IMPORTANT: The CLI must be independant of the app instance and libs
|
|
33
29
|
*/
|
|
34
30
|
export class CLI {
|
|
35
|
-
|
|
36
31
|
// Context
|
|
37
32
|
public args: TArgsObject = {};
|
|
38
33
|
|
|
39
34
|
public commandOptionDefaults: { [command: string]: TArgsObject } = {
|
|
40
|
-
dev: {
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
build: {
|
|
44
|
-
port: '',
|
|
45
|
-
dev: false,
|
|
46
|
-
prod: false,
|
|
47
|
-
analyze: false,
|
|
48
|
-
cache: false,
|
|
49
|
-
},
|
|
35
|
+
dev: { port: '', cache: true },
|
|
36
|
+
build: { port: '', dev: false, prod: false, cache: false, analyze: false },
|
|
37
|
+
lint: { fix: false },
|
|
50
38
|
};
|
|
51
|
-
|
|
39
|
+
|
|
52
40
|
public debug: boolean = false;
|
|
53
41
|
|
|
54
|
-
public packageJson: {[key: string]: any};
|
|
42
|
+
public packageJson: { [key: string]: any };
|
|
55
43
|
|
|
56
|
-
public constructor(
|
|
57
|
-
public paths = new Paths( process.cwd() )
|
|
58
|
-
) {
|
|
44
|
+
public constructor(public paths = new Paths(process.cwd())) {
|
|
59
45
|
this.debug && console.log(`[cli] 5HTP CLI`, process.env.npm_package_version);
|
|
60
46
|
|
|
61
47
|
this.debug && console.log(`[cli] Apply aliases ...`);
|
|
@@ -72,118 +58,111 @@ export class CLI {
|
|
|
72
58
|
// Les importations asynchrones permettent d'accéder à l'instance de cli via un import
|
|
73
59
|
// WARN: We load commands asynchonously, so the aliases are applied before the file is imported
|
|
74
60
|
public commands: { [name: string]: TCliCommand } = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
61
|
+
init: () => import('./commands/init'),
|
|
62
|
+
dev: () => import('./commands/dev'),
|
|
63
|
+
refresh: () => import('./commands/refresh'),
|
|
64
|
+
build: () => import('./commands/build'),
|
|
65
|
+
typecheck: () => import('./commands/typecheck'),
|
|
66
|
+
lint: () => import('./commands/lint'),
|
|
67
|
+
check: () => import('./commands/check'),
|
|
68
|
+
};
|
|
80
69
|
|
|
81
70
|
private loadPkg() {
|
|
82
71
|
return fs.readJSONSync(this.paths.core.root + '/package.json');
|
|
83
72
|
}
|
|
84
73
|
|
|
85
74
|
public start() {
|
|
86
|
-
|
|
87
75
|
const [, , commandName, ...argv] = process.argv;
|
|
88
76
|
|
|
89
|
-
if (this.commands[commandName] === undefined)
|
|
90
|
-
throw new Error(`Command ${commandName} does not exists.`);
|
|
77
|
+
if (this.commands[commandName] === undefined) throw new Error(`Command ${commandName} does not exists.`);
|
|
91
78
|
|
|
92
|
-
this.args = {
|
|
93
|
-
...(this.commandOptionDefaults[commandName] || {})
|
|
94
|
-
};
|
|
79
|
+
this.args = { ...(this.commandOptionDefaults[commandName] || {}) };
|
|
95
80
|
this.args.workdir = process.cwd();
|
|
96
81
|
|
|
97
82
|
let opt: string | null = null;
|
|
98
83
|
for (const a of argv) {
|
|
99
|
-
|
|
100
84
|
if (a.startsWith('-')) {
|
|
101
|
-
|
|
102
85
|
opt = a.replace(/^-+/, '');
|
|
103
|
-
if (opt.length === 0)
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
|
|
86
|
+
if (opt.length === 0) throw new Error(`Unknown option: ${a}`);
|
|
87
|
+
|
|
88
|
+
if (opt.startsWith('no-')) {
|
|
89
|
+
const booleanOpt = opt.substring(3);
|
|
90
|
+
if (!(booleanOpt in this.args)) throw new Error(`Unknown option: ${opt}`);
|
|
91
|
+
if (typeof this.args[booleanOpt] !== 'boolean')
|
|
92
|
+
throw new Error(`Option ${booleanOpt} does not support --no-${booleanOpt}.`);
|
|
93
|
+
|
|
94
|
+
this.args[booleanOpt] = false;
|
|
95
|
+
opt = null;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!(opt in this.args)) throw new Error(`Unknown option: ${opt}`);
|
|
107
100
|
|
|
108
101
|
// Init with default value
|
|
109
|
-
if (typeof this.args[opt] ===
|
|
102
|
+
if (typeof this.args[opt] === 'boolean') {
|
|
110
103
|
this.args[opt] = true;
|
|
111
104
|
opt = null;
|
|
112
105
|
}
|
|
113
|
-
|
|
114
106
|
} else if (opt !== null) {
|
|
115
|
-
|
|
116
107
|
const curVal = this.args[opt];
|
|
117
108
|
|
|
118
|
-
if (Array.isArray( curVal
|
|
119
|
-
|
|
120
|
-
else
|
|
121
|
-
this.args[opt] = a;
|
|
109
|
+
if (Array.isArray(curVal)) curVal.push(a);
|
|
110
|
+
else this.args[opt] = a;
|
|
122
111
|
|
|
123
112
|
opt = null;
|
|
124
|
-
|
|
125
113
|
} else {
|
|
126
|
-
|
|
127
|
-
this.args[ a ] = true;
|
|
128
|
-
|
|
114
|
+
this.args[a] = true;
|
|
129
115
|
}
|
|
130
116
|
}
|
|
131
117
|
|
|
132
|
-
if (opt !== null && typeof this.args[opt] !== 'boolean')
|
|
133
|
-
throw new Error(`Missing value for option: ${opt}`);
|
|
118
|
+
if (opt !== null && typeof this.args[opt] !== 'boolean') throw new Error(`Missing value for option: ${opt}`);
|
|
134
119
|
|
|
135
120
|
this.runCommand(commandName);
|
|
136
121
|
}
|
|
137
122
|
|
|
138
123
|
public async runCommand(command: string) {
|
|
139
|
-
|
|
140
124
|
this.debug && console.info(`Running command ${command}`, this.args);
|
|
141
125
|
|
|
142
126
|
// Check existance
|
|
143
|
-
if (this.commands[command] === undefined)
|
|
144
|
-
throw new Error(`Command ${command} does not exists.`);
|
|
127
|
+
if (this.commands[command] === undefined) throw new Error(`Command ${command} does not exists.`);
|
|
145
128
|
|
|
146
129
|
const runner = await this.commands[command]();
|
|
130
|
+
let exitCode = 0;
|
|
147
131
|
|
|
148
132
|
// Running
|
|
149
|
-
runner
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
})
|
|
133
|
+
runner
|
|
134
|
+
.run()
|
|
135
|
+
.then(() => {
|
|
136
|
+
this.debug && console.info(`Command ${command} finished.`);
|
|
137
|
+
})
|
|
138
|
+
.catch((e) => {
|
|
139
|
+
exitCode = 1;
|
|
140
|
+
console.error(`Error during execution of ${command}:`, e);
|
|
141
|
+
})
|
|
142
|
+
.finally(() => {
|
|
143
|
+
process.exit(exitCode);
|
|
144
|
+
});
|
|
162
145
|
}
|
|
163
146
|
|
|
164
|
-
|
|
165
147
|
public shell(...commands: string[]) {
|
|
166
|
-
|
|
167
148
|
return new Promise<void>(async (resolve) => {
|
|
149
|
+
const fullCommand = commands
|
|
150
|
+
.map((command) => {
|
|
151
|
+
command = command.trim();
|
|
168
152
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
command = command.trim();
|
|
172
|
-
|
|
173
|
-
if (command.endsWith(';'))
|
|
174
|
-
command = command.substring(0, command.length - 1);
|
|
153
|
+
if (command.endsWith(';')) command = command.substring(0, command.length - 1);
|
|
175
154
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
155
|
+
return command;
|
|
156
|
+
})
|
|
157
|
+
.join(';');
|
|
179
158
|
|
|
180
159
|
console.log('$ ' + fullCommand);
|
|
181
160
|
|
|
182
161
|
/*const tempFile = this.paths.app.root + '/.exec.sh';
|
|
183
162
|
fs.outputFileSync(tempFile, '#! /bin/bash\n' + fullCommand);
|
|
184
163
|
const wrappedCommand = `tilix --new-process -e bash -c 'chmod +x "${tempFile}"; "${tempFile}"; echo "Entrée pour continuer"; read a;'`;*/
|
|
185
|
-
const wrappedCommand =
|
|
186
|
-
console.log(
|
|
164
|
+
const wrappedCommand = `bash -c '${fullCommand}'`;
|
|
165
|
+
console.log('Running command: ' + wrappedCommand);
|
|
187
166
|
//await this.waitForInput('enter');
|
|
188
167
|
|
|
189
168
|
const proc = cp.spawn(wrappedCommand, [], {
|
|
@@ -191,23 +170,19 @@ export class CLI {
|
|
|
191
170
|
detached: false,
|
|
192
171
|
// Permer de lancer les commandes via des chaines pures (autrement, il faut separer chaque arg dans un tableau)
|
|
193
172
|
// https://stackoverflow.com/questions/23487363/how-can-i-parse-a-string-into-appropriate-arguments-for-child-process-spawn
|
|
194
|
-
shell: true
|
|
173
|
+
shell: true,
|
|
195
174
|
});
|
|
196
175
|
|
|
197
|
-
console.log(
|
|
176
|
+
console.log(proc.exitCode);
|
|
198
177
|
|
|
199
178
|
proc.on('exit', function () {
|
|
200
|
-
|
|
201
179
|
//fs.removeSync(tempFile);
|
|
202
180
|
|
|
203
|
-
console.log(
|
|
181
|
+
console.log('Command finished.');
|
|
204
182
|
resolve();
|
|
205
|
-
})
|
|
206
|
-
|
|
183
|
+
});
|
|
207
184
|
});
|
|
208
|
-
|
|
209
185
|
}
|
|
210
|
-
|
|
211
186
|
}
|
|
212
187
|
|
|
213
|
-
export default new CLI()
|
|
188
|
+
export default new CLI();
|