5htp 0.6.2 → 0.6.3-2

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.
@@ -1,11 +1,7 @@
1
1
  // Plugons
2
2
  import MiniCssExtractPlugin from "mini-css-extract-plugin";
3
- import lessToJs from 'less-vars-to-js';
4
3
 
5
- import fs from 'fs-extra';
6
- import cli from '@cli';
7
-
8
- import type App from '../../../app';
4
+ import type { App } from '../../../app';
9
5
 
10
6
  module.exports = (app: App, dev: Boolean, client: boolean) => {
11
7
 
@@ -31,11 +27,32 @@ module.exports = (app: App, dev: Boolean, client: boolean) => {
31
27
  loader: 'css-loader',
32
28
  options: {
33
29
  // CSS Loader https://github.com/webpack/css-loader
34
- importLoaders: 1,
30
+ importLoaders: 1, // let postcss run on @imports
35
31
  sourceMap: dev
36
32
  },
37
33
  },
38
34
 
35
+ // Postcss
36
+ {
37
+ loader: 'postcss-loader',
38
+ options: {
39
+ postcssOptions: {
40
+ plugins: [
41
+ /* Tailwind V4 */require('@tailwindcss/postcss')({
42
+ // Ensure Tailwind scans the application sources even if the build
43
+ // process is launched from another working directory (e.g. Docker).
44
+ base: app.paths.root,
45
+
46
+ // Avoid double-minifying: Webpack already runs CssMinimizerPlugin in prod.
47
+ optimize: false,
48
+ }),
49
+ ///* Tailwind V3 */require('tailwindcss'),
50
+ require('autoprefixer'),
51
+ ],
52
+ },
53
+ },
54
+ },
55
+
39
56
  {
40
57
  test: /\.less$/,
41
58
  loader: 'less-loader',
@@ -58,4 +75,4 @@ module.exports = (app: App, dev: Boolean, client: boolean) => {
58
75
  }*/
59
76
  ]
60
77
 
61
- }
78
+ }
@@ -8,9 +8,6 @@ import dayjs from 'dayjs';
8
8
 
9
9
  // Plugins
10
10
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
11
- import PluginIndexage from './plugins/indexage';
12
- import IconesSvg from './plugins/indexage/icones-svg';
13
- import InjectDeps from './plugins/indexage/injection-dependances';
14
11
 
15
12
  // Core
16
13
  import cli from '../..';
@@ -88,12 +85,6 @@ export default function createCommonConfig(
88
85
 
89
86
  }),
90
87
 
