5htp 0.0.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.
Files changed (35) hide show
  1. package/package.json +94 -0
  2. package/src/commands/build.ts +32 -0
  3. package/src/commands/deploy/app.ts +29 -0
  4. package/src/commands/deploy/web.ts +62 -0
  5. package/src/commands/dev.ts +100 -0
  6. package/src/compiler/client/identite.ts +70 -0
  7. package/src/compiler/client/index.ts +335 -0
  8. package/src/compiler/common/babel/index.ts +261 -0
  9. package/src/compiler/common/babel/plugins/form.ts +191 -0
  10. package/src/compiler/common/babel/plugins/icones-svg.ts +350 -0
  11. package/src/compiler/common/babel/plugins/importations.ts +337 -0
  12. package/src/compiler/common/babel/plugins/injection-dependances/index.ts +223 -0
  13. package/src/compiler/common/babel/plugins/injection-dependances/remplacerFonction.ts +226 -0
  14. package/src/compiler/common/babel/plugins/models.ts +241 -0
  15. package/src/compiler/common/babel/plugins/pages.ts +185 -0
  16. package/src/compiler/common/babel/plugins/queries/index.ts +166 -0
  17. package/src/compiler/common/files/autres.ts +37 -0
  18. package/src/compiler/common/files/images.ts +19 -0
  19. package/src/compiler/common/files/style.ts +64 -0
  20. package/src/compiler/common/index.ts +148 -0
  21. package/src/compiler/common/plugins/indexage/_utils/Stringify.ts +72 -0
  22. package/src/compiler/common/plugins/indexage/_utils/annotations.ts +88 -0
  23. package/src/compiler/common/plugins/indexage/_utils/iterateur.ts +52 -0
  24. package/src/compiler/common/plugins/indexage/icones-svg/index.ts +198 -0
  25. package/src/compiler/common/plugins/indexage/index.ts +132 -0
  26. package/src/compiler/common/plugins/indexage/indexeur.ts +13 -0
  27. package/src/compiler/common/plugins/indexage/injection-dependances/index.ts +68 -0
  28. package/src/compiler/index.ts +86 -0
  29. package/src/compiler/server/index.ts +177 -0
  30. package/src/index.ts +192 -0
  31. package/src/paths.ts +158 -0
  32. package/src/print.ts +12 -0
  33. package/src/utils/index.ts +22 -0
  34. package/src/utils/keyboard.ts +78 -0
  35. package/tsconfig.json +38 -0
@@ -0,0 +1,335 @@
1
+ /*----------------------------------
2
+ - DEPENDANCES
3
+ ----------------------------------*/
4
+
5
+ // Npm
6
+ import webpack from 'webpack';
7
+ import fs from 'fs-extra';
8
+
9
+ // Plugins
10
+ const TerserPlugin = require('terser-webpack-plugin');
11
+ // Optimisations
12
+ const BrotliCompression = require("brotli-webpack-plugin");
13
+ import CompressionPlugin from "compression-webpack-plugin";
14
+ const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
15
+ const imageminWebp = require('imagemin-webp');
16
+ const { extendDefaultPlugins } = require("svgo");
17
+ // Ressources
18
+ const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
19
+ import MiniCssExtractPlugin from "mini-css-extract-plugin";
20
+ import WebpackAssetsManifest from 'webpack-assets-manifest';
21
+ // Dev
22
+ import PreactRefreshPlugin from '@prefresh/webpack';
23
+
24
+ // Core
25
+ import createCommonConfig, { TCompileMode, regex } from '../common';
26
+ import identityAssets from './identite';
27
+ import cli from '../..';
28
+
29
+ /*----------------------------------
30
+ - CONFIG
31
+ ----------------------------------*/
32
+ export default function createCompiler(mode: TCompileMode): webpack.Configuration {
33
+
34
+ console.info(`Creating compiler for client (${mode}).`);
35
+ const dev = mode === 'dev';
36
+
37
+ const commonConfig = createCommonConfig('client', mode);
38
+
39
+ // Pas besoin d'attendre que les assets soient générés pour lancer la compilation
40
+ identityAssets();
41
+
42
+ // Symlinks to public
43
+ /*const publicDirs = fs.readdirSync(cli.paths.app.root + '/public');
44
+ for (const publicDir of publicDirs)
45
+ fs.symlinkSync(
46
+ cli.paths.app.root + '/public/' + publicDir,
47
+ cli.paths.app.public + '/' + publicDir
48
+ );*/
49
+
50
+ // Convert tsconfig cli.paths to webpack aliases
51
+ const { aliases } = cli.paths.aliases.client.forWebpack(cli.paths.app.root + '/node_modules');
52
+ // Disable access to server-side libs from client side
53
+ delete aliases["@server"];
54
+ delete aliases["@/server"];
55
+
56
+ const config: webpack.Configuration = {
57
+
58
+ ...commonConfig,
59
+
60
+ name: 'client',
61
+ target: 'web',
62
+ entry: {
63
+ client: [
64
+ /*...(dev ? [
65
+ process.env.framework + '/cli/compilation/webpack/libs/webpackHotDevClient.js',
66
+ // https://github.com/webpack-contrib/webpack-hot-middleware#config
67
+ cli.paths.core.root + '/node_modules' + '/webpack-hot-middleware/client?name=client&reload=true',
68
+ ] : []),*/
69
+ cli.paths.core.root + '/src/client/index.tsx'
70
+ ]
71
+ },
72
+
73
+ output: {
74
+
75
+ pathinfo: dev,
76
+ path: cli.paths.app.bin + '/public',
77
+ filename: '[name].js', // Output client.js
78
+ assetModuleFilename: '[hash][ext]',
79
+
80
+ chunkFilename: dev
81
+ ? '[name].js'
82
+ : '[id].[hash:8].js'
83
+ },
84
+
85
+ resolve: {
86
+
87
+ ...commonConfig.resolve,
88
+
89
+ alias: aliases,
90
+
91
+ // RAPPEL: on a besoin de résoudre les node_modules
92
+ extensions: [".mjs", '.ts', '.tsx', ".jsx", ".js", ".json", ".sql"],
93
+ },
94
+
95
+ module: {
96
+ // Make missing exports an error instead of warning
97
+ strictExportPresence: true,
98
+
99
+ rules: [
100
+ {
101
+ test: regex.scripts,
102
+ include: [
103
+
104
+ cli.paths.app.root + '/src/client',
105
+ cli.paths.core.root + '/src/client',
106
+
107
+ cli.paths.app.root + '/src/common',
108
+ cli.paths.core.root + '/src/common',
109
+
110
+ ],
111
+ rules: require('../common/babel')('client', dev)
112
+ },
113
+
114
+ // Les pages étan tà la fois compilées dans le bundle client et serveur
115
+ // On ne compile les ressources (css) qu'une seule fois
116
+ {
117
+ test: regex.style,
118
+ rules: require('../common/files/style')(true, dev),
119
+
120
+ // Don't consider CSS imports dead code even if the
121
+ // containing package claims to have no side effects.
122
+ // Remove this when webpack adds a warning or an error for this.
123
+ // See https://github.com/webpack/webpack/issues/6571
124
+ sideEffects: true,
125
+ },
126
+
127
+ ...require('../common/files/images')(dev, true),
128
+
129
+ ...require('../common/files/autres')(dev, true),
130
+
131
+ // Exclude dev modules from production build
132
+ /*...(dev ? [] : [
133
+ {
134
+ test: cli.paths.app.root + '/node_modules/react-deep-force-update/lib/index.js'),
135
+ loader: 'null-loader',
136
+ },
137
+ ]),*/
138
+ ],
139
+ },
140
+
141
+ plugins: [
142
+
143
+ ...(commonConfig.plugins || []),
144
+
145
+ new MiniCssExtractPlugin({
146
+
147
+ }),
148
+
149
+ // Emit a file with assets cli.paths
150
+ // https://github.com/webdeveric/webpack-assets-manifest#options
151
+ new WebpackAssetsManifest({
152
+ output: cli.paths.app.root + `/bin/asset-manifest.json`,
153
+ publicPath: true,
154
+ writeToDisk: true, // Force la copie du fichier sur e disque, au lieu d'en mémoire en mode dev
155
+ customize: ({ key, value }) => {
156
+ // You can prevent adding items to the manifest by returning false.
157
+ if (key.toLowerCase().endsWith('.map')) return false;
158
+ return { key, value };
159
+ },
160
+ done: (manifest, stats) => {
161
+ // Write chunk-manifest.json.json
162
+ const chunkFileName = cli.paths.app.root + `/bin/chunk-manifest.json`;
163
+ try {
164
+ const fileFilter = file => !file.endsWith('.map');
165
+ const addPath = file => manifest.getPublicPath(file);
166
+ const chunkFiles = stats.compilation.chunkGroups.reduce((acc, c) => {
167
+ acc[c.name] = [
168
+ ...(acc[c.name] || []),
169
+ ...c.chunks.reduce(
170
+ (files, cc) => [
171
+ ...files,
172
+ ...cc.files.filter(fileFilter).map(addPath),
173
+ ],
174
+ [],
175
+ ),
176
+ ];
177
+ return acc;
178
+ }, Object.create(null));
179
+ fs.writeFileSync(chunkFileName, JSON.stringify(chunkFiles, null, 4));
180
+ } catch (err) {
181
+ console.error(`ERROR: Cannot write ${chunkFileName}: `, err);
182
+ if (!dev) process.exit(1);
183
+ }
184
+ },
185
+ }),
186
+
187
+ ...(dev ? [
188
+
189
+ // HMR pour preact
190
+ //new PreactRefreshPlugin(),
191
+
192
+ ] : [
193
+
194
+ /*new MomentLocalesPlugin({
195
+ localesToKeep: ['fr'],
196
+ }),*/
197
+
198
+ /*new CompressionPlugin({
199
+ cache: true,
200
+ minRatio: 0.99
201
+ }),
202
+
203
+ new BrotliCompression({
204
+ algorithm: 'gzip',
205
+ test: /\.js$|\.css$|\.html$/,
206
+ threshold: 10240,
207
+ minRatio: 0.8,
208
+ })*/
209
+
210
+ /*new webpack.HashedModuleIdsPlugin({
211
+ hashFunction: 'sha256',
212
+ hashDigest: 'hex',
213
+ hashDigestLength: 20,
214
+ }),*/
215
+
216
+ /*new PurgecssPlugin({}),*/
217
+ ]),
218
+ ],
219
+
220
+ // https://webpack.js.org/configuration/devtool/#devtool
221
+ devtool: 'source-map',
222
+ /*devServer: {
223
+ hot: true,
224
+ },*/
225
+
226
+ optimization: {
227
+
228
+ // Code splitting serveur = même que client
229
+ // La décomposition des chunks doit toujours être la même car le rendu des pages dépend de cette organisation
230
+
231
+ // https://webpack.js.org/plugins/split-chunks-plugin/#configuration
232
+ splitChunks: {
233
+
234
+ // This indicates which chunks will be selected for optimization
235
+ chunks: 'async',
236
+ // Minimum size, in bytes, for a chunk to be generated.
237
+ // Pour les imports async (ex: pages), on crée systématiquemen un chunk séparé
238
+ // Afin que le css d'une page ne soit appliqué qu'à la page concernée
239
+ minSize: 0,
240
+
241
+ cacheGroups: {
242
+
243
+ /*defaultVendors: {
244
+ test: /[\\/]node_modules[\\/]/,
245
+ name(module) {
246
+ const packageName = module.context.match(
247
+ /[\\/]node_modules[\\/](.*?)([\\/]|$)/,
248
+ )[1];
249
+ return `npm.${packageName.replace('@', '')}`;
250
+ },
251
+ priority: -10,
252
+ },*/
253
+
254
+ /*default: {
255
+ minChunks: 2,
256
+ priority: -20,
257
+ reuseExistingChunk: true
258
+ }*/
259
+ },
260
+ },
261
+
262
+ // Production
263
+ ...(dev ? {} : {
264
+
265
+ // https://github.com/react-boilerplate/react-boilerplate/blob/master/internals/webpack/webpack.prod.babel.js
266
+ minimize: true,
267
+ removeAvailableModules: true,
268
+ minimizer: [
269
+ new TerserPlugin({
270
+ terserOptions: {
271
+ parse: {
272
+ // We want terser to parse ecma 8 code. However, we don't want it
273
+ // to apply any minification steps that turns valid ecma 5 code
274
+ // into invalid ecma 5 code. This is why the 'compress' and 'output'
275
+ // sections only apply transformations that are ecma 5 safe
276
+ // https://github.com/facebook/create-react-app/pull/4234
277
+ ecma: 8,
278
+ },
279
+ compress: {
280
+ ecma: 5,
281
+ warnings: false,
282
+ // Disabled because of an issue with Uglify breaking seemingly valid code:
283
+ // https://github.com/facebook/create-react-app/issues/2376
284
+ // Pending further investigation:
285
+ // https://github.com/mishoo/UglifyJS2/issues/2011
286
+ comparisons: false,
287
+ // Disabled because of an issue with Terser breaking valid code:
288
+ // https://github.com/facebook/create-react-app/issues/5250
289
+ // Pending further investigation:
290
+ // https://github.com/terser-js/terser/issues/120
291
+ inline: 2,
292
+ },
293
+ mangle: {
294
+ safari10: true,
295
+ },
296
+ output: {
297
+ ecma: 5,
298
+ comments: false,
299
+ // Turned on because emoji and regex is not minified properly using default
300
+ // https://github.com/facebook/create-react-app/issues/2488
301
+ ascii_only: true,
302
+ },
303
+ }
304
+ }),
305
+
306
+ ...(dev ? [] : [
307
+ new CssMinimizerPlugin()
308
+ ]),
309
+
310
+ // BUG: Essai de charger les plugins depuis app/node_modules
311
+ // Et la specification via require() ne sembl epas être supportée ...
312
+ // https://webpack.js.org/plugins/image-minimizer-webpack-plugin/
313
+ /*new ImageMinimizerPlugin({
314
+ generator: [
315
+ {
316
+ // You can apply generator using `?as=webp`, you can use any name and provide more options
317
+ preset: "webp",
318
+ implementation: ImageMinimizerPlugin.imageminGenerate,
319
+ options: {
320
+ // Please specify only one plugin here, multiple plugins will not work
321
+ plugins: ["imagemin-webp"],
322
+ },
323
+ },
324
+ ],
325
+ }),*/
326
+ ],
327
+ nodeEnv: 'production',
328
+ sideEffects: true,
329
+ }),
330
+
331
+ },
332
+ };
333
+
334
+ return config;
335
+ };
@@ -0,0 +1,261 @@
1
+ /*----------------------------------
2
+ - DEPENDANCES
3
+ ----------------------------------*/
4
+
5
+ // Npm
6
+ import path from 'path';
7
+ import type webpack from 'webpack';
8
+ import * as types from '@babel/types'
9
+
10
+ // Core
11
+ import PluginIndexage from '../plugins/indexage';
12
+ import BabelGlobImports from './plugins/importations';
13
+
14
+ import cli from '../../..';
15
+ import { TAppSide } from '../../..';
16
+
17
+ // Const
18
+ const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
19
+
20
+ // Resources
21
+ const routesToPreload = require( cli.paths.appRoot + '/src/client/pages/preload.json' );
22
+
23
+ /*----------------------------------
24
+ - REGLES
25
+ ----------------------------------*/
26
+ module.exports = (side: TAppSide, dev: boolean): webpack.RuleSetRule[] => ([{
27
+ loader: 'babel-loader',
28
+ options: {
29
+
30
+ // https://github.com/babel/babel-loader#options
31
+
32
+ // ATTENTION: Ne prend pas toujours compte des màj des plugins babel
33
+ cacheDirectory: cli.args.cache === true,
34
+ // Désactive car ralenti compilation
35
+ cacheCompression: false,
36
+
37
+ metadataSubscribers: [
38
+ PluginIndexage.metadataContextFunctionName
39
+ ],
40
+
41
+ compact: !dev,
42
+
43
+ // https://babeljs.io/docs/usage/options/
44
+ babelrc: false,
45
+ presets: [
46
+
47
+ // https://github.com/babel/babel-preset-env
48
+ [require('@babel/preset-env'), side === 'client' ? {
49
+
50
+ // Ajoute automatiquement les polyfills babel
51
+ // https://stackoverflow.com/a/61517521/12199605
52
+ "useBuiltIns": "usage", // alternative mode: "entry"
53
+ "corejs": 3, // default would be 2
54
+
55
+ targets: {
56
+ browsers: cli.pkg.app.browserslist,
57
+ },
58
+ forceAllTransforms: !dev, // for UglifyJS
59
+ modules: false,
60
+ debug: false,
61
+ } : {
62
+ targets: {
63
+ node: true,//pkg.engines.node.match(/(\d+\.?)+/)[0],
64
+ },
65
+ modules: false,
66
+ useBuiltIns: false,
67
+ debug: false,
68
+ }],
69
+
70
+ [require("@babel/preset-typescript"), {
71
+ useDefineForClassFields: true,
72
+ //jsxPragma: "h"
73
+ }],
74
+
75
+ // JSX
76
+ // https://github.com/babel/babel/tree/master/packages/babel-preset-react
77
+ [require('@babel/preset-react'), {
78
+ //pragma: "h"
79
+ }],
80
+
81
+ ],
82
+ plugins: [
83
+
84
+ // NOTE: On résoud les plugins et presets directement ici
85
+ // Autrement, babel-loader les cherchera dans projet/node_modules
86
+
87
+
88
+ [require("@babel/plugin-proposal-decorators"), { "legacy": true }],
89
+
90
+ [require('@babel/plugin-proposal-class-properties'), { "loose": true }],
91
+
92
+ [require('@babel/plugin-proposal-private-methods'), { "loose": true }],
93
+
94
+ // Masque erreur associée à @babel/plugin-proposal-decorators legacy: true
95
+ [require('@babel/plugin-proposal-private-property-in-object'), { "loose": true }],
96
+
97
+ ...(dev ? [
98
+
99
+ ...(side === 'client' ? [
100
+
101
+ // HMR Preact avec support des hooks
102
+ //['@prefresh/babel-plugin'],
103
+
104
+ ] : [])
105
+
106
+ ] : [
107
+
108
+ // Les 3 plugins suivants sont tirés de https://github.com/jamiebuilds/babel-react-optimize
109
+
110
+ // Remove unnecessary React propTypes from the production build
111
+ // https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types
112
+ [require('babel-plugin-transform-react-remove-prop-types')],
113
+ // Treat React JSX elements as value types and hoist them to the highest scope
114
+ // https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-constant-elements
115
+ [require('@babel/plugin-transform-react-constant-elements')],
116
+
117
+ // Pour du tree shaking manuel
118
+ // https://www.npmjs.com/package/babel-plugin-transform-imports
119
+ [require("babel-plugin-transform-imports"), {
120
+ "lodash": {
121
+ "transform": "lodash/${member}",
122
+ "preventFullImport": true
123
+ }
124
+ }]
125
+ ]),
126
+
127
+ BabelGlobImports({
128
+ debug: false,
129
+ removeAliases: (source: string) => cli.paths.withoutAlias(source, side)
130
+ }, [{
131
+ test: (request) => {
132
+ if (request.source === '@models') {
133
+ request.source = cli.paths.app.src + '/server/models/**/*.ts';
134
+ return true;
135
+ }
136
+ return false;
137
+ },
138
+ replace: (request, matches, t) => {
139
+ // Preserve default behavior
140
+ }
141
+ }, {
142
+ test: (request) => (
143
+ side === 'client'
144
+ &&
145
+ (
146
+ request.source === '@/client/pages/**/*.tsx'
147
+ ||
148
+ request.source === '@client/pages/**/*.tsx'
149
+ )
150
+ &&
151
+ request.type === 'import'
152
+ ),
153
+ replace: (request, matches, t) => {
154
+
155
+ if (!('default' in request) || request.default === undefined)
156
+ return;
157
+
158
+ const imports: types.ImportDeclaration[] = [];
159
+
160
+ // const routes = {
161
+ // <chunkId1>: () => import(/* webpackChunkName: '<chunkId>' */ "<file>"),
162
+ // <chunkId2>: () => require("<file>").default,
163
+ // }
164
+
165
+ const pageLoaders: types.ObjectProperty[] = [];
166
+ for (const file of matches) {
167
+
168
+ // Exclude layouts
169
+ if (file.filename.includes("/_layout/")) {
170
+ //console.log("Exclude", file, 'from pages loaders (its a layout)');
171
+ continue;
172
+ }
173
+
174
+ // Excliude components
175
+ const filename = path.basename( file.filename );
176
+ if (alphabet.includes(filename[0]) && filename[0] === filename[0].toUpperCase()) {
177
+ //console.log("Exclude", file, 'from pages loaders (its a component)');
178
+ continue;
179
+ }
180
+
181
+ // Page config
182
+ const { chunkId } = cli.paths.getPageChunk(file.filename);
183
+ const preloadPage = routesToPreload.includes(chunkId);
184
+
185
+ // Import type according to preloading option
186
+ if (preloadPage) {
187
+
188
+ // import <chunkId> from "<file>";
189
+ imports.push(
190
+ t.importDeclaration(
191
+ [t.importDefaultSpecifier( t.identifier(chunkId) )],
192
+ t.stringLiteral(file.filename)
193
+ )
194
+ );
195
+
196
+ // { <chunkId>: <chunkId> }
197
+ pageLoaders.push(
198
+ t.objectProperty(
199
+ t.stringLiteral(chunkId),
200
+ t.identifier(chunkId)
201
+ )
202
+ );
203
+
204
+ } else {
205
+
206
+ // <chunkId>: () => ...
207
+ pageLoaders.push(
208
+ t.objectProperty(
209
+
210
+ t.stringLiteral(chunkId),
211
+ // () => import(/* webpackChunkName: '<chunkId>' */ "<file>")
212
+ t.arrowFunctionExpression([], t.callExpression(
213
+
214
+ t.import(), [t.addComment(
215
+ t.stringLiteral(file.filename),
216
+ "leading",
217
+ "webpackChunkName: '" + chunkId + "'"
218
+ )]
219
+ ))
220
+ )
221
+ )
222
+ }
223
+ }
224
+
225
+ return [
226
+ ...imports,
227
+ // const routes = { ... }
228
+ t.variableDeclaration("const", [t.variableDeclarator(
229
+ t.identifier(request.default),
230
+ t.objectExpression(pageLoaders)
231
+ )])
232
+ ]
233
+
234
+ }
235
+ }])
236
+
237
+ ],
238
+
239
+ overrides: [
240
+
241
+ require("./plugins/pages")({ side }),
242
+
243
+ require("./plugins/models")({ side }),
244
+
245
+ require('./plugins/icones-svg'),
246
+
247
+ require('./plugins/form'),
248
+
249
+ /*
250
+
251
+ ...(side === 'client' ? [
252
+
253
+ ] : [
254
+ require('./plugins/queries');
255
+ require('./plugins/injection-dependances'),
256
+ ]),
257
+
258
+ */
259
+ ]
260
+ }
261
+ }])