5htp 0.3.0 → 0.3.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "5htp",
3
3
  "description": "Convenient TypeScript framework designed for Performance and Productivity.",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp.git",
7
7
  "license": "MIT",
@@ -41,6 +41,7 @@
41
41
  "@types/webpack-env": "^1.16.2",
42
42
  "@types/ws": "^7.4.7",
43
43
  "babel-loader": "^8.2.2",
44
+ "babel-plugin-glob-import": "^0.0.7",
44
45
  "babel-plugin-transform-imports": "^2.0.0",
45
46
  "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
46
47
  "brotli-webpack-plugin": "^1.1.0",
@@ -87,7 +88,6 @@
87
88
  "@types/node": "^16.9.1",
88
89
  "@types/nodemailer": "^6.4.4",
89
90
  "@types/prompts": "^2.0.14",
90
- "@types/webpack-env": "^1.16.2",
91
- "babel-plugin-glob-import": "^0.0.7"
91
+ "@types/webpack-env": "^1.16.2"
92
92
  }
93
93
  }
package/src/app/index.ts CHANGED
@@ -56,6 +56,15 @@ export class App {
56
56
  this.aliases[side].realpath(filename),
57
57
  }
58
58
 
59
+ public containerServices = [
60
+ 'Services',
61
+ 'Environment',
62
+ 'Identity',
63
+ /*'Application',
64
+ 'Path',
65
+ 'Event'*/
66
+ ]
67
+
59
68
  public constructor() {
60
69
 
61
70
  cli.debug && console.log(`[cli] Loading app config ...`);
@@ -10,14 +10,6 @@ import type { PluginObj } from '@babel/core';
10
10
  import cli from '@cli';
11
11
  import { App, TAppSide } from '../../../../app';
12
12
 
13
- const containerServices = [
14
- 'Environment',
15
- 'Application',
16
- 'Path',
17
- 'Services',
18
- 'Event'
19
- ]
20
-
21
13
  /*----------------------------------
22
14
  - WEBPACK RULE
23
15
  ----------------------------------*/
@@ -43,8 +35,23 @@ function Plugin(babel, { app, side, debug }: TOptions) {
43
35
  const t = babel.types as typeof types;
44
36
 
45
37
  /*
46
- - Wrap route.get(...) with (app: Application) => { }
47
- - Inject chunk ID into client route options
38
+ Transforms:
39
+ import { MyService, Environment } from '@app';
40
+ ...
41
+ MyService.method()
42
+ Environment.name
43
+
44
+ To:
45
+ import app from '@app';
46
+ import Container from '@server/app/container';
47
+ ...
48
+ app.services.MyService.method()
49
+ Container.Environment.name
50
+
51
+ Processed files:
52
+ @/server/config
53
+ @/server/routes
54
+ @/server/services
48
55
  */
49
56
 
50
57
  const plugin: PluginObj<{
@@ -68,7 +75,13 @@ function Plugin(babel, { app, side, debug }: TOptions) {
68
75
  pre(state) {
69
76
 
70
77
  this.filename = state.opts.filename as string;
71
- this.processFile = this.filename.startsWith( cli.paths.appRoot + '/src/server' );
78
+ this.processFile = (
79
+ this.filename.startsWith( cli.paths.appRoot + '/src/server/config' )
80
+ ||
81
+ this.filename.startsWith( cli.paths.appRoot + '/src/server/routes' )
82
+ ||
83
+ this.filename.startsWith( cli.paths.appRoot + '/src/server/services' )
84
+ )
72
85
 
73
86
  this.importedServices = {}
74
87
  this.bySource = {
@@ -103,7 +116,7 @@ function Plugin(babel, { app, side, debug }: TOptions) {
103
116
  this.importedServicesCount++;
104
117
 
105
118
  let importSource: TImportSource;
106
- if (containerServices.includes(specifier.imported.name))
119
+ if (app.containerServices.includes(specifier.imported.name))
107
120
  importSource = 'container';
108
121
  else
109
122
  importSource = 'application';
@@ -129,13 +142,14 @@ function Plugin(babel, { app, side, debug }: TOptions) {
129
142
  )
130
143
  );
131
144
 
132
- if (this.bySource.application > 0)
145
+ // NOTE: Update 20/07: services should be accessed through current service instance
146
+ /*if (this.bySource.application > 0)
133
147
  replaceWith.push(
134
148
  t.importDeclaration(
135
149
  [t.importDefaultSpecifier( t.identifier('application') )],
136
150
  t.stringLiteral( cli.paths.core.src + '/server/app/instance')
137
151
  )
138
- );
152
+ );*/
139
153
 
140
154
  path.replaceWithMultiple(replaceWith);
141
155
  },
@@ -178,8 +192,8 @@ function Plugin(babel, { app, side, debug }: TOptions) {
178
192
  ? t.identifier( service.source )
179
193
  // application.services.Disks
180
194
  : t.memberExpression(
181
- t.identifier( service.source ),
182
- t.identifier('services'),
195
+ t.identifier('this'),
196
+ t.identifier('app'),
183
197
  ),
184
198
  path.node
185
199
  )
@@ -6,8 +6,6 @@
6
6
  import path from 'path';
7
7
  import webpack from 'webpack';
8
8
  import fs from 'fs-extra';
9
- import micromatch from 'micromatch';
10
- import moduleAlias from 'module-alias';
11
9
 
12
10
  import SpeedMeasurePlugin from "speed-measure-webpack-plugin";
13
11
  const smp = new SpeedMeasurePlugin({ disable: true });
@@ -147,7 +145,23 @@ dependences: ${JSON.stringify(dependences)},
147
145
  }
148
146
  }
149
147
 
148
+ // Define the app class identifier
149
+ const appClassIdentifier = app.identity.identifier;
150
+ const containerServices = app.containerServices.map( s => "'" + s + "'").join('|');
151
+
150
152
  // Output the services index
153
+ fs.outputFileSync(
154
+ path.join( app.paths.client.generated, 'services.d.ts'),
155
+ `declare module "@app" {
156
+
157
+ import { CrossPathClient } from '@/client/index';
158
+
159
+ const appClass: CrossPathClient;
160
+
161
+ export = appClass
162
+ }`
163
+ );
164
+
151
165
  fs.outputFileSync(
152
166
  path.join( app.paths.server.generated, 'services.ts'),
153
167
  `${imported.join('\n')}
@@ -161,12 +175,39 @@ export default {
161
175
 
162
176
  fs.outputFileSync(
163
177
  path.join( app.paths.server.generated, 'services.d.ts'),
164
- `declare module "@app" {
165
- type Services = import("./services").Services;
166
- const ServerServices: Services & {
167
- app: import('@server/app').Application<Services>
168
- }
178
+ `type InstalledServices = import('./services').Services;
179
+
180
+ declare type ${appClassIdentifier} = import("@/server").default;
181
+
182
+ declare module "@app" {
183
+
184
+ import { ApplicationContainer } from '@server/app/container';
185
+
186
+ const ServerServices: (
187
+ Pick<
188
+ ApplicationContainer<InstalledServices>,
189
+ ${containerServices}
190
+ >
191
+ &
192
+ ${appClassIdentifier}
193
+ )
194
+
169
195
  export = ServerServices
196
+ }
197
+
198
+ declare module '@server/app' {
199
+
200
+ import { Application } from "@server/app/index";
201
+ import { ServicesContainer } from "@server/app/service/container";
202
+
203
+ export interface Exported {
204
+ Application: typeof Application,
205
+ Services: ServicesContainer<InstalledServices>,
206
+ }
207
+
208
+ const foo: Exported;
209
+
210
+ export = foo;
170
211
  }`
171
212
  );
172
213
  }
@@ -1,125 +0,0 @@
1
- import app from '@server/app'; // CLI or App
2
- app.configure({
3
-
4
- // Tracking
5
- tracking: {
6
- // https://analytics.google.com/analytics/web/@report-home/a114396550w244235024p227300451
7
- ga: {
8
- pub: 'G-198FW1K066',
9
- // Client ID
10
- prv: '',
11
- // Secret code for GA4 measurement api
12
- // https://analytics.google.com/analytics/web/#/a114396550p308927292/admin/streams/table/3375435279
13
- secret: 'MJWpU7MqSZKth1LJvp2gag'
14
- }
15
- },
16
-
17
- // HTTP
18
- http: {
19
-
20
- port: 3010,
21
- ssl: false,
22
-
23
- upload: {
24
- maxSize: '10mb'
25
- },
26
-
27
- // Protections against bots
28
- security: {
29
- // https://www.google.com/recaptcha/admin/site/346699952
30
- recaptcha: {
31
- pub: '6LewOKoUAAAAAKmaDqpcNaQz31z_AJarSs0sQvft',
32
- prv: '6LewOKoUAAAAAOAj80m9vOJuP9YcR7PnYQ3E-y4o'
33
- },
34
- iphub: "Mzk3MzpLWE84eHhXQ0ZvUlNQODh0M3J0OXpDTGE2WGx5Szl6OA=="
35
- }
36
- /*session: {
37
- duration: 604800, // 7 Jours
38
- secret: 'secret',
39
- name: 'sessionId',
40
- }*/
41
- },
42
-
43
- // Database (SQL)
44
- database: {
45
- list: ['megacharger'],
46
-
47
- dev: {
48
- host: '127.0.0.1',
49
- port: 3306,
50
- login: 'gaetan',
51
- password: "$mdp=MySQL!159753",
52
- },
53
-
54
- prod: {
55
- host: 'mysqldb',
56
- port: 3306,
57
- login: 'gaetan',
58
- password: "$mdp=MySQL!159753",
59
- },
60
-
61
- },
62
-
63
- // Authentication
64
- auth: {
65
- jwt: {
66
- // 2048 bits
67
- key: "D*G-KaPdSgVkYp3s6v9y$B&E(H+MbQeThWmZq4t7w!z%C*F-J@NcRfUjXn2r5u8x/A?D(G+KbPdSgVkYp3s6v9y$B&E)H@McQfThWmZq4t7w!z%C*F-JaNdRgUkXn2r5u8x/A?D(G+KbPeShVmYq3s6v9y$B&E)H@McQfTjWnZr4u7w!z%C*F-JaNdRgUkXp2s5v8y/A?D(G+KbPeShVmYq3t6w9z$C&E)H@McQfTjWnZr4u7x!A%D*G-JaNdRgU",
68
- expiration: "7 days",
69
- },
70
- google: {
71
- web: {
72
- clientId: "186669785739-e760eqsevhi7hd6nii6ha5pk0rip1s86.apps.googleusercontent.com",
73
- secret: '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',
74
- },
75
- android: {
76
- clientId: "186669785739-geqn7egdepda7aqgoob0ce7jot1ko2gh.apps.googleusercontent.com"
77
- }
78
- }
79
- },
80
-
81
- // Router
82
- router: {
83
-
84
- },
85
-
86
- // Socket
87
- socket: {
88
- port: 3011,
89
- },
90
-
91
- // Email
92
- email: {
93
- default: {
94
- transporter: 'mailjet',
95
- from: 'sites@gaetan-legac.fr',
96
- },
97
- transporters: {
98
- local: {
99
- // Réseau
100
- host: 'localhost',
101
- port: 25,
102
- tls: false,
103
- // Auth
104
- login: 'contact',
105
- password: '$mdp=VPS!159753',
106
- },
107
- sendgrid: {
108
- api: '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',
109
- },
110
- mailjet: {
111
- api: '2c24ad3fa9254fe1a50f4d707069d654'
112
- }
113
- }
114
- },
115
-
116
- // Redis
117
- redis: {
118
-
119
- },
120
-
121
- // Cron
122
- cron: {
123
-
124
- }
125
- })