@epublishing/grunt-epublishing 1.0.7 → 1.1.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.
package/README.md CHANGED
@@ -1,113 +1,204 @@
1
1
  # grunt-epublishing
2
2
 
3
- > Automated front-end tasks for ePublishing Jade and client sites.
3
+ > Modern front-end build tools for ePublishing Jade and client sites.
4
+ > **Note:** Grunt has been removed. Use `npx epublishing-build` or npm scripts.
5
+
6
+ ## Requirements
7
+
8
+ - **Node.js** >= 18.0.0
9
+ - **Bundler** and the jade gem (or jade client gem) in your Gemfile
4
10
 
5
11
  ## Getting Started
6
- This plugin requires Grunt v1.0.0.
7
12
 
8
- If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins.
13
+ ### 1. Add the package
9
14
 
10
- NodeJS and Grunt-Cli must be installed before you proceed.
15
+ Add `@epublishing/grunt-epublishing` as a dev dependency:
11
16
 
12
- If you are on Mac OS X and use homebrew. The following commands will get you ready to run grunt.
17
+ ```bash
18
+ npm install --save-dev @epublishing/grunt-epublishing
19
+ ```
13
20
 
21
+ ### 2. Add npm scripts to `package.json`
14
22
 
15
- ```sh
16
- brew install node
17
- npm install -g grunt-cli
23
+ ```json
24
+ {
25
+ "name": "my-site",
26
+ "version": "1.0.0",
27
+ "scripts": {
28
+ "build": "epublishing-build",
29
+ "build:watch": "epublishing-build --watch"
30
+ },
31
+ "devDependencies": {
32
+ "@epublishing/grunt-epublishing": "^1.0.0"
33
+ }
34
+ }
18
35
  ```
19
36
 
20
- * To get started with using Grunt Jade you first need the right files within the project you wish to use this plugin. You will create a package.json and gruntfile.js in the root of your application. (unless someone has already done this)
37
+ ### 3. Run the build
21
38
 
22
- * The gruntfile should contain the following code which enables the default jade task:
39
+ ```bash
40
+ # Full build (webpack + sass + concat/minify)
41
+ npm run build
23
42
 
43
+ # Watch mode (rebuilds on file changes)
44
+ npm run build:watch
45
+ ```
24
46
 
25
- ```js
26
- module.exports = function(grunt) {
27
- // Load the grunt jade task
28
- grunt.loadNpmTasks('@epublishing/grunt-epublishing');
47
+ ### Using npx (without installing)
29
48
 
30
- // Run jade-default Grunt Task
31
- grunt.registerTask('default', ['jade']);
32
- };
49
+ ```bash
50
+ npx epublishing-build # Full build
51
+ npx epublishing-build --watch # Watch mode
33
52
  ```
34
53
 
35
- * The package.json file will contain the name of your site, version, and required dependencies that get installed before you can run "grunt". This file would look similar to this, and includes the actual required dependencies for Grunt Jade:
54
+ ---
36
55
 
56
+ ## CLI Usage
37
57
 
38
- ```json
39
- {
40
- "name": "jade-labs",
41
- "version": "0.1.0",
42
- "description":"jade-labs",
43
- "repository": {
44
- "type": "git",
45
- "url": "git@bitbucket.org:epub_dev/jade"
46
- },
47
- "devDependencies": {
48
- "grunt": "^1.0.0",
49
- "grunt-jade": "git+ssh://git@bitbucket.org:epub_dev/grunt-jade.git"
50
- }
51
- }
58
+ ```bash
59
+ epublishing-build [task] [options]
52
60
  ```
53
61
 
54
- * Install the npm modules that this Grunt task depends on. To do this, run the following command in the application you wish to use this plugin.
55
-
56
- ```sh
57
- npm install
62
+ ### Tasks
63
+
64
+ | Task | Description |
65
+ |------|-------------|
66
+ | `all` (default) | Full build: webpack, sass, concat/minify |
67
+ | `webpack` | Compile JS bundles only |
68
+ | `sass` | Compile SCSS to CSS only |
69
+ | `concat` | Concatenate and minify standalone JS only |
70
+ | `clean` | Remove compiled assets |
71
+ | `tsconfig` | Generate tsconfig.json files for IDEs |
72
+ | `clean-tsconfig` | Remove generated tsconfig files |
73
+
74
+ ### Options
75
+
76
+ | Option | Description |
77
+ |--------|-------------|
78
+ | `-w, --watch` | Watch mode; rebuild on file changes |
79
+ | `--no-minify` | Skip minification |
80
+ | `--analyze` | Generate webpack bundle analysis |
81
+ | `--lint` | Run ESLint |
82
+ | `-v, --verbose` | Verbose output |
83
+ | `--parallel` | Run webpack, sass, and concat in parallel |
84
+ | `--no-banner` | Hide the build tools banner |
85
+ | `--env <env>` | Set NODE_ENV |
86
+ | `--gc-between-tasks` | Force GC between tasks (requires `--expose-gc`) |
87
+
88
+ ### Examples
89
+
90
+ ```bash
91
+ # Full build
92
+ epublishing-build
93
+ npm run build
94
+
95
+ # Watch mode
96
+ epublishing-build --watch
97
+ npm run build:watch
98
+
99
+ # Webpack only
100
+ epublishing-build webpack
101
+
102
+ # Sass only
103
+ epublishing-build sass
104
+
105
+ # Webpack in watch mode
106
+ epublishing-build webpack --watch
107
+
108
+ # Production build with bundle analysis
109
+ epublishing-build --analyze --env production
58
110
  ```
59
111
 
60
- Awesome! You are ready to run Grunt in the command line and watch Grunt Jade start working on your front-end assets. Grunt Jade will concatenate and minify the SCSS and Javascript. Here is what `grunt-jade` does when you run `grunt`:
61
-
62
- 1. `set-jade-paths`: Resolve the locations of the active Jade gem, Jade child gem (if there is one), and site directories, making them available as config variables to subsequent tasks.
63
- 1. `npm-install`: Install Node module dependencies in Jade and child gem locations if `package.json` files are present.
64
- 1. `clean`: Clean (delete) previously compiled assets, if any.
65
- 1. `babel`: Transpile standalone ES2015 scripts into public/javascripts/app with Babel.
66
- 1. `concat`: Concatenate our default JS assets into a single script, `jade.default.js`.
67
- 1. `uglify`: Minify the above script.
68
- 1. `webpack`: Compile configured modules in `app/js` and bundle them with their dependencies using Webpack, saving them to `public/javascripts/app/bundle`.
69
- 1. `sass`: Compile SCSS stylesheets to CSS using `libsass`.
70
- 1. `bless`: _(disabled by default)_ Split compiled stylesheets into chunks in order to comply with MSIE 9's stylesheet selector limit.
71
-
72
- ### Custom Tasks
73
-
74
- `grunt-jade` provides a couple of custom Grunt tasks that run as part of the default task set:
75
-
76
- + `set-jade-paths` makes Grunt's configuration aware of the ePublishing gems that a site depends on.
77
- + Spawns a [Ruby script](./tasks/get-jade-gems.rb) as a subprocess that does the following things:
78
- + Sets up Bundler and loads the site's RubyGems dependencies.
79
- + Prints a list of gems whose names match the regular expression `/jade/` to stdout, as a JSON array.
80
- + Parses the JSON array and populates `grunt.config.paths` with entries corresponding to:
81
- + Jade's installation path as `paths.jade`
82
- + The child gem's installation path (if any) as `paths.jadechild`
83
- + Various relative asset directory paths (i.e. `paths.js_src`, `paths.css`, etc.)
84
- + `npm-install` iterates through the paths populated by `set-jade-paths` looking for package.json files.
85
- + If any results are found, it does the following for each:
86
- + Switches the current working directory to the parent folder of the current package.json result.
87
- + Runs `npm install` as a subprocess and waits for it to complete.
88
- + When all results have been processed, the task changes the working directory back to the site's root.
89
- + `watch-all` runs `grunt watch` and `grunt webpack --watch` at the same time in subprocesses
112
+ ---
90
113
 
91
- ## Release Management
114
+ ## Configuration
115
+
116
+ The build tools load configuration from the jade hierarchy: **jade → jade child gem → site**, merging in that order.
117
+
118
+ Configuration files are discovered in this order:
92
119
 
93
- `grunt-epublishing` installs the [bumped](https://bumped.github.io/) package as a development dependency, and its package.json file provides an NPM script that can be used to increment release versions, commit, tag, push, and publish to NPM in a single step:
120
+ 1. `config/build.config.js` (new)
121
+ 2. `config/grunt-config.js` (legacy, still supported)
94
122
 
95
- ```sh
96
- # Example (bump patch version):
97
- $ npm run release patch
123
+ Config can export a function that receives the base config:
124
+
125
+ ```js
126
+ // config/build.config.js or config/grunt-config.js
127
+ module.exports = function(baseConfig) {
128
+ return {
129
+ webpack: {
130
+ dist: {
131
+ entry: { ... },
132
+ output: { ... }
133
+ }
134
+ },
135
+ sass: { ... },
136
+ concat: { ... }
137
+ };
138
+ };
98
139
  ```
99
140
 
141
+ Or a plain object:
142
+
143
+ ```js
144
+ module.exports = {
145
+ webpack: { ... },
146
+ sass: { ... }
147
+ };
148
+ ```
149
+
150
+ ### What the build does
151
+
152
+ 1. **Resolve paths**: Finds jade gem, jade child gem (if any), and site directories via Bundler
153
+ 2. **npm install**: Runs `npm ci` (or `npm install`) in jade and jade child gem directories that have `package.json`. Installs dependencies from each gem—the site's `npm install` remains manual.
154
+ 3. **Webpack**: Compiles JS modules from `app/js` with SWC, outputs to `public/javascripts/app/bundle`
155
+ 4. **Sass**: Compiles SCSS to CSS using sass-embedded
156
+ 5. **Concat/Minify**: Concatenates and minifies standalone scripts into `jade.default.js` and similar outputs
157
+
158
+ ---
159
+
100
160
  ## Local Development
101
161
 
102
- If you're working on new build system features, you can link your local clone of grunt-epublishing into a Jade site like
103
- so:
162
+ To develop or debug the build tools against a Jade site:
104
163
 
105
- ```sh
164
+ ```bash
106
165
  # Inside the grunt-epublishing directory:
107
166
  npm link
108
167
 
109
- # Change directories to the site:
110
- cd ../jade-site
111
-
168
+ # In your site directory:
112
169
  npm link @epublishing/grunt-epublishing
113
170
  ```
171
+
172
+ Then run `epublishing-build` from the site; it will use your local clone.
173
+
174
+ ---
175
+
176
+ ## Migration from Grunt
177
+
178
+ If you were using the old Grunt-based setup:
179
+
180
+ **Before (Grunt):**
181
+ ```js
182
+ // Gruntfile.js
183
+ module.exports = function(grunt) {
184
+ grunt.loadNpmTasks('@epublishing/grunt-epublishing');
185
+ grunt.registerTask('default', ['jade']);
186
+ };
187
+ ```
188
+ ```bash
189
+ grunt
190
+ grunt jade
191
+ ```
192
+
193
+ **After:**
194
+ - Remove the Gruntfile (or repurpose it if you have custom tasks)
195
+ - Add npm scripts: `"build": "epublishing-build"`, `"build:watch": "epublishing-build --watch"`
196
+ - Run `npm run build` or `npx epublishing-build` instead of `grunt`
197
+
198
+ Existing `config/grunt-config.js` files continue to work; no config changes required.
199
+
200
+ ---
201
+
202
+ ## Release Management
203
+
204
+ If using [bumped](https://bumped.github.io/) (see `.bumpedrc`), version bumping and publishing can be automated. Otherwise, manually bump `version` in `package.json`, commit, tag, and run `npm publish`.
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * ePublishing Build Tools CLI
5
+ *
6
+ * Modern replacement for grunt-epublishing.
7
+ *
8
+ * Usage:
9
+ * npx epublishing-build # Full build
10
+ * npx epublishing-build --watch # Watch mode
11
+ * npx epublishing-build webpack # Webpack only
12
+ * npx epublishing-build sass # Sass only
13
+ * npx epublishing-build concat # Concat only
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ const { run } = require('../lib/cli');
19
+
20
+ run(process.argv.slice(2)).catch((err) => {
21
+ console.error('Build failed:', err.message);
22
+ if (process.env.DEBUG) {
23
+ console.error(err.stack);
24
+ }
25
+ process.exit(1);
26
+ });
27
+
28
+