91
- new PluginIndexage(side === 'client' ? {
92
- 'icones-svg': new IconesSvg(app),
93
- } : {
94
- //'injection-dependances': new InjectDeps,
95
- }),
96
-
97
88
  ...(side === 'client' && cli.args.analyze ? [
98
89
 
99
90
  new BundleAnalyzerPlugin({
package/compiler/index.ts CHANGED
@@ -17,7 +17,6 @@ import cli from '..';
17
17
  import createServerConfig from './server';
18
18
  import createClientConfig from './client';
19
19
  import { TCompileMode } from './common';
20
- import { routerServices } from './common/babel/plugins/services';
21
20
 
22
21
  type TCompilerCallback = (compiler: webpack.Compiler) => void
23
22
 
@@ -34,7 +33,7 @@ type TRegisteredService = {
34
33
  id?: string,
35
34
  name: string,
36
35
  className: string,
37
- instanciation: (parentRef: string) => string,
36
+ instanciation: (parentRef?: string) => string,
38
37
  priority: number,
39
38
  }
40
39
 
@@ -198,7 +197,7 @@ export default class Compiler {
198
197
  const refTo = serviceConfig.refTo;
199
198
  return {
200
199
  name: serviceName,
201
- instanciation: (parentRef: string) => `this.${refTo}`,
200
+ instanciation: () => `this.${refTo}`,
202
201
  priority: 0
203
202
  }
204
203
  }
@@ -228,7 +227,7 @@ export default class Compiler {
228
227
 
229
228
  // Reference to a service
230
229
  else if (value.type === 'service.setup' || value.type === 'service.ref') // TODO: more reliable way to detect a service reference
231
- propsStr += `${key}:`+ refService(key, value, level + 1).instanciation('instance') + ',\n'
230
+ propsStr += `${key}:`+ refService(key, value, level + 1).instanciation() + ',\n'
232
231
 
233
232
  // Recursion
234
233
  else if (level <= 4 && !Array.isArray(value))
@@ -244,10 +243,10 @@ export default class Compiler {
244
243
  const config = processConfig(serviceConfig.config || {});
245
244
 
246
245
  // Generate the service instance
247
- const instanciation = (parentRef: string) =>
246
+ const instanciation = (parentRef?: string) =>
248
247
  `new ${serviceMetas.name}(
249
- ${parentRef},
250
- (instance: ${serviceMetas.name}) => (${config}),
248
+ ${parentRef ? `${parentRef},` : ''}
249
+ ${config},
251
250
  this
252
251
  )`
253
252
 
@@ -267,7 +266,7 @@ export default class Compiler {
267
266
  const appClassIdentifier = app.identity.identifier;
268
267
  const containerServices = app.containerServices.map( s => "'" + s + "'").join('|');
269
268
 
270
- // Output the services index
269
+ // @/client/.generated/services.d.ts
271
270
  fs.outputFileSync(
272
271
  path.join( app.paths.client.generated, 'services.d.ts'),
273
272
  `declare module "@app" {
@@ -303,6 +302,7 @@ declare namespace preact.JSX {
303
302
  `
304
303
  );
305
304
 
305
+ // @/client/.generated/context.ts
306
306
  fs.outputFileSync(
307
307
  path.join( app.paths.client.generated, 'context.ts'),
308
308
  `// TODO: move it into core (but how to make sure usecontext returns ${appClassIdentifier}'s context ?)
@@ -333,16 +333,28 @@ export type ClientContext = (
333
333
  export const ReactClientContext = React.createContext<ClientContext>({} as ClientContext);
334
334
  export default (): ClientContext => React.useContext<ClientContext>(ReactClientContext);`);
335
335
 
336
+ // @/common/.generated/services.d.ts
337
+ fs.outputFileSync(
338
+ path.join( app.paths.common.generated, 'services.d.ts'),
339
+ `declare module '@models/types' {
340
+ export * from '@/var/prisma/index';
341
+ }`
342
+ );
343
+
344
+ // @/server/.generated/app.ts
336
345
  fs.outputFileSync(
337
346
  path.join( app.paths.server.generated, 'app.ts'),
338
- `import { Application } from '@server/app/index';
347
+ `
348
+ import { Application } from '@server/app/index';
349
+ import { ServicesContainer } from '@server/app/service/container';
339
350
 
340
351
  ${imported.join('\n')}
341
352
 
342
- export default class ${appClassIdentifier} extends Application {
353
+ export default class ${appClassIdentifier} extends Application<ServicesContainer, CurrentUser> {
343
354
 
355
+ // Make sure the services typigs are reflecting the config and referring to the app
344
356
  ${sortedServices.map(service =>
345
- `public ${service.name}!: ${service.className};`
357
+ `public ${service.name}!: ReturnType<${appClassIdentifier}["registered"]["${service.id}"]["start"]>;`
346
358
  ).join('\n')}
347
359
 
348
360
  protected registered = {
@@ -359,6 +371,7 @@ export default class ${appClassIdentifier} extends Application {
359
371
 
360
372
  `);
361
373
 
374
+ // @/server/.generated/services.d.ts
362
375
  fs.outputFileSync(
363
376
  path.join( app.paths.server.generated, 'services.d.ts'),
364
377
  `type InstalledServices = import('./services').Services;
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.6.2",
4
+ "version": "0.6.3-2",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp.git",
7
7
  "license": "MIT",
@@ -27,6 +27,7 @@
27
27
  "@babel/preset-typescript": "^7.15.0",
28
28
  "@prefresh/webpack": "^3.3.2",
29
29
  "@squoosh/lib": "^0.4.0",
30
+ "@tailwindcss/postcss": "^4.1.17",
30
31
  "@types/babel__core": "^7.1.16",
31
32
  "@types/cookie": "^0.4.1",
32
33
  "@types/express": "^4.17.13",
@@ -40,6 +41,7 @@
40
41
  "@types/universal-analytics": "^0.4.5",
41
42
  "@types/webpack-env": "^1.16.2",
42
43
  "@types/ws": "^7.4.7",
44
+ "autoprefixer": "^10.4.21",
43
45
  "babel-loader": "^10.0.0",
44
46
  "babel-plugin-glob-import": "^0.0.9-1",
45
47
  "babel-plugin-transform-imports": "^2.0.0",
@@ -50,7 +52,7 @@
50
52
  "compression-webpack-plugin": "^8.0.1",
51
53
  "console-table-printer": "^2.10.0",
52
54
  "css-loader": "^6.2.0",
53
- "css-minimizer-webpack-plugin": "^4.1.0",
55
+ "css-minimizer-webpack-plugin": "^7.0.4",
54
56
  "dayjs": "^1.11.5",
55
57
  "favicons": "^7.2.0",
56
58
  "filesize": "^8.0.3",
@@ -67,6 +69,7 @@
67
69
  "node-cmd": "^5.0.0",
68
70
  "node-notifier": "^10.0.0",
69
71
  "null-loader": "^4.0.1",
72
+ "postcss-loader": "^8.2.0",
70
73
  "prompts": "^2.4.2",
71
74
  "react-dev-utils": "^11.0.4",
72
75
  "replace-once": "^1.0.0",
@@ -74,6 +77,7 @@
74
77
  "serialize-javascript": "^6.0.2",
75
78
  "sharp": "^0.34.3",
76
79
  "speed-measure-webpack-plugin": "^1.5.0",
80
+ "tailwindcss": "^4.1.17",
77
81
  "terser-webpack-plugin": "^5.2.4",
78
82
  "ts-alias": "^0.0.7",
79
83
  "ts-node": "^10.9.1",
@@ -84,7 +88,8 @@
84
88
  "webpack-dev-middleware": "^5.1.0",
85
89
  "webpack-hot-middleware": "^2.25.0",
86
90
  "webpack-node-externals": "^3.0.0",
87
- "webpack-virtual-modules": "^0.4.3"
91
+ "webpack-virtual-modules": "^0.4.3",
92
+ "yaml": "^2.8.2"
88
93
  },
89
94
  "devDependencies": {
90
95
  "@types/babel__preset-env": "^7.9.6",
@@ -1,191 +0,0 @@
1
- /*----------------------------------
2
- - DEPENDANCES
3
- ----------------------------------*/
4
-
5
- import { PluginObj } from '@babel/core';
6
-
7
- import * as types from '@babel/types'
8
- import generate from '@babel/generator';
9
-
10
- /*----------------------------------
11
- - WEBPACK RULE
12
- ----------------------------------*/
13
- module.exports = {
14
- test: "**/client/**/*.tsx",
15
- plugins: [
16
- [Plugin]
17
- ]
18
- }
19
-
20
- const debug = false
21
-
22
- /*----------------------------------
23
- - PLUGIN
24
- ----------------------------------*/
25
- function Plugin (babel) {
26
-
27
- const t = babel.types as typeof types;
28
-
29
- const plugin: PluginObj<{
30
- fichier: string,
31
- cancel: boolean
32
- }> = {
33
- pre(state) {
34
-
35
- this.fichier = state.opts.filename as string;
36
-
37
- if (!('useForm' in state.scope.bindings))
38
- this.cancel = true;
39
-
40
- },
41
- visitor: {
42
- JSXElement(instruction) {
43
-
44
- if (this.cancel === true)
45
- return;
46
-
47
- const balise = instruction.node.openingElement;
48
-
49
- /*
50
- <Champs.metas.titre className="full" attrsChamp={{ className: "h1" }} />
51
- */
52
-
53
- if (!(
54
- balise.selfClosing === true
55
- &&
56
- balise.name.type === 'JSXMemberExpression'
57
- &&
58
- balise.name.property.type === 'JSXIdentifier'
59
- ))
60
- return;
61
-
62
- debug && console.log(`[compilation][babel][form] Original: `, generate(instruction.node).code);
63
-
64
- // Si le premier element du memberexpression est Champ
65
- let nomA: types.JSXMemberExpression | types.JSXIdentifier = balise.name;
66
- while (nomA.type === 'JSXMemberExpression')
67
- nomA = nomA.object;
68
- if (!nomA.name.startsWith('Champs'))
69
- return;
70
-
71
- // Ne pas parcourir les élements enfant
72
- // Avec .stop, babel arrête d'itérer les élements voisins à partir du 6ème - 7ème
73
- //instruction.stop();
74
- instruction.skip();
75
-
76
- // Transformation de la lste des attributs en un objet
77
- /*
78
- className="full" attrsChamp={{ className: "h1" }}
79
-
80
- =>
81
-
82
- { className: "full", attrsChamp: { className: "h1" } }
83
- */
84
- let objAttributs: types.ObjectProperty[] = [];
85
- for (const attribut of balise.attributes)
86
- if (
87
- attribut.type === 'JSXAttribute' &&
88
- attribut.value !== undefined &&
89
- typeof attribut.name.name === "string"
90
- ) {
91
-
92
- let propValue: types.ObjectProperty["value"];
93
- if (attribut.value === null) // <Champ.titre autoFocus />
94
- propValue = t.booleanLiteral(true);
95
- else if (attribut.value.type !== 'JSXExpressionContainer')
96
- propValue = attribut.value;
97
- else if (attribut.value.expression.type !== 'JSXEmptyExpression')
98
- propValue = attribut.value.expression;
99
- else
100
- propValue = t.nullLiteral();
101
-
102
- objAttributs.push(
103
- t.objectProperty(
104
- t.identifier( attribut.name.name ),
105
- propValue
106
- )
107
- )
108
- }
109
-
110
- // Traverse chaque branche du chemin du champ, dans l'ordre inverse
111
- // NOTE: on aurai pu reconstituer le chemin et créer les memberexpressions en une seule itération
112
- // Mais le fait d ele faire en deux itérations rend le code plus claire et maintenable
113
- let cheminComposant: string[] = []
114
- let brancheA: types.JSXMemberExpression | types.JSXIdentifier = balise.name;
115
- while (brancheA.type === 'JSXMemberExpression') {
116
-
117
- const { property } = brancheA;
118
-
119
- cheminComposant.unshift(property.name)
120
- brancheA = brancheA.object;
121
- }
122
-
123
- let cheminSchema: types.MemberExpression | types.OptionalMemberExpression = t.memberExpression(
124
- t.identifier('Champs'),
125
- t.identifier('schema')
126
- );
127
- let cheminDonnees: types.MemberExpression | types.OptionalMemberExpression = t.memberExpression(
128
- t.identifier('Champs'),
129
- t.identifier('data')
130
- );
131
- const iDerniereBranche = cheminComposant.length - 1
132
- for (let iBranche = iDerniereBranche; iBranche >= 0; iBranche--) {
133
-
134
- const branche = cheminComposant[ iBranche ];
135
-
136
- cheminSchema = t.optionalMemberExpression(
137
- cheminSchema,
138
- t.identifier( branche ),
139
- undefined,
140
- true
141
- )
142
-
143
- if (iBranche !== iDerniereBranche)
144
- cheminDonnees = t.optionalMemberExpression(
145
- cheminDonnees,
146
- t.identifier(branche),
147
- undefined,
148
- true
149
- )
150
-
151
- }
152
-
153
- // Remplacement
154
- /*
155
- {Champs._render( Champs.metas?.titre, Champs._data.metas?.titre, 'metas.titre', {
156
- className: "full",
157
- attrsChamp: { className: "h1" }
158
- })}
159
- */
160
- const remplacement = t.callExpression(
161
-
162
- // Champs.render
163
- t.memberExpression(
164
- t.identifier('Champs'),
165
- t.identifier('render')
166
- ),
167
- [
168
- // Champs.<chemin>
169
- cheminSchema,
170
-
171
- // Champs._data.<chemin>
172
- cheminDonnees,
173
-
174
- // Chemin
175
- t.stringLiteral( cheminComposant.join('.') ),
176
-
177
- // { <attrs> }
178
- t.objectExpression(objAttributs)
179
- ]
180
- )
181
-
182
- debug && console.log(`[compilation][babel][form] Remplacement: `, generate(remplacement).code );
183
-
184
- instruction.replaceWith(remplacement);
185
-
186
- }
187
- },
188
- };
189
-
190
- return plugin;
191
- }