proteum 1.0.0-1

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.
Files changed (156) hide show
  1. package/.dockerignore +10 -0
  2. package/Rte.zip +0 -0
  3. package/cli/app/config.ts +54 -0
  4. package/cli/app/index.ts +195 -0
  5. package/cli/bin.js +11 -0
  6. package/cli/commands/build.ts +34 -0
  7. package/cli/commands/deploy/app.ts +29 -0
  8. package/cli/commands/deploy/web.ts +60 -0
  9. package/cli/commands/dev.ts +109 -0
  10. package/cli/commands/init.ts +85 -0
  11. package/cli/compiler/client/identite.ts +72 -0
  12. package/cli/compiler/client/index.ts +334 -0
  13. package/cli/compiler/common/babel/index.ts +170 -0
  14. package/cli/compiler/common/babel/plugins/index.ts +0 -0
  15. package/cli/compiler/common/babel/plugins/services.ts +579 -0
  16. package/cli/compiler/common/babel/routes/imports.ts +127 -0
  17. package/cli/compiler/common/babel/routes/routes.ts +1130 -0
  18. package/cli/compiler/common/files/autres.ts +39 -0
  19. package/cli/compiler/common/files/images.ts +35 -0
  20. package/cli/compiler/common/files/style.ts +78 -0
  21. package/cli/compiler/common/index.ts +154 -0
  22. package/cli/compiler/index.ts +532 -0
  23. package/cli/compiler/server/index.ts +211 -0
  24. package/cli/index.ts +189 -0
  25. package/cli/paths.ts +165 -0
  26. package/cli/print.ts +12 -0
  27. package/cli/tsconfig.json +38 -0
  28. package/cli/utils/index.ts +22 -0
  29. package/cli/utils/keyboard.ts +78 -0
  30. package/client/app/component.tsx +54 -0
  31. package/client/app/index.ts +142 -0
  32. package/client/app/service.ts +34 -0
  33. package/client/app.tsconfig.json +28 -0
  34. package/client/components/Button.tsx +298 -0
  35. package/client/components/Dialog/Manager.tsx +309 -0
  36. package/client/components/Dialog/card.tsx +208 -0
  37. package/client/components/Dialog/index.less +151 -0
  38. package/client/components/Dialog/status.less +176 -0
  39. package/client/components/Dialog/status.tsx +48 -0
  40. package/client/components/index.ts +2 -0
  41. package/client/components/types.d.ts +3 -0
  42. package/client/data/input.ts +32 -0
  43. package/client/global.d.ts +5 -0
  44. package/client/hooks.ts +22 -0
  45. package/client/index.ts +6 -0
  46. package/client/pages/_layout/index.less +6 -0
  47. package/client/pages/_layout/index.tsx +43 -0
  48. package/client/pages/bug.tsx.old +60 -0
  49. package/client/pages/useHeader.tsx +50 -0
  50. package/client/services/captcha/index.ts +67 -0
  51. package/client/services/router/components/Link.tsx +46 -0
  52. package/client/services/router/components/Page.tsx +55 -0
  53. package/client/services/router/components/router.tsx +218 -0
  54. package/client/services/router/index.tsx +521 -0
  55. package/client/services/router/request/api.ts +267 -0
  56. package/client/services/router/request/history.ts +5 -0
  57. package/client/services/router/request/index.ts +53 -0
  58. package/client/services/router/request/multipart.ts +147 -0
  59. package/client/services/router/response/index.tsx +128 -0
  60. package/client/services/router/response/page.ts +86 -0
  61. package/client/services/socket/index.ts +147 -0
  62. package/client/utils/dom.ts +77 -0
  63. package/common/app/index.ts +9 -0
  64. package/common/data/chaines/index.ts +54 -0
  65. package/common/data/dates.ts +179 -0
  66. package/common/data/markdown.ts +73 -0
  67. package/common/data/rte/nodes.ts +83 -0
  68. package/common/data/stats.ts +90 -0
  69. package/common/errors/index.tsx +326 -0
  70. package/common/router/index.ts +213 -0
  71. package/common/router/layouts.ts +93 -0
  72. package/common/router/register.ts +55 -0
  73. package/common/router/request/api.ts +77 -0
  74. package/common/router/request/index.ts +35 -0
  75. package/common/router/response/index.ts +45 -0
  76. package/common/router/response/page.ts +128 -0
  77. package/common/utils/rte.ts +183 -0
  78. package/common/utils.ts +7 -0
  79. package/doc/TODO.md +71 -0
  80. package/doc/front/router.md +27 -0
  81. package/doc/workspace/workspace.png +0 -0
  82. package/doc/workspace/workspace2.png +0 -0
  83. package/doc/workspace/workspace_26.01.22.png +0 -0
  84. package/package.json +171 -0
  85. package/server/app/commands.ts +141 -0
  86. package/server/app/container/config.ts +203 -0
  87. package/server/app/container/console/index.ts +550 -0
  88. package/server/app/container/index.ts +137 -0
  89. package/server/app/index.ts +273 -0
  90. package/server/app/service/container.ts +88 -0
  91. package/server/app/service/index.ts +235 -0
  92. package/server/app.tsconfig.json +28 -0
  93. package/server/context.ts +4 -0
  94. package/server/index.ts +4 -0
  95. package/server/services/auth/index.ts +250 -0
  96. package/server/services/auth/old.ts +277 -0
  97. package/server/services/auth/router/index.ts +95 -0
  98. package/server/services/auth/router/request.ts +54 -0
  99. package/server/services/auth/router/service.json +6 -0
  100. package/server/services/auth/service.json +6 -0
  101. package/server/services/cache/commands.ts +41 -0
  102. package/server/services/cache/index.ts +297 -0
  103. package/server/services/cache/service.json +6 -0
  104. package/server/services/cron/CronTask.ts +86 -0
  105. package/server/services/cron/index.ts +112 -0
  106. package/server/services/cron/service.json +6 -0
  107. package/server/services/disks/driver.ts +103 -0
  108. package/server/services/disks/drivers/local/index.ts +188 -0
  109. package/server/services/disks/drivers/local/service.json +6 -0
  110. package/server/services/disks/drivers/s3/index.ts +301 -0
  111. package/server/services/disks/drivers/s3/service.json +6 -0
  112. package/server/services/disks/index.ts +90 -0
  113. package/server/services/disks/service.json +6 -0
  114. package/server/services/email/index.ts +188 -0
  115. package/server/services/email/utils.ts +53 -0
  116. package/server/services/fetch/index.ts +201 -0
  117. package/server/services/fetch/service.json +7 -0
  118. package/server/services/models.7z +0 -0
  119. package/server/services/prisma/Facet.ts +142 -0
  120. package/server/services/prisma/index.ts +201 -0
  121. package/server/services/prisma/service.json +6 -0
  122. package/server/services/router/http/index.ts +217 -0
  123. package/server/services/router/http/multipart.ts +102 -0
  124. package/server/services/router/http/session.ts.old +40 -0
  125. package/server/services/router/index.ts +801 -0
  126. package/server/services/router/request/api.ts +87 -0
  127. package/server/services/router/request/index.ts +184 -0
  128. package/server/services/router/request/service.ts +21 -0
  129. package/server/services/router/request/validation/zod.ts +180 -0
  130. package/server/services/router/response/index.ts +338 -0
  131. package/server/services/router/response/mask/Filter.ts +323 -0
  132. package/server/services/router/response/mask/index.ts +60 -0
  133. package/server/services/router/response/mask/selecteurs.ts +92 -0
  134. package/server/services/router/response/page/document.tsx +160 -0
  135. package/server/services/router/response/page/index.tsx +196 -0
  136. package/server/services/router/service.json +6 -0
  137. package/server/services/router/service.ts +36 -0
  138. package/server/services/schema/index.ts +44 -0
  139. package/server/services/schema/request.ts +49 -0
  140. package/server/services/schema/router/index.ts +28 -0
  141. package/server/services/schema/router/service.json +6 -0
  142. package/server/services/schema/service.json +6 -0
  143. package/server/services/security/encrypt/aes/index.ts +85 -0
  144. package/server/services/security/encrypt/aes/service.json +6 -0
  145. package/server/services/socket/index.ts +162 -0
  146. package/server/services/socket/scope.ts +226 -0
  147. package/server/services/socket/service.json +6 -0
  148. package/server/services_old/SocketClient.ts +92 -0
  149. package/server/services_old/Token.old.ts +97 -0
  150. package/server/utils/slug.ts +79 -0
  151. package/tsconfig.common.json +45 -0
  152. package/tsconfig.json +3 -0
  153. package/types/aliases.d.ts +54 -0
  154. package/types/global/modules.d.ts +49 -0
  155. package/types/global/utils.d.ts +103 -0
  156. package/types/icons.d.ts +1 -0
package/.dockerignore ADDED
@@ -0,0 +1,10 @@
1
+ # NodeJS
2
+ node_modules
3
+ package-lock.json
4
+
5
+ # Config files
6
+ .git
7
+ .vscode
8
+ Dockerfile
9
+ .dockerignore
10
+ .gitignore
package/Rte.zip ADDED
Binary file
@@ -0,0 +1,54 @@
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
+ ) {
29
+
30
+ }
31
+
32
+ private loadYaml( filepath: string ) {
33
+ console.info(`Loading config ${filepath}`);
34
+ const rawConfig = fs.readFileSync(filepath, 'utf-8');
35
+ return yaml.parse(rawConfig);
36
+ }
37
+
38
+ public env(): TEnvConfig {
39
+ // We assume that when we run 5htp dev, we're in local
40
+ // Otherwise, we're in production environment (docker)
41
+ console.log("[app] Using environment:", process.env.NODE_ENV);
42
+ const envFileName = this.appDir + '/env.yaml';
43
+ const envFile = this.loadYaml( envFileName );
44
+ return {
45
+ ...envFile,
46
+ version: 'CLI'
47
+ }
48
+ }
49
+
50
+ public identity() {
51
+ const identityFile = this.appDir + '/identity.yaml';
52
+ return this.loadYaml( identityFile );
53
+ }
54
+ }
@@ -0,0 +1,195 @@
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
+ /*----------------------------------
41
+ - SERVICE
42
+ ----------------------------------*/
43
+ export class App {
44
+
45
+ // config
46
+ // WARNING: High level config files (env and services) shouldn't be loaded from the CLI
47
+ // The CLI will be run on CircleCI, and no env file should be sent to this service
48
+ public identity: Config.Identity;
49
+
50
+ public env: TEnvConfig;
51
+
52
+ public packageJson: {[key: string]: any};
53
+
54
+ public buildId: number = Date.now();
55
+
56
+ public paths = {
57
+
58
+ root: cli.paths.appRoot,
59
+ bin: path.join( cli.paths.appRoot, 'bin'),
60
+ data: path.join( cli.paths.appRoot, 'var', 'data'),
61
+ public: path.join( cli.paths.appRoot, 'public'),
62
+ pages: path.join( cli.paths.appRoot, 'client', 'pages'),
63
+ cache: path.join( cli.paths.appRoot, '.cache'),
64
+
65
+ client: {
66
+ generated: path.join( cli.paths.appRoot, 'client', '.generated')
67
+ },
68
+ server: {
69
+ generated: path.join( cli.paths.appRoot, 'server', '.generated'),
70
+ configs: path.join( cli.paths.appRoot, 'server', 'app')
71
+ },
72
+ common: {
73
+ generated: path.join( cli.paths.appRoot, 'common', '.generated')
74
+ },
75
+
76
+ withAlias: (filename: string, side: TAppSide) =>
77
+ this.aliases[side].apply(filename),
78
+
79
+ withoutAlias: (filename: string, side: TAppSide) =>
80
+ this.aliases[side].realpath(filename),
81
+ }
82
+
83
+ public containerServices = [
84
+ //'Services',
85
+ 'Environment',
86
+ 'Identity',
87
+ /*'Application',
88
+ 'Path',
89
+ 'Event'*/
90
+ ]
91
+
92
+ public constructor() {
93
+
94
+ cli.debug && console.log(`[cli] Loading app config ...`);
95
+ const configParser = new ConfigParser( cli.paths.appRoot );
96
+ this.identity = configParser.identity();
97
+ this.env = configParser.env();
98
+ this.packageJson = this.loadPkg();
99
+
100
+ }
101
+
102
+ /*----------------------------------
103
+ - ALIAS
104
+ ----------------------------------*/
105
+
106
+ public aliases = {
107
+ client: new TsAlias({
108
+ rootDir: this.paths.root + '/client',
109
+ modulesDir: [
110
+ cli.paths.appRoot + '/node_modules',
111
+ cli.paths.coreRoot + '/node_modules'
112
+ ],
113
+ debug: false
114
+ }),
115
+ server: new TsAlias({
116
+ rootDir: this.paths.root + '/server',
117
+ modulesDir: [
118
+ cli.paths.appRoot + '/node_modules',
119
+ cli.paths.coreRoot + '/node_modules'
120
+ ],
121
+ debug: false
122
+ }),
123
+ }
124
+
125
+ private loadPkg() {
126
+ return fs.readJSONSync(this.paths.root + '/package.json');
127
+ }
128
+
129
+ /*----------------------------------
130
+ - WARMUP (Services awareness)
131
+ ----------------------------------*/
132
+
133
+ public registered = {}
134
+
135
+ public use( referenceName: string ): TServiceRef {
136
+
137
+ // We don't check because all service are not regstered when we register subservices
138
+ /*if (this.registered[referenceName] === undefined) {
139
+ throw new Error(`Service ${referenceName} is not registered`);
140
+ }*/
141
+
142
+ return {
143
+ refTo: referenceName,
144
+ type: 'service.ref'
145
+ }
146
+ }
147
+
148
+ public setup(...args: [
149
+ // { user: app.setup('Core/User') }
150
+ servicePath: string,
151
+ serviceConfig?: {},
152
+ ] | [
153
+ // app.setup('User', 'Core/User')
154
+ serviceName: string,
155
+ servicePath: string,
156
+ serviceConfig?: {},
157
+ ]): TServiceSetup {
158
+
159
+ // Registration to app root
160
+ if (typeof args[1] === 'string') {
161
+
162
+ const [name, id, config] = args;
163
+
164
+ const service = { id, name, config, type: 'service.setup' } as TServiceSetup
165
+
166
+ this.registered[name] = service;
167
+
168
+ return service;
169
+
170
+ // Scoped to a parent service
171
+ } else {
172
+
173
+ const [id, config] = args;
174
+
175
+ const service = { id, config, type: 'service.setup' } as TServiceSetup
176
+
177
+ return service;
178
+ }
179
+ }
180
+
181
+ public async warmup() {
182
+
183
+ // Require all config files in @/server/config
184
+ const configDir = path.resolve(cli.paths.appRoot, 'server', 'config');
185
+ const configFiles = fs.readdirSync(configDir);
186
+ for (const configFile of configFiles) {
187
+ console.log("Loading config file:", configFile);
188
+ require( path.resolve(configDir, configFile) );
189
+ }
190
+ }
191
+ }
192
+
193
+ export const app = new App
194
+
195
+ export default app
package/cli/bin.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require('path');
4
+
5
+ process.env.TS_NODE_PROJECT = path.join(__dirname, 'tsconfig.json');
6
+ process.env.TS_NODE_TRANSPILE_ONLY = '1';
7
+
8
+ require('ts-node/register/transpile-only');
9
+
10
+ require('./index.ts');
11
+
@@ -0,0 +1,34 @@
1
+ /*----------------------------------
2
+ - DEPENDANCES
3
+ ----------------------------------*/
4
+
5
+ // Npm
6
+ import prompts from 'prompts';
7
+
8
+ // Configs
9
+ import Compiler from '../compiler';
10
+
11
+ /*----------------------------------
12
+ - TYPES
13
+ ----------------------------------*/
14
+
15
+ /*----------------------------------
16
+ - COMMAND
17
+ ----------------------------------*/
18
+ export const run = (): Promise<void> => new Promise(async (resolve) => {
19
+
20
+ const compiler = new Compiler('prod');
21
+
22
+ const multiCompiler = await compiler.create();
23
+
24
+ multiCompiler.run((error, stats) => {
25
+
26
+ if (error) {
27
+ console.error("An error occurred during the compilation:", error);
28
+ throw error;
29
+ }
30
+
31
+ //resolve();
32
+
33
+ });
34
+ });
@@ -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,109 @@
1
+ /*----------------------------------
2
+ - DEPENDANCES
3
+ ----------------------------------*/
4
+
5
+ // Npm
6
+ import fs from 'fs-extra';
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
+ /*----------------------------------
20
+ - COMMANDE
21
+ ----------------------------------*/
22
+ export const run = () => new Promise<void>(async () => {
23
+
24
+ const compiler = new Compiler('dev', {
25
+ before: (compiler) => {
26
+
27
+ const changedFilesList = compiler.modifiedFiles ? [...compiler.modifiedFiles] : [];
28
+
29
+ if (changedFilesList.length === 0)
30
+ stopApp("Starting a new compilation");
31
+ else
32
+ stopApp("Need to recompile because files changed:\n" + changedFilesList.join('\n'));
33
+
34
+ },
35
+ after: () => {
36
+
37
+
38
+ }
39
+ });
40
+
41
+ const multiCompiler = await compiler.create();
42
+
43
+ multiCompiler.watch({
44
+
45
+ // https://webpack.js.org/configuration/watch/#watchoptions
46
+ // Watching may not work with NFS and machines in VirtualBox
47
+ // Uncomment next line if it is your case (use true or interval in milliseconds)
48
+ poll: 1000,
49
+
50
+ // Decrease CPU or memory usage in some file systems
51
+ // Ignore updated from:
52
+ // - Node modules except 5HTP core (framework dev mode)
53
+ // - Generated files during runtime (cause infinite loop. Ex: models.d.ts)
54
+ ignored: /(node_modules\/(?!proteum\/))|(\.generated\/)/
55
+
56
+ //aggregateTimeout: 1000,
57
+ }, async (error, stats) => {
58
+
59
+ if (error) {
60
+ console.error(`Error in milticompiler.watch`, error, stats?.toString());
61
+ return;
62
+ }
63
+
64
+ console.log("Watch callback. Reloading app ...");
65
+ startApp(app);
66
+
67
+ });
68
+
69
+ Keyboard.input('ctrl+r', async () => {
70
+
71
+ console.log(`Waiting for compilers to be ready ...`, Object.keys(compiler.compiling));
72
+ await Promise.all(Object.values(compiler.compiling));
73
+
74
+ console.log(`Reloading app ...`);
75
+ startApp(app);
76
+
77
+ });
78
+
79
+ Keyboard.input('ctrl+c', () => {
80
+ stopApp("CTRL+C Pressed");
81
+ });
82
+ });
83
+
84
+
85
+ /*----------------------------------
86
+ - APP RUN
87
+ ----------------------------------*/
88
+ let cp: ChildProcess | undefined = undefined;
89
+
90
+ async function startApp( app: App ) {
91
+
92
+ stopApp('Restart asked');
93
+
94
+ console.info(`Launching new server ...`);
95
+ cp = spawn('node', ['' + app.paths.bin + '/server.js', '--preserve-symlinks'], {
96
+
97
+ // sdin, sdout, sderr
98
+ stdio: ['inherit', 'inherit', 'inherit']
99
+
100
+ });
101
+ }
102
+
103
+ function stopApp( reason: string ) {
104
+ if (cp !== undefined) {
105
+ console.info(`Killing current server instance (ID: ${cp.pid}) for the following reason:`, reason);
106
+ cp.kill();
107
+ }
108
+
109
+ }
@@ -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
+ });
@@ -0,0 +1,72 @@
1
+ // Npm
2
+ import favicons from 'favicons';
3
+ import fs from 'fs-extra';
4
+
5
+ // Libs
6
+ import cli from '../..';
7
+
8
+ // Type
9
+ import type App from '../../app';
10
+
11
+ export default async ( app: App ) => {
12
+
13
+ const dossierCache = app.paths.root + '/public/app';
14
+
15
+ if (!fs.existsSync(dossierCache)) {
16
+
17
+ console.info(`Generating identity assets ...`);
18
+ fs.emptyDirSync(dossierCache);
19
+
20
+ const identity = app.identity;
21
+
22
+ const response = await favicons( app.paths.root + '/client/assets/identity/logo.svg', {
23
+
24
+ path: '/assets/img/identite/favicons/',
25
+ appName: identity.name,
26
+ appShortName: identity.name,
27
+ appDescription: identity.description,
28
+ developerName: identity.author.name,
29
+ developerURL: identity.author.url,
30
+ dir: "auto",
31
+ lang: identity.language,
32
+ background: "#fff",
33
+ theme_color: identity.maincolor,
34
+ appleStatusBarStyle: "default",
35
+ display: "standalone",
36
+ orientation: "any",
37
+ //scope: "/",
38
+ start_url: "/",
39
+ version: identity.web.version,
40
+ logging: false,
41
+ pixel_art: false,
42
+ icons: {
43
+ android: true,
44
+ appleIcon: true,
45
+ appleStartup: false,
46
+ coast: false,
47
+ favicons: true,
48
+ firefox: true,
49
+ windows: true,
50
+ yandex: false
51
+ }
52
+
53
+ });
54
+
55
+ await Promise.all([
56
+
57
+ // Enregistrement images
58
+ ...response.images.map((image) => {
59
+ let destimg = dossierCache + '/' + image.name;
60
+ return fs.writeFile(destimg, image.contents);
61
+ }),
62
+
63
+ // Enregistrement fichiers
64
+ ...response.files.map((fichier) => {
65
+ let destfichier = dossierCache + '/' + fichier.name;
66
+ return fs.writeFile(destfichier, fichier.contents);
67
+ })
68
+
69
+ ]);
70
+ }
71
+
72
+ }