@cley_faye/boilerplate 3.1.1 → 3.3.0

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/README.md CHANGED
@@ -19,6 +19,8 @@ required, and for what. It's up to the calling project to have the proper depend
19
19
 
20
20
  For webapp building:
21
21
 
22
+ - resolve-typescript-plugin (due to the way webpack plugins are handled, this is mandatory for dev
23
+ install)
22
24
  - babel-loader
23
25
  - eslint-webpack-plugin
24
26
  - @babel/core
@@ -27,14 +29,14 @@ For webapp building:
27
29
  - babel-plugin-transform-define
28
30
  - core-js
29
31
  - @babel/plugin-transform-runtime
30
- - @keeex/grunt-contrib-imagemin
31
32
  - grunt-contrib-pug
32
33
  - grunt-contrib-copy
33
34
  - grunt-contrib-watch
34
35
  - grunt-sass
35
- - node-sass
36
+ - sass
36
37
  - grunt-webpack
37
38
  - grunt
39
+ - ts-loader (for supporting TypeScript import in webpack/babel)
38
40
 
39
41
  For express:
40
42
 
@@ -155,6 +157,7 @@ The webpack options support a host of properties:
155
157
  - babelPlugins: array of plugins for Babel
156
158
  - mode: The build mode. "development", "production" or "none"
157
159
  - defines: a record of value to define using Babel transform-define
160
+ - resolve: a custom "resolve" object for webpack config
158
161
 
159
162
  ### SASS
160
163
  All `.sass` and `.scss` files in the webapp directory will be processed as `.css` files in the
@@ -200,7 +203,7 @@ module.exports = grunt => {
200
203
  )
201
204
  );
202
205
  grunt.initConfig(baseGruntConfig);
