5htp 0.6.3-8 → 0.6.4

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/app/index.ts CHANGED
@@ -56,7 +56,13 @@ export class App {
56
56
  public paths = {
57
57
 
58
58
  root: cli.paths.appRoot,
59
- bin: path.join( cli.paths.appRoot, 'bin'),
59
+ binBuild: path.join( cli.paths.appRoot, 'bin'),
60
+ binDev: path.join( cli.paths.appRoot, 'bin-dev'),
61
+ get bin() {
62
+ return cli.commandName === 'dev'
63
+ ? this.binDev
64
+ : this.binBuild;
65
+ },
60
66
  data: path.join( cli.paths.appRoot, 'var', 'data'),
61
67
  public: path.join( cli.paths.appRoot, 'public'),
62
68
  pages: path.join( cli.paths.appRoot, 'client', 'pages'),
@@ -192,4 +198,4 @@ export class App {
192
198
 
193
199
  export const app = new App
194
200
 
195
- export default app
201
+ export default app
package/commands/build.ts CHANGED
@@ -2,22 +2,35 @@
2
2
  - DEPENDANCES
3
3
  ----------------------------------*/
4
4
 
5
- // Npm
6
- import prompts from 'prompts';
7
-
8
5
  // Configs
6
+ import cli from '..';
9
7
  import Compiler from '../compiler';
8
+ import type { TCompileMode } from '../compiler/common';
10
9
 
11
10
  /*----------------------------------
12
11
  - TYPES
13
12
  ----------------------------------*/
14
13
 
14
+ const buildModes: TCompileMode[] = ['dev', 'prod'];
15
+
16
+ function getBuildMode(): TCompileMode {
17
+
18
+ const selectedModes = buildModes.filter(mode => cli.args[mode] === true);
19
+
20
+ if (selectedModes.length > 1)
21
+ throw new Error(`Build mode is ambiguous. Use only one mode among: ${buildModes.join(', ')}`);
22
+
23
+ return selectedModes[0] || 'dev';
24
+ }
25
+
15
26
  /*----------------------------------
16
27
  - COMMAND
17
28
  ----------------------------------*/
18
- export const run = (): Promise<void> => new Promise(async (resolve) => {
29
+ export const run = (): Promise<void> => new Promise(async (resolve, reject) => {
19
30
 
20
- const compiler = new Compiler('prod');
31
+ const mode = getBuildMode();
32
+
33
+ const compiler = new Compiler(mode);
21
34
 
22
35
  const multiCompiler = await compiler.create();
23
36
 
@@ -25,10 +38,24 @@ export const run = (): Promise<void> => new Promise(async (resolve) => {
25
38
 
26
39
  if (error) {
27
40
  console.error("An error occurred during the compilation:", error);
28
- throw error;
41
+ reject(error);
42
+ return;
43
+ }
44
+
45
+ if (stats?.hasErrors()) {
46
+ reject(new Error(`Build failed in ${mode} mode.`));
47
+ return;
29
48
  }
30
49
 
31
- //resolve();
50
+ multiCompiler.close((closeError) => {
51
+
52
+ if (closeError) {
53
+ reject(closeError);
54
+ return;
55
+ }
56
+
57
+ resolve();
58
+ });
32
59
 
33
60
  });
34
- });
61
+ });
@@ -35,6 +35,7 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
35
35
 
36
36
  console.info(`Creating compiler for client (${mode}).`);
37
37
  const dev = mode === 'dev';
38
+ const buildCheck = dev && cli.commandName === 'build';
38
39
 
39
40
  const commonConfig = createCommonConfig(app, 'client', mode);
40
41
 
@@ -78,7 +79,7 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
78
79
 
79
80
  output: {
80
81
 
81
- pathinfo: dev,
82
+ pathinfo: dev && !buildCheck,
82
83
  path: app.paths.bin + '/public',
83
84
  filename: '[name].js', // Output client.js
84
85
  assetModuleFilename: '[hash][ext]',
@@ -157,7 +158,7 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
157
158
  // Emit a file with assets cli.paths
158
159
  // https://github.com/webdeveric/webpack-assets-manifest#options
159
160
  new WebpackAssetsManifest({
160
- output: app.paths.root + `/bin/asset-manifest.json`,
161
+ output: app.paths.bin + `/asset-manifest.json`,
161
162
  publicPath: true,
162
163
  writeToDisk: true, // Force la copie du fichier sur e disque, au lieu d'en mémoire en mode dev
163
164
  customize: ({ key, value }) => {
@@ -167,7 +168,7 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
167
168
  },
168
169
  done: (manifest, stats) => {
169
170
  // Write chunk-manifest.json.json
170
- const chunkFileName = app.paths.root + `/bin/chunk-manifest.json`;
171
+ const chunkFileName = app.paths.bin + `/chunk-manifest.json`;
171
172
  try {
172
173
  const fileFilter = file => !file.endsWith('.map');
173
174
  const addPath = file => manifest.getPublicPath(file);
@@ -226,7 +227,7 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
226
227
  ],
227
228
 
228
229
  // https://webpack.js.org/configuration/devtool/#devtool
229
- devtool: 'source-map',
230
+ devtool: buildCheck ? false : 'source-map',
230
231
  /*devServer: {
231
232
  hot: true,
232
233
  },*/
@@ -45,6 +45,7 @@ export default function createCommonConfig(
45
45
  ): webpack.Configuration {
46
46
 
47
47
  const dev = mode === 'dev';
48
+ const buildCheck = dev && cli.commandName === 'build';
48
49
  const config: webpack.Configuration = {
49
50
 
50
51
  // Project root
@@ -127,13 +128,17 @@ export default function createCommonConfig(
127
128
  // "webpack" The "path" argument must be of type string. Received undefined
128
129
  // https://github.com/webpack/webpack/issues/12616
129
130
  // Update: Hum it's fixed, just had to update webpack deps
130
- cache: dev,
131
+ cache: dev && !buildCheck,
131
132
 
132
- profile: true,
133
+ profile: !buildCheck,
133
134
 
134
135
  // Pour bundle-stats
135
136
  // https://github.com/relative-ci/bundle-stats/tree/master/packages/cli#webpack-configuration
136
- stats: {
137
+ stats: buildCheck ? {
138
+ colors: true,
139
+ errorDetails: true,
140
+ timings: true,
141
+ } : {
137
142
  cached: dev,
138
143
  cachedAssets: dev,
139
144
  chunks: dev,
@@ -151,4 +156,4 @@ export default function createCommonConfig(
151
156
 
152
157
  return config;
153
158
 
154
- }
159
+ }
@@ -43,6 +43,7 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
43
43
 
44
44
  debug && console.info(`Creating compiler for server (${mode}).`);
45
45
  const dev = mode === 'dev';
46
+ const buildCheck = dev && cli.commandName === 'build';
46
47
 
47
48
  const commonConfig = createCommonConfig(app, 'server', mode);
48
49
  const { aliases } = app.aliases.server.forWebpack({
@@ -69,7 +70,7 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
69
70
 
70
71
  output: {
71
72
 
72
- pathinfo: dev,
73
+ pathinfo: dev && !buildCheck,
73
74
 
74
75
  libraryTarget: 'commonjs2',
75
76
 
@@ -198,7 +199,9 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
198
199
  },
199
200
 
200
201
  // https://webpack.js.org/configuration/devtool/#devtool
201
- devtool: dev
202
+ devtool: buildCheck
203
+ ? false
204
+ : dev
202
205
  ? 'eval-source-map' // Recommended choice for development builds with high quality SourceMaps.
203
206
  : 'source-map', // Recommended choice for production builds with high quality SourceMaps.
204
207
 
@@ -209,4 +212,4 @@ export default function createCompiler( app: App, mode: TCompileMode ): webpack.
209
212
  };
210
213
 
211
214
  return config;
212
- };
215
+ };
package/index.ts CHANGED
@@ -33,6 +33,8 @@ export class CLI {
33
33
 
34
34
  // Context
35
35
  public args: TArgsObject = {};
36
+
37
+ public commandName: string | null = null;
36
38
 
37
39
  public debug: boolean = false;
38
40
 
@@ -112,6 +114,7 @@ export class CLI {
112
114
 
113
115
  public async runCommand(command: string) {
114
116
 
117
+ this.commandName = command;
115
118
  this.debug && console.info(`Running command ${command}`, this.args);
116
119
 
117
120
  // Check existance
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.3-8",
4
+ "version": "0.6.4",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp.git",
7
7
  "license": "MIT",
package/readme.md CHANGED
@@ -36,10 +36,20 @@ Requires Node.js `18.20+` or any compatible `20.x` release.
36
36
 
37
37
  `5htp dev`
38
38
 
39
- 4. Build for production:
39
+ Dev compilation output is written to `bin-dev`.
40
+
41
+ 4. Build output files with the development config:
40
42
 
41
43
  `5htp build`
42
44
 
45
+ `5htp build dev`
46
+
47
+ 5. Build for production:
48
+
49
+ `5htp build prod`
50
+
51
+ Build output is written to `bin`.
52
+
43
53
  ## To be done:
44
54
 
45
55
  - [ ] Update templates & documentation