proteum 1.0.0 → 1.0.3
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 +9 -0
- package/cli/app/config.ts +61 -0
- package/cli/app/index.ts +227 -0
- package/cli/bin.js +35 -0
- package/cli/commands/build.ts +60 -0
- package/cli/commands/deploy/app.ts +29 -0
- package/cli/commands/deploy/web.ts +60 -0
- package/cli/commands/dev.ts +124 -0
- package/cli/commands/init.ts +85 -0
- package/cli/commands/refresh.ts +18 -0
- package/cli/compiler/client/identite.ts +69 -0
- package/cli/compiler/client/index.ts +343 -0
- package/cli/compiler/common/babel/index.ts +173 -0
- package/cli/compiler/common/babel/plugins/index.ts +0 -0
- package/cli/compiler/common/babel/plugins/services.ts +586 -0
- package/cli/compiler/common/babel/routes/imports.ts +127 -0
- package/cli/compiler/common/babel/routes/routes.ts +1170 -0
- package/cli/compiler/common/files/autres.ts +39 -0
- package/cli/compiler/common/files/images.ts +42 -0
- package/cli/compiler/common/files/style.ts +82 -0
- package/cli/compiler/common/index.ts +165 -0
- package/cli/compiler/index.ts +585 -0
- package/cli/compiler/server/index.ts +220 -0
- package/cli/index.ts +213 -0
- package/cli/paths.ts +165 -0
- package/cli/print.ts +12 -0
- package/cli/tsconfig.json +42 -0
- package/cli/utils/index.ts +22 -0
- package/cli/utils/keyboard.ts +78 -0
- package/client/app/index.ts +2 -0
- package/client/components/Dialog/Manager.tsx +3 -49
- package/client/components/Dialog/index.less +3 -1
- package/client/components/index.ts +1 -2
- package/client/services/router/index.tsx +6 -16
- package/common/errors/index.tsx +12 -31
- package/package.json +58 -22
- package/server/app/container/config.ts +20 -1
- package/server/app/container/console/index.ts +1 -1
- package/server/services/auth/index.ts +62 -27
- package/server/services/auth/router/request.ts +17 -6
- package/server/services/router/http/index.ts +3 -3
- package/server/services/router/response/index.ts +1 -1
- package/server/services/schema/request.ts +28 -10
- package/server/utils/slug.ts +0 -3
- package/tsconfig.common.json +2 -1
- package/types/global/constants.d.ts +12 -0
- package/changelog.md +0 -5
- package/client/components/Button.tsx +0 -298
- package/client/components/Dialog/card.tsx +0 -208
- package/client/data/input.ts +0 -32
- package/client/pages/bug.tsx.old +0 -60
- package/templates/composant.tsx +0 -40
- package/templates/form.ts +0 -30
- package/templates/modal.tsx +0 -47
- package/templates/modele.ts +0 -56
- package/templates/page.tsx +0 -74
- package/templates/route.ts +0 -43
- package/templates/service.ts +0 -75
- package/vscode/copyimportationpath/.eslintrc.json +0 -24
- package/vscode/copyimportationpath/.vscodeignore +0 -12
- package/vscode/copyimportationpath/CHANGELOG.md +0 -9
- package/vscode/copyimportationpath/README.md +0 -3
- package/vscode/copyimportationpath/copyimportationpath-0.0.1.vsix +0 -0
- package/vscode/copyimportationpath/out/extension.js +0 -206
- package/vscode/copyimportationpath/out/extension.js.map +0 -1
- package/vscode/copyimportationpath/package-lock.json +0 -4536
- package/vscode/copyimportationpath/package.json +0 -86
- package/vscode/copyimportationpath/src/extension.ts +0 -300
- package/vscode/copyimportationpath/tsconfig.json +0 -22
- package/vscode/copyimportationpath/vsc-extension-quickstart.md +0 -42
package/AGENTS.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Workflow
|
|
2
|
+
|
|
3
|
+
- Everytime I input error messages without any instructions, don't implement fixes.
|
|
4
|
+
Instead, ivestigate the potential causes of the errors, and for each:
|
|
5
|
+
1. Evaluate / quantify the probabiliies
|
|
6
|
+
2. Give why and
|
|
7
|
+
3. Suggest how to fix it
|
|
8
|
+
- When you have finished your work, summarize in one top-level short sentence ALL the changes you made since the beginning of the WHOLE conversation. Output as "Commit message". Max 90 characters.
|
|
9
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
NOTE: This is a copy of core/sever/app/config
|
|
7
|
+
We can't import core deps here because it will cause the following error:
|
|
8
|
+
"Can't use import when not a module"
|
|
9
|
+
It will be possible to import core files when the CLI will be compiled as one output file with tsc
|
|
10
|
+
And for that, we need to fix the TS errors for the CLI
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Npm
|
|
14
|
+
import fs from 'fs-extra';
|
|
15
|
+
import yaml from 'yaml';
|
|
16
|
+
|
|
17
|
+
// Types
|
|
18
|
+
import type { TEnvConfig } from '../../server/app/container/config';
|
|
19
|
+
|
|
20
|
+
/*----------------------------------
|
|
21
|
+
- LOADE
|
|
22
|
+
----------------------------------*/
|
|
23
|
+
export default class ConfigParser {
|
|
24
|
+
|
|
25
|
+
public constructor(
|
|
26
|
+
public appDir: string,
|
|
27
|
+
public envName?: string,
|
|
28
|
+
public routerPortOverride?: number
|
|
29
|
+
) {
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private loadYaml( filepath: string ) {
|
|
34
|
+
console.info(`Loading config ${filepath}`);
|
|
35
|
+
const rawConfig = fs.readFileSync(filepath, 'utf-8');
|
|
36
|
+
return yaml.parse(rawConfig);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public env(): TEnvConfig {
|
|
40
|
+
// We assume that when we run 5htp dev, we're in local
|
|
41
|
+
// Otherwise, we're in production environment (docker)
|
|
42
|
+
console.log("[app] Using environment:", process.env.NODE_ENV);
|
|
43
|
+
const envFileName = this.appDir + '/env.yaml';
|
|
44
|
+
const envFile = this.loadYaml( envFileName );
|
|
45
|
+
return {
|
|
46
|
+
...envFile,
|
|
47
|
+
router: this.routerPortOverride === undefined
|
|
48
|
+
? envFile.router
|
|
49
|
+
: {
|
|
50
|
+
...envFile.router,
|
|
51
|
+
port: this.routerPortOverride
|
|
52
|
+
},
|
|
53
|
+
version: 'CLI'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public identity() {
|
|
58
|
+
const identityFile = this.appDir + '/identity.yaml';
|
|
59
|
+
return this.loadYaml( identityFile );
|
|
60
|
+
}
|
|
61
|
+
}
|
package/cli/app/index.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// npm
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import TsAlias from 'ts-alias';
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
|
|
10
|
+
// Cre
|
|
11
|
+
import cli from '..';
|
|
12
|
+
|
|
13
|
+
// Specific
|
|
14
|
+
import ConfigParser from './config';
|
|
15
|
+
import type { TEnvConfig } from '../../server/app/container/config';
|
|
16
|
+
|
|
17
|
+
/*----------------------------------
|
|
18
|
+
- TYPES
|
|
19
|
+
----------------------------------*/
|
|
20
|
+
|
|
21
|
+
export type TAppSide = 'server' | 'client'
|
|
22
|
+
|
|
23
|
+
type TServiceSetup = {
|
|
24
|
+
id: string,
|
|
25
|
+
name: string,
|
|
26
|
+
config: {},
|
|
27
|
+
subservices: TServiceSubservices,
|
|
28
|
+
type: 'service.setup'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type TServiceRef = {
|
|
32
|
+
refTo: string,
|
|
33
|
+
type: 'service.ref'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type TServiceSubservices = {
|
|
37
|
+
[key: string]: TServiceSetup | TServiceRef
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const parseRouterPortOverride = (
|
|
41
|
+
rawPort: string | boolean | string[] | undefined
|
|
42
|
+
): number | undefined => {
|
|
43
|
+
|
|
44
|
+
if (rawPort === undefined || rawPort === '')
|
|
45
|
+
return undefined;
|
|
46
|
+
|
|
47
|
+
if (typeof rawPort !== 'string')
|
|
48
|
+
throw new Error(`Invalid value for -port: expected a numeric value.`);
|
|
49
|
+
|
|
50
|
+
const port = Number(rawPort);
|
|
51
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
52
|
+
throw new Error(`Invalid value for -port: "${rawPort}". Expected an integer between 1 and 65535.`);
|
|
53
|
+
|
|
54
|
+
return port;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/*----------------------------------
|
|
58
|
+
- SERVICE
|
|
59
|
+
----------------------------------*/
|
|
60
|
+
export class App {
|
|
61
|
+
|
|
62
|
+
// config
|
|
63
|
+
// WARNING: High level config files (env and services) shouldn't be loaded from the CLI
|
|
64
|
+
// The CLI will be run on CircleCI, and no env file should be sent to this service
|
|
65
|
+
public identity: Config.Identity;
|
|
66
|
+
|
|
67
|
+
public env: TEnvConfig;
|
|
68
|
+
|
|
69
|
+
public routerPortOverride?: number;
|
|
70
|
+
|
|
71
|
+
public packageJson: {[key: string]: any};
|
|
72
|
+
|
|
73
|
+
public buildId: number = Date.now();
|
|
74
|
+
|
|
75
|
+
public paths = {
|
|
76
|
+
|
|
77
|
+
root: cli.paths.appRoot,
|
|
78
|
+
bin: path.join( cli.paths.appRoot, 'bin'),
|
|
79
|
+
dev: path.join( cli.paths.appRoot, 'dev'),
|
|
80
|
+
data: path.join( cli.paths.appRoot, 'var', 'data'),
|
|
81
|
+
public: path.join( cli.paths.appRoot, 'public'),
|
|
82
|
+
pages: path.join( cli.paths.appRoot, 'client', 'pages'),
|
|
83
|
+
cache: path.join( cli.paths.appRoot, '.cache'),
|
|
84
|
+
|
|
85
|
+
client: {
|
|
86
|
+
generated: path.join( cli.paths.appRoot, 'client', '.generated')
|
|
87
|
+
},
|
|
88
|
+
server: {
|
|
89
|
+
generated: path.join( cli.paths.appRoot, 'server', '.generated'),
|
|
90
|
+
configs: path.join( cli.paths.appRoot, 'server', 'app')
|
|
91
|
+
},
|
|
92
|
+
common: {
|
|
93
|
+
generated: path.join( cli.paths.appRoot, 'common', '.generated')
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
withAlias: (filename: string, side: TAppSide) =>
|
|
97
|
+
this.aliases[side].apply(filename),
|
|
98
|
+
|
|
99
|
+
withoutAlias: (filename: string, side: TAppSide) =>
|
|
100
|
+
this.aliases[side].realpath(filename),
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public containerServices = [
|
|
104
|
+
//'Services',
|
|
105
|
+
'Environment',
|
|
106
|
+
'Identity',
|
|
107
|
+
/*'Application',
|
|
108
|
+
'Path',
|
|
109
|
+
'Event'*/
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
public constructor() {
|
|
113
|
+
|
|
114
|
+
cli.debug && console.log(`[cli] Loading app config ...`);
|
|
115
|
+
this.routerPortOverride = parseRouterPortOverride( cli.args.port );
|
|
116
|
+
|
|
117
|
+
const configParser = new ConfigParser(
|
|
118
|
+
cli.paths.appRoot,
|
|
119
|
+
undefined,
|
|
120
|
+
this.routerPortOverride
|
|
121
|
+
);
|
|
122
|
+
this.identity = configParser.identity();
|
|
123
|
+
this.env = configParser.env();
|
|
124
|
+
this.packageJson = this.loadPkg();
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public outputPath(target: 'dev' | 'bin') {
|
|
129
|
+
return target === 'dev'
|
|
130
|
+
? this.paths.dev
|
|
131
|
+
: this.paths.bin;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/*----------------------------------
|
|
135
|
+
- ALIAS
|
|
136
|
+
----------------------------------*/
|
|
137
|
+
|
|
138
|
+
public aliases = {
|
|
139
|
+
client: new TsAlias({
|
|
140
|
+
rootDir: this.paths.root + '/client',
|
|
141
|
+
modulesDir: [
|
|
142
|
+
cli.paths.appRoot + '/node_modules',
|
|
143
|
+
cli.paths.coreRoot + '/node_modules'
|
|
144
|
+
],
|
|
145
|
+
debug: false
|
|
146
|
+
}),
|
|
147
|
+
server: new TsAlias({
|
|
148
|
+
rootDir: this.paths.root + '/server',
|
|
149
|
+
modulesDir: [
|
|
150
|
+
cli.paths.appRoot + '/node_modules',
|
|
151
|
+
cli.paths.coreRoot + '/node_modules'
|
|
152
|
+
],
|
|
153
|
+
debug: false
|
|
154
|
+
}),
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private loadPkg() {
|
|
158
|
+
return fs.readJSONSync(this.paths.root + '/package.json');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/*----------------------------------
|
|
162
|
+
- WARMUP (Services awareness)
|
|
163
|
+
----------------------------------*/
|
|
164
|
+
|
|
165
|
+
public registered = {}
|
|
166
|
+
|
|
167
|
+
public use( referenceName: string ): TServiceRef {
|
|
168
|
+
|
|
169
|
+
// We don't check because all service are not regstered when we register subservices
|
|
170
|
+
/*if (this.registered[referenceName] === undefined) {
|
|
171
|
+
throw new Error(`Service ${referenceName} is not registered`);
|
|
172
|
+
}*/
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
refTo: referenceName,
|
|
176
|
+
type: 'service.ref'
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public setup(...args: [
|
|
181
|
+
// { user: app.setup('Core/User') }
|
|
182
|
+
servicePath: string,
|
|
183
|
+
serviceConfig?: {},
|
|
184
|
+
] | [
|
|
185
|
+
// app.setup('User', 'Core/User')
|
|
186
|
+
serviceName: string,
|
|
187
|
+
servicePath: string,
|
|
188
|
+
serviceConfig?: {},
|
|
189
|
+
]): TServiceSetup {
|
|
190
|
+
|
|
191
|
+
// Registration to app root
|
|
192
|
+
if (typeof args[1] === 'string') {
|
|
193
|
+
|
|
194
|
+
const [name, id, config] = args;
|
|
195
|
+
|
|
196
|
+
const service = { id, name, config, type: 'service.setup' } as TServiceSetup
|
|
197
|
+
|
|
198
|
+
this.registered[name] = service;
|
|
199
|
+
|
|
200
|
+
return service;
|
|
201
|
+
|
|
202
|
+
// Scoped to a parent service
|
|
203
|
+
} else {
|
|
204
|
+
|
|
205
|
+
const [id, config] = args;
|
|
206
|
+
|
|
207
|
+
const service = { id, config, type: 'service.setup' } as TServiceSetup
|
|
208
|
+
|
|
209
|
+
return service;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public async warmup() {
|
|
214
|
+
|
|
215
|
+
// Require all config files in @/server/config
|
|
216
|
+
const configDir = path.resolve(cli.paths.appRoot, 'server', 'config');
|
|
217
|
+
const configFiles = fs.readdirSync(configDir);
|
|
218
|
+
for (const configFile of configFiles) {
|
|
219
|
+
console.log("Loading config file:", configFile);
|
|
220
|
+
require( path.resolve(configDir, configFile) );
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export const app = new App
|
|
226
|
+
|
|
227
|
+
export default app
|
package/cli/bin.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
Why this exists (npm i vs npm link difference)
|
|
7
|
+
|
|
8
|
+
Proteum's CLI is written in TypeScript and is executed via ts-node at runtime.
|
|
9
|
+
When Proteum is installed from npm, `cli/tsconfig.json` lives inside `node_modules/proteum/cli`.
|
|
10
|
+
|
|
11
|
+
ts-node's default ignore pattern (`/(?:^|\\/)node_modules\\//`) is applied to *paths relative to the tsconfig folder*.
|
|
12
|
+
For hoisted deps (ex: `node_modules/tailwindcss/...`), the relative path becomes `../../tailwindcss/...` (no `node_modules/` segment),
|
|
13
|
+
so ts-node mistakenly transpiles those sibling dependencies.
|
|
14
|
+
|
|
15
|
+
Tailwind v4 contains `class ... extends Map` and downleveling that to ES5 turns `super()` into `Map.call(this)`,
|
|
16
|
+
which throws: "TypeError: Constructor Map requires 'new'".
|
|
17
|
+
|
|
18
|
+
Fix: extend ts-node ignore patterns so it also ignores `../../<pkg>/...` (hoisted siblings), while still allowing the CLI
|
|
19
|
+
to `require()` the user's app config (ex: `../../../server/config/*.ts`).
|
|
20
|
+
*/
|
|
21
|
+
if (!process.env.TS_NODE_IGNORE) {
|
|
22
|
+
process.env.TS_NODE_IGNORE = [
|
|
23
|
+
// Default ts-node ignore rule (works when deps are nested under `../node_modules/...`)
|
|
24
|
+
'(node_modules\/(?!proteum\/))|(\.generated\/)|(\.cache\/)',
|
|
25
|
+
// Extra rule for deps hoisted next to Proteum (ex: `../../tailwindcss/...`)
|
|
26
|
+
'^\\.\\./\\.\\./(?!\\./|\\.\\./)[^/]+/'
|
|
27
|
+
].join(',');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
process.env.TS_NODE_PROJECT = path.join(__dirname, 'tsconfig.json');
|
|
31
|
+
process.env.TS_NODE_TRANSPILE_ONLY = '1';
|
|
32
|
+
|
|
33
|
+
require('ts-node/register/transpile-only');
|
|
34
|
+
|
|
35
|
+
require('./index.ts');
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// Core
|
|
6
|
+
import cli from '..';
|
|
7
|
+
|
|
8
|
+
// Configs
|
|
9
|
+
import Compiler from '../compiler';
|
|
10
|
+
import type { TCompileMode } from '../compiler/common';
|
|
11
|
+
|
|
12
|
+
const allowedBuildArgs = new Set(['dev', 'prod', 'analyze', 'cache']);
|
|
13
|
+
|
|
14
|
+
/*----------------------------------
|
|
15
|
+
- COMMAND
|
|
16
|
+
----------------------------------*/
|
|
17
|
+
function resolveBuildMode(): TCompileMode {
|
|
18
|
+
|
|
19
|
+
const enabledArgs = Object.entries(cli.args)
|
|
20
|
+
.filter(([name, value]) => name !== 'workdir' && value === true)
|
|
21
|
+
.map(([name]) => name);
|
|
22
|
+
|
|
23
|
+
const invalidArgs = enabledArgs.filter(arg => !allowedBuildArgs.has(arg));
|
|
24
|
+
if (invalidArgs.length > 0)
|
|
25
|
+
throw new Error(`Unknown build argument(s): ${invalidArgs.join(', ')}. Allowed values: dev, prod, analyze, cache.`);
|
|
26
|
+
|
|
27
|
+
const requestedModes = enabledArgs.filter((arg): arg is TCompileMode =>
|
|
28
|
+
arg === 'dev' || arg === 'prod'
|
|
29
|
+
);
|
|
30
|
+
if (requestedModes.length > 1)
|
|
31
|
+
throw new Error(`Please specify only one build mode. Received: ${requestedModes.join(', ')}.`);
|
|
32
|
+
|
|
33
|
+
return requestedModes[0] ?? 'dev';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const run = async (): Promise<void> => {
|
|
37
|
+
|
|
38
|
+
const mode = resolveBuildMode();
|
|
39
|
+
const compiler = new Compiler(mode, {}, false, 'bin');
|
|
40
|
+
const multiCompiler = await compiler.create();
|
|
41
|
+
|
|
42
|
+
await new Promise<void>((resolve, reject) => {
|
|
43
|
+
multiCompiler.run((error, stats) => {
|
|
44
|
+
|
|
45
|
+
if (error) {
|
|
46
|
+
console.error("An error occurred during the compilation:", error);
|
|
47
|
+
reject(error);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (stats?.hasErrors()) {
|
|
52
|
+
reject(new Error(`Compilation failed for build mode "${mode}".`));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
resolve();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
});
|
|
60
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// Npm
|
|
6
|
+
import fs from 'fs-extra';
|
|
7
|
+
|
|
8
|
+
// Core
|
|
9
|
+
import cli from '../..';
|
|
10
|
+
import { api } from '../../utils';
|
|
11
|
+
|
|
12
|
+
/*----------------------------------
|
|
13
|
+
- COMMAND
|
|
14
|
+
----------------------------------*/
|
|
15
|
+
export async function run() {
|
|
16
|
+
|
|
17
|
+
const { project, local } = cli.args;
|
|
18
|
+
|
|
19
|
+
const versionfile = fs.readFileSync( project + '/version.txt', 'utf-8' );
|
|
20
|
+
|
|
21
|
+
const [platform, version, build] = versionfile.split('\n');
|
|
22
|
+
|
|
23
|
+
console.log({ project, platform, version, build });
|
|
24
|
+
|
|
25
|
+
await cli.shell(
|
|
26
|
+
api('POST', '/app/release', { platform, version, build }, local)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// Npm
|
|
6
|
+
import fs from 'fs-extra';
|
|
7
|
+
import prompts from 'prompts';
|
|
8
|
+
|
|
9
|
+
// Core
|
|
10
|
+
import cli from '../..';
|
|
11
|
+
import { api } from '../../utils';
|
|
12
|
+
|
|
13
|
+
0/*----------------------------------
|
|
14
|
+
- HELPERS
|
|
15
|
+
----------------------------------*/
|
|
16
|
+
|
|
17
|
+
const mergeDeps = ({ dependencies: coreDeps }, { dependencies: appDeps }) => {
|
|
18
|
+
for (const dep in appDeps)
|
|
19
|
+
if (dep in coreDeps) {
|
|
20
|
+
|
|
21
|
+
if (coreDeps[dep] !== appDeps[dep])
|
|
22
|
+
throw new Error(`Duplicate dependency "${dep}" with different version in core (${coreDeps[dep]}) and app (${appDeps[dep]})`);
|
|
23
|
+
else
|
|
24
|
+
console.warn(`Duplicate dependency "${dep}" in core and app`);
|
|
25
|
+
|
|
26
|
+
} else
|
|
27
|
+
coreDeps[dep] = appDeps[dep];
|
|
28
|
+
return coreDeps;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const toast = (type: string, title: string, content: string) =>
|
|
32
|
+
api('POST', '/admin/api/notification', { type, title, content }, true)
|
|
33
|
+
|
|
34
|
+
/*----------------------------------
|
|
35
|
+
- COMMAND
|
|
36
|
+
----------------------------------*/
|
|
37
|
+
export async function run() {
|
|
38
|
+
|
|
39
|
+
const { simulate } = cli.args;
|
|
40
|
+
|
|
41
|
+
const temp = app.paths.root + '/.deployment';
|
|
42
|
+
fs.emptyDirSync(temp);
|
|
43
|
+
|
|
44
|
+
// Merge package.json: framework + app
|
|
45
|
+
fs.outputJSONSync(temp + '/package.json', {
|
|
46
|
+
...appPkg,
|
|
47
|
+
dependencies: mergeDeps(cli.packageJson, appPkg),
|
|
48
|
+
devDependencies: {}
|
|
49
|
+
}, { spaces: 4 });
|
|
50
|
+
|
|
51
|
+
// Copy config file
|
|
52
|
+
fs.copyFileSync( app.paths.root + (simulate ? '/env.yaml' : '/env.server.yaml'), temp + '/env.yaml' );
|
|
53
|
+
|
|
54
|
+
// Compile & Run Docker
|
|
55
|
+
await cli.shell(`docker compose up --build`);
|
|
56
|
+
toast("info", "Server update", "A server update will start. You might experience some temporary slowdowns.")
|
|
57
|
+
|
|
58
|
+
fs.removeSync(temp);
|
|
59
|
+
|
|
60
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// Npm
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { spawn, ChildProcess } from 'child_process';
|
|
8
|
+
|
|
9
|
+
// Cor elibs
|
|
10
|
+
import cli from '..';
|
|
11
|
+
import Keyboard from '../utils/keyboard';
|
|
12
|
+
|
|
13
|
+
// Configs
|
|
14
|
+
import Compiler from '../compiler';
|
|
15
|
+
|
|
16
|
+
// Core
|
|
17
|
+
import { app, App } from '../app';
|
|
18
|
+
|
|
19
|
+
const ignoredWatchPathPatterns = /(node_modules\/(?!proteum\/))|(\.generated\/)|(\.cache\/)/;
|
|
20
|
+
|
|
21
|
+
/*----------------------------------
|
|
22
|
+
- COMMANDE
|
|
23
|
+
----------------------------------*/
|
|
24
|
+
export const run = () => new Promise<void>(async () => {
|
|
25
|
+
|
|
26
|
+
const compiler = new Compiler('dev', {
|
|
27
|
+
before: (compiler) => {
|
|
28
|
+
|
|
29
|
+
const changedFilesList = compiler.modifiedFiles ? [...compiler.modifiedFiles] : [];
|
|
30
|
+
|
|
31
|
+
if (changedFilesList.length === 0)
|
|
32
|
+
stopApp("Starting a new compilation");
|
|
33
|
+
else
|
|
34
|
+
stopApp("Need to recompile because files changed:\n" + changedFilesList.join('\n'));
|
|
35
|
+
|
|
36
|
+
},
|
|
37
|
+
after: () => {
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const multiCompiler = await compiler.create();
|
|
44
|
+
const ignoredOutputPaths = [app.paths.bin, app.paths.dev].map(normalizeWatchPath);
|
|
45
|
+
|
|
46
|
+
multiCompiler.watch({
|
|
47
|
+
|
|
48
|
+
// https://webpack.js.org/configuration/watch/#watchoptions
|
|
49
|
+
// Watching may not work with NFS and machines in VirtualBox
|
|
50
|
+
// Uncomment next line if it is your case (use true or interval in milliseconds)
|
|
51
|
+
//poll: 1000,
|
|
52
|
+
|
|
53
|
+
// Decrease CPU or memory usage in some file systems
|
|
54
|
+
// Ignore updated from:
|
|
55
|
+
// - Node modules except 5HTP core (framework dev mode)
|
|
56
|
+
// - Generated files during runtime (cause infinite loop. Ex: models.d.ts)
|
|
57
|
+
// - Webpack output folders (`./dev`, legacy `./bin`)
|
|
58
|
+
ignored: (watchPath: string) => {
|
|
59
|
+
const normalizedPath = normalizeWatchPath(watchPath);
|
|
60
|
+
return ignoredWatchPathPatterns.test(normalizedPath)
|
|
61
|
+
|| ignoredOutputPaths.some(outputPath =>
|
|
62
|
+
normalizedPath === outputPath
|
|
63
|
+
|| normalizedPath.startsWith(outputPath + '/')
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//aggregateTimeout: 1000,
|
|
68
|
+
}, async (error, stats) => {
|
|
69
|
+
|
|
70
|
+
if (error) {
|
|
71
|
+
console.error(`Error in milticompiler.watch`, error, stats?.toString());
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.log("Watch callback. Reloading app ...");
|
|
76
|
+
startApp(app);
|
|
77
|
+
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
Keyboard.input('ctrl+r', async () => {
|
|
81
|
+
|
|
82
|
+
console.log(`Waiting for compilers to be ready ...`, Object.keys(compiler.compiling));
|
|
83
|
+
await Promise.all(Object.values(compiler.compiling));
|
|
84
|
+
|
|
85
|
+
console.log(`Reloading app ...`);
|
|
86
|
+
startApp(app);
|
|
87
|
+
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
Keyboard.input('ctrl+c', () => {
|
|
91
|
+
stopApp("CTRL+C Pressed");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
/*----------------------------------
|
|
97
|
+
- APP RUN
|
|
98
|
+
----------------------------------*/
|
|
99
|
+
let cp: ChildProcess | undefined = undefined;
|
|
100
|
+
|
|
101
|
+
async function startApp( app: App ) {
|
|
102
|
+
|
|
103
|
+
stopApp('Restart asked');
|
|
104
|
+
|
|
105
|
+
console.info(`Launching new server ...`);
|
|
106
|
+
cp = spawn('node', ['' + app.outputPath('dev') + '/server.js', '--preserve-symlinks'], {
|
|
107
|
+
|
|
108
|
+
// sdin, sdout, sderr
|
|
109
|
+
stdio: ['inherit', 'inherit', 'inherit']
|
|
110
|
+
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function stopApp( reason: string ) {
|
|
115
|
+
if (cp !== undefined) {
|
|
116
|
+
console.info(`Killing current server instance (ID: ${cp.pid}) for the following reason:`, reason);
|
|
117
|
+
cp.kill();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function normalizeWatchPath(watchPath: string) {
|
|
123
|
+
return path.resolve(watchPath).replace(/\\/g, '/').replace(/\/$/, '');
|
|
124
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// Npm
|
|
6
|
+
import fs from 'fs-extra';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import prompts from 'prompts';
|
|
9
|
+
import cmd from 'node-cmd';
|
|
10
|
+
import replaceOnce from 'replace-once';
|
|
11
|
+
|
|
12
|
+
// Cor elibs
|
|
13
|
+
import cli from '..';
|
|
14
|
+
|
|
15
|
+
// Configs
|
|
16
|
+
const filesToConfig = [
|
|
17
|
+
'package.json',
|
|
18
|
+
'identity.yaml'
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
/*----------------------------------
|
|
22
|
+
- COMMANDE
|
|
23
|
+
----------------------------------*/
|
|
24
|
+
export const run = () => new Promise<void>(async () => {
|
|
25
|
+
|
|
26
|
+
const config = await prompts([{
|
|
27
|
+
type: 'text', name: 'name',
|
|
28
|
+
message: 'Project name ?',
|
|
29
|
+
initial: "MyProject",
|
|
30
|
+
validate: value => /[a-z0-9\-\.]/i.test(value) || "Must only include alphanumeric characters, and - . "
|
|
31
|
+
},{
|
|
32
|
+
type: 'text', name: 'dirname',
|
|
33
|
+
message: 'Folder name ?',
|
|
34
|
+
initial: value => value.toLowerCase(),
|
|
35
|
+
validate: value => /[a-z0-9\-\.]/.test(value) || "Must only include lowercase alphanumeric characters, and - . "
|
|
36
|
+
},{
|
|
37
|
+
type: 'text', name: 'description',
|
|
38
|
+
message: 'Briefly describe your project to your mom:',
|
|
39
|
+
initial: "It will revolutionnize the world",
|
|
40
|
+
validate: value => /[a-z0-9\-\. ]/i.test(value) || "Must only include alphanumeric characters, and - . "
|
|
41
|
+
},{
|
|
42
|
+
type: 'toggle', name: 'microservice',
|
|
43
|
+
message: 'Separate API from the UI servers ?'
|
|
44
|
+
}]);
|
|
45
|
+
|
|
46
|
+
const placeholders = {
|
|
47
|
+
PROJECT_NAME: config.name,
|
|
48
|
+
PACKAGE_NAME: config.name.toLowerCase(),
|
|
49
|
+
PROJECT_DESCRIPTION: config.description
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const paths = {
|
|
53
|
+
skeleton: path.join( cli.paths.core.cli, 'skeleton'),
|
|
54
|
+
project: path.join( process.cwd(), config.dirname)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Copy skeleton to cwd/<project-name>
|
|
58
|
+
console.info("Creating project skeleton ...");
|
|
59
|
+
fs.copySync( paths.skeleton, paths.project );
|
|
60
|
+
|
|
61
|
+
// Replace placeholders
|
|
62
|
+
console.info("Configuring project ...");
|
|
63
|
+
for (const file of filesToConfig) {
|
|
64
|
+
console.log('- ' + file);
|
|
65
|
+
|
|
66
|
+
const filepath = path.join( paths.project, file )
|
|
67
|
+
const content = fs.readFileSync(filepath, 'utf-8');
|
|
68
|
+
|
|
69
|
+
const placeholders_keys = Object.keys(placeholders).map(k => '{{ ' + k + ' }}')
|
|
70
|
+
const values = Object.values(placeholders);
|
|
71
|
+
|
|
72
|
+
fs.writeFileSync(filepath,
|
|
73
|
+
replaceOnce(content, placeholders_keys, values)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Npm install
|
|
78
|
+
console.info("Installing packages ...");
|
|
79
|
+
cmd.runSync(`cd "${paths.project}" && npm i`);
|
|
80
|
+
|
|
81
|
+
// Run demo app
|
|
82
|
+
/*console.info("Run demo ...");
|
|
83
|
+
await cli.shell('5htp dev');*/
|
|
84
|
+
|
|
85
|
+
});
|