203
- grunt.register(
206
+ grunt.registerTask(
204
207
  "myWebApp",
205
208
  "Build the webapp",
206
209
  requiredTasks
@@ -426,8 +429,10 @@ Typical use of TypeScript implies converting `.ts` file to `.js`.
426
429
  For a React app using webpack, there's two approach: either instruct webpack to accept `.ts` files
427
430
  (for example, using `ts-loader`) or have your entry point be a `.js` file that imports the generated
428
431
  output from TypeScript.
429
- Either way, watch mode will be capable of detecting change in the source material, as long as the
430
- TypeScript compiler is also running.
432
+ If you reference the output of the TypeScript compiler, you can keep it updated using `npx tsc -w`.
433
+
434
+ Using `ts-loader` can be done automatically by setting the `typescript` property in the webpack
435
+ configuration to `true`.
431
436
 
432
437
  For Express app, there is no particular things to take care, except that if you use a facility like
433
438
  `nodemon` you have to watch the TypeScript output instead of the actual source files.
@@ -66,6 +66,10 @@ export declare type OptionDefinition = OptionDefinitionString | OptionDefinition
66
66
  * Expected options from command line
67
67
  */
68
68
  export declare type ConfigDefinition = Record<string, OptionDefinition>;
69
+ /**
70
+ * Display help to the user
71
+ */
72
+ export declare const displayHelp: (configDef: ConfigDefinition) => void;
69
73
  /**
70
74
  * Construct the full config object from command line values.
71
75
  *
package/lib/grunt/args.js CHANGED
@@ -26,7 +26,7 @@
26
26
  */
27
27
  "use strict";
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getOptionsFromGruntCLI = exports.OptType = void 0;
29
+ exports.getOptionsFromGruntCLI = exports.displayHelp = exports.OptType = void 0;
30
30
  const util_js_1 = require("../util.js");
31
31
  // eslint-disable-next-line no-shadow
32
32
  var OptType;
@@ -125,6 +125,7 @@ const displayHelp = (configDef) => {
125
125
  outputHelp("Accepted command line arguments:");
126
126
  Object.keys(configDef).forEach(configKey => displayHelpForConfigKey(configKey, configDef[configKey]));
127
127
  };
128
+ exports.displayHelp = displayHelp;
128
129
  /**
129
130
  * Construct the full config object from command line values.
130
131
  *
@@ -132,7 +133,7 @@ const displayHelp = (configDef) => {
132
133
  */
133
134
  const getOptionsFromGruntCLI = (optionProvider, configDef) => {
134
135
  if (getFromOptionProvider("help", optionProvider) === true) {
135
- displayHelp(configDef);
136
+ (0, exports.displayHelp)(configDef);
136
137
  return null;
137
138
  }
138
139
  const result = {};
@@ -18,10 +18,10 @@ export interface ImageOptions extends BaseOptions {
18
18
  * Options for the image task configuration.
19
19
  *
20
20
  * @param [imageOptions.options]
21
- * Options to pass to grunt-contrib-imagemin.
21
+ * Options to pass to @cley_faye/imagemin-lite.
22
22
  *
23
23
  * @param [imageOptions.sourcePath]
24
- * Path where the pug templates can be found. Subdirectories will be searched.
24
+ * Path where the source images can be found. Subdirectories will be searched.
25
25
  * Default to "webres/<targetName>"
26
26
  *
27
27
  * @param [imageOptions.outputPath]
@@ -47,10 +47,10 @@ const handledExtensions = [
47
47
  * Options for the image task configuration.
48
48
  *
49
49
  * @param [imageOptions.options]
50
- * Options to pass to grunt-contrib-imagemin.
50
+ * Options to pass to @cley_faye/imagemin-lite.
51
51
  *
52
52
  * @param [imageOptions.sourcePath]
53
- * Path where the pug templates can be found. Subdirectories will be searched.
53
+ * Path where the source images can be found. Subdirectories will be searched.
54
54
  * Default to "webres/<targetName>"
55
55
  *
56
56
  * @param [imageOptions.outputPath]
@@ -63,6 +63,7 @@ const handledExtensions = [
63
63
  */
64
64
  const handle = (gruntConfig, targetName, imageOptions) => {
65
65
  const handledFiles = handledExtensions.map(ext => `**/*${ext}`);
66
+ // TODO use @cley_faye/imagemin-lite once it exists
66
67
  const newImageTask = {
67
68
  options: imageOptions.options,
68
69
  files: [
@@ -75,7 +76,7 @@ const handle = (gruntConfig, targetName, imageOptions) => {
75
76
  ],
76
77
  };
77
78
  const requiredTasks = [
78
- (0, util_js_1.insertTask)(gruntConfig, "imagemin", targetName, newImageTask),
79
+ (0, util_js_1.insertTask)(gruntConfig, "copy", `${targetName}_image`, newImageTask),
79
80
  ];
80
81
  const watchTasks = [
81
82
  {
@@ -9,6 +9,7 @@ export interface WebpackLoadersOptions {
9
9
  targets?: string;
10
10
  plugins?: Array<Record<string, unknown>>;
11
11
  };
12
+ typescript?: boolean;
12
13
  }
13
14
  /** Build the default webpack loaders list.
14
15
  *
@@ -30,6 +31,9 @@ export interface WebpackLoadersOptions {
30
31
  *
31
32
  * @param [options.babel.plugins]
32
33
  * Plugins to add to babel
34
+ *
35
+ * @param [options.typescript]
36
+ * Add support for importing .ts and .tsx files
33
37
  */
34
38
  export declare const webpackLoadersDefault: (options: WebpackLoadersOptions) => Array<Record<string, unknown>>;
35
39
  export interface WebpackOptions extends BaseOptions {
@@ -45,6 +49,8 @@ export interface WebpackOptions extends BaseOptions {
45
49
  plugins?: Array<Record<string, unknown>>;
46
50
  babelPlugins?: Array<Record<string, unknown>>;
47
51
  defines?: Record<string, string>;
52
+ resolve?: Record<string, unknown>;
53
+ typescript?: boolean;
48
54
  }
49
55
  /** Add a webpack task for the reactApp recipe
50
56
  *
@@ -98,6 +104,9 @@ export interface WebpackOptions extends BaseOptions {
98
104
  * Build mode. "development", "production" or "none".
99
105
  * Defaults to "development"
100
106
  *
107
+ * @param [webpackOptions.typescript]
108
+ * Allow loading typescript source for webpack/babel.
109
+ *
101
110
  * @return
102
111
  * List of tasks added.
103
112
  * This function add "webpack:<targetName>".
@@ -33,6 +33,7 @@ exports.handle = exports.webpackLoadersDefault = void 0;
33
33
  const path_1 = require("path");
34
34
  const util_js_1 = require("./util.js");
35
35
  const eslint_webpack_plugin_1 = __importDefault(require("eslint-webpack-plugin"));
36
+ const resolve_typescript_plugin_1 = __importDefault(require("resolve-typescript-plugin"));
36
37
  const defaultCoreJS = 3;
37
38
  const eslintPlugin = () => new eslint_webpack_plugin_1.default({ cache: true });
38
39
  const defaultLoadersDefine = (options) => [
@@ -78,27 +79,43 @@ const defaultLoadersReact = (options) => [
78
79
  *
79
80
  * @param [options.babel.plugins]
80
81
  * Plugins to add to babel
82
+ *
83
+ * @param [options.typescript]
84
+ * Add support for importing .ts and .tsx files
81
85
  */
82
- const webpackLoadersDefault = (options) => [
83
- {
84
- test: /.js$/u,
85
- exclude: /node_modules/u,
86
- use: {
87
- loader: "babel-loader",
88
- options: {
89
- cacheDirectory: true,
90
- presets: [
91
- defaultLoadersPresetEnv(options),
92
- defaultLoadersReact(options),
93
- ],
94
- plugins: [
95
- defaultLoadersDefine(options),
96
- ...(options.babel?.plugins ?? []),
97
- ],
86
+ const webpackLoadersDefault = (options) => {
87
+ const allFilesCheck = options.typescript
88
+ ? /.(?:js|ts|tsx)$/u
89
+ : /.js$/u;
90
+ const res = [
91
+ {
92
+ test: allFilesCheck,
93
+ exclude: /node_modules/u,
94
+ use: {
95
+ loader: "babel-loader",
96
+ options: {
97
+ cacheDirectory: true,
98
+ presets: [
99
+ defaultLoadersPresetEnv(options),
100
+ defaultLoadersReact(options),
101
+ ],
102
+ plugins: [
103
+ defaultLoadersDefine(options),
104
+ ...(options.babel?.plugins ?? []),
105
+ ],
106
+ },
98
107
  },
99
108
  },
100
- },
101
- ];
109
+ ];
110
+ if (options.typescript) {
111
+ res.push({
112
+ test: /.(?:ts|tsx)$/u,
113
+ use: "ts-loader",
114
+ exclude: /node_modules/u,
115
+ });
116
+ }
117
+ return res;
118
+ };
102
119
  exports.webpackLoadersDefault = webpackLoadersDefault;
103
120
  const computeWebpackOutput = (webpackOptions, targetName) => webpackOptions.output ?? {
104
121
  path: (0, path_1.resolve)("dist", targetName, "js"),
@@ -143,6 +160,16 @@ const registerTasks = (gruntConfig, targetName, webpackConfig) => {
143
160
  (0, util_js_1.insertTask)(gruntConfig, "webpack", targetName, webpackConfig),
144
161
  ];
145
162
  };
163
+ const computeWebpackResolve = (webpackOptions) => {
164
+ const res = { ...webpackOptions.resolve };
165
+ if (webpackOptions.typescript) {
166
+ if (res.plugins === undefined) {
167
+ res.plugins = [];
168
+ }
169
+ res.plugins.push(new resolve_typescript_plugin_1.default());
170
+ }
171
+ return res;
172
+ };
146
173
  /** Add a webpack task for the reactApp recipe
147
174
  *
148
175
  * @param gruntConfig
@@ -195,6 +222,9 @@ const registerTasks = (gruntConfig, targetName, webpackConfig) => {
195
222
  * Build mode. "development", "production" or "none".
196
223
  * Defaults to "development"
197
224
  *
225
+ * @param [webpackOptions.typescript]
226
+ * Allow loading typescript source for webpack/babel.
227
+ *
198
228
  * @return
199
229
  * List of tasks added.
200
230
  * This function add "webpack:<targetName>".
@@ -209,7 +239,9 @@ const handle = (gruntConfig, targetName, webpackOptions) => {
209
239
  development: webpackOptions.mode === "development",
210
240
  defines: webpackOptions.defines,
211
241
  babel: { plugins: webpackOptions.babelPlugins },
242
+ typescript: webpackOptions.typescript,
212
243
  });
244
+ const resolve = computeWebpackResolve(webpackOptions);
213
245
  const webpackConfig = {
214
246
  mode: webpackOptions.mode,
215
247
  devtool: webpackOptions.mode === "development" ? "eval-source-map" : false,
@@ -221,6 +253,7 @@ const handle = (gruntConfig, targetName, webpackOptions) => {
221
253
  eslintPlugin(),
222
254
  ...webpackOptions.plugins ?? [],
223
255
  ],
256
+ resolve,
224
257
  };
225
258
  // Special case: I'm not sure I can move options in the task-specific part of
226
259
  // the configuration, so I add it at the toplevel of the "webpack" task.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cley_faye/boilerplate",
3
- "version": "3.1.1",
3
+ "version": "3.3.0",
4
4
  "description": "Boilerplate code generator for generic projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,7 +41,6 @@
41
41
  "@babel/plugin-transform-runtime": "7.x",
42
42
  "@babel/preset-env": "7.x",
43
43
  "@babel/preset-react": "7.x",
44
- "@keeex/grunt-contrib-imagemin": "4.x",
45
44
  "babel-loader": "8.x",
46
45
  "babel-plugin-transform-define": "2.x",
47
46
  "core-js": "3.x",
@@ -54,7 +53,9 @@
54
53
  "grunt-contrib-watch": "1.x",
55
54
  "grunt-sass": "3.x",
56
55
  "grunt-webpack": "5.x",
56
+ "resolve-typescript-plugin": "^1.1.1",
57
57
  "sass": "1.x",
58
+ "ts-loader": "^9.2.6",
58
59
  "winston": "3.x"
59
60
  },
60
61
  "peerDependenciesMeta": {
@@ -79,9 +80,6 @@
79
80
  "grunt-contrib-pug": {
80
81
  "optional": true
81
82
  },
82
- "grunt-contrib-imagemin": {
83
- "optional": true
84
- },
85
83
  "@babel/plugin-transform-runtime": {
86
84
  "optional": true
87
85
  },