-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate out CSS/JS lint tasks from copy-assets
#2863
Conversation
f3146cd
to
5e550d8
Compare
copy-assets
copy-assets
40f87ea
to
3fc590e
Compare
3fc590e
to
9ebc415
Compare
9ebc415
to
90f427f
Compare
90f427f
to
c4a34eb
Compare
c4a34eb
to
92233ac
Compare
1164290
to
6559896
Compare
92233ac
to
3b31bfd
Compare
docs/contributing/tasks.md
Outdated
- run accessibility tests on HTML files | ||
- run tests on the review application | ||
|
||
**`npm run heroku` runs on Heroku build/PR and it:** | ||
- compiles components' HTML | ||
- compiles CSS & JS | ||
- compiles Sass & JavaScript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very understandable, but it would be more accurate to say "compiles Sass to CSS". That's probably needlessly wordy, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @domoscargin
The diff has changed but I've gone with:
Short descriptions
For npm scripts (or gulp tasks with sub tasks)
**`npm run heroku` runs on Heroku build/PR and it will:**
- run `npm run build:compile`
- start up Express
Long descriptions
For the main gulp task that does the work
**`gulp styles`**
This task will:
- check Sass code quality via Stylelint (`npm run lint:scss`)
- compile Sass to CSS (`gulp scss:compile`) into `./public`, or another location via the `--destination` flag
**`gulp scripts`**
This task will:
- check JavaScript code quality via ESLint (`npm run lint:js`) (using JavaScript Standard Style)
- compile JavaScript ESM to CommonJS (`gulp js:compile`) into `./public`, or another location via the `--destination` flag
Is that alright?
@@ -70,18 +65,21 @@ This task will: | |||
**`gulp styles`** | |||
|
|||
This task will: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"This task performs:"?
Or add a verb to the beginning of each bullet point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added verbs to all bullets, thanks 😊
docs/contributing/tasks.md
Outdated
This task will: | ||
- concatenate and uglify javascript (`gulp js:compile`) to a destination folder that can be specified via a --destination flag | ||
This task will: | ||
- JavaScript code quality checks via ESLint (`gulp js:lint`) (using JavaScript Standard Style) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a verb to start
docs/examples/webpack/assets/main.js
Outdated
@@ -1,3 +1,7 @@ | |||
import Button from 'govuk-frontend/govuk/components/button/button' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we split this commit out?
Or add something to the commit message about why it's part of this linting PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the commit to a separate PR, bit simpler that way #2869
// -------------------------------------- | ||
/** | ||
* Serve task | ||
* Restarts Node.js app when there are changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we reflect that Sass changes cause a rebuild (via the watch task)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added more detail to the watch task for .scss
and .mjs
files
This one is serve (via Nodemon) so will only restart for Node.js related changes
gulpfile.js
Outdated
// -------------------------------------- | ||
/** | ||
* Dev task | ||
* Runs a sequence of task on start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Runs a sequence of task on start | |
* Runs a sequence of tasks on start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed
/** | ||
* Copy assets task | ||
* Copies assets to taskArguments.destination (public) | ||
*/ | ||
gulp.task('copy:assets', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're referring to two things as "assets" in these tasks:
- The static assets in
src/assets
- The compiled JS and CSS files
Maybe we should rename this to copy:static-assets or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep I noticed this too!
Hope the change I went with clears things up?
Rename gulp copy-assets
→ gulp compile
(compiles CSS, Sass, Sassdoc)
Rename gulp copy-files
→ gulp copy:files
(compiles selected files into --destination
)
Gulp also looks for .displayName
properties (see Task metadata) on plain Node.js functions so I've added these so everything makes sense from the command line:
clean:dist
clean:package
clean:public
Oh and as a bonus, it'll now output the actual npm script name too (not our task wrappers)
[12:27:26] Using gulpfile ~/path/to/project/govuk-frontend/gulpfile.js
[12:27:26] Starting 'styles'...
[12:27:26] Starting 'npm run lint:scss --silent'...
[12:27:29] Finished 'npm run lint:scss --silent' after 3.68 s
[12:27:29] Starting 'scss:compile'...
[12:27:30] Finished 'scss:compile' after 409 ms
[12:27:30] Finished 'styles' after 4.09 s
I've left a few small comments, but overall I think this looks good. It'd be good to update this sheet when this gets approved: https://docs.google.com/spreadsheets/d/1aprdKVIx6FzBtX9ohWx6LR8p5XH3s2PNq1tev1ZwxkY/edit#gid=77403370 I can't think of any situation where we'd be hindered by not running linting before builds. Our Github workflow would catch anything getting pushed, and our dev/start task would catch anything we were working on locally. I'll leave this open to see if anybody else wants to chime in. |
f8b2827
to
0b54976
Compare
00907ff
to
b669f11
Compare
b669f11
to
0dddc0d
Compare
0dddc0d
to
5ae1389
Compare
5ae1389
to
f37d032
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a few naming comments as I was trying to wrap my head around what runTask
was doing, but otherwise it looks neat to me 😄
I think we'll need some further work around linting and testing though. There's a scenario that's pretty annoying when working on tests running with Puppeteer.
- if you update a non-test JS file with a linting error,
- the linting still runs on the
gulp dev
that runs to recompile, so nothing will be re-compiled - your test will keep running on the old version of the code, and likely still be failing
- and, that's the annoying bit, the info on why it fails is in another terminal than the one running your test and that's tricky to see.
I'm not sure how we'd feel about removing the linting from the dev task altogether and just having it run on CI? Perhaps something to be done part of adding Git hooks to ensure there's still some local checks before code reaches Github.
tasks/run.js
Outdated
const runTask = (name, args = []) => { | ||
const script = `${name} ${args.join(' ')}`.trim() | ||
|
||
// Create named runner | ||
// https://gulpjs.com/docs/en/api/task#task-metadata | ||
const runner = () => task(name, args) | ||
runner.displayName = `npm run ${script}` | ||
|
||
return runner | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused by the naming. From what I understand, this'll only run npm scripts, so maybe we should clarify this by renaming to runNpmScript
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind if I use the following?
Function for npm script
task()
→ npmScript()
Function for gulp task (that returns npm script)
runTask()
→ npmScriptTask()
tasks/run.js
Outdated
|
||
// Create named runner | ||
// https://gulpjs.com/docs/en/api/task#task-metadata | ||
const runner = () => task(name, args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a bit of naming collision there as this is not the task
function from Gulp, but our own from right above. We may want to rename that taskForNpmScript
for clarification, especially as it doesn't have the same signature as Gulp's task
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Gulp v4 tasks can be "a stream, promise, event emitter, child process, or observable"
I've flipped it the other way around (function that returns Promise<number>
)
const runner = () => task(name, args) | |
const task = () => npmScript(name, args) |
tasks/run.js
Outdated
* @returns {() => Promise<number>} Exit code | ||
*/ | ||
const runTask = (name, args = []) => { | ||
const script = `${name} ${args.join(' ')}`.trim() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe slightly nitpicky, but it seems that line is only used to generate the displayName
. I got confused by why it was computed early, but then not passed to task
down below, so I think it'd flow more clearly if it was right before the runner.displayName
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine, can put it all on the same line
// Add task alias
// https://gulpjs.com/docs/en/api/task#task-metadata
task.displayName = `npm run ${name} ${args.join(' ')}`.trim()
Improves compatibility on Windows/Linux/Mac for linting tools
Also includes `configPaths` consistency and JSDoc descriptions
f37d032
to
3a9d281
Compare
Also moves sassdoc into `gulp compile` sub tasks
Linting tasks no longer run before assets are built or tested
3a9d281
to
10d4581
Compare
@romaricpascal Mind taking another look? Can you give me an example of an ESLint error that blocks the JavaScript compile too? I tried a simple one here showing how we resolve (not reject) the npm script Promise for all exit codes [09:48:48] Starting 'scripts'...
[09:48:48] Starting 'npm run lint:js --silent'...
Server started at http://localhost:3000
/path/to/project/govuk-frontend/src/govuk/components/accordion/accordion.mjs
36:71 error Extra semicolon semi
✖ 1 problem (1 error, 0 warnings)
1 error and 0 warnings potentially fixable with the `--fix` option.
[09:48:49] Finished 'npm run lint:js --silent' after 1.28 s
[09:48:49] Starting 'js:compile'...
[09:48:51] Finished 'js:compile' after 1.64 s
[09:48:51] Finished 'scripts' after 2.92 s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give me an example of an ESLint error that blocks the JavaScript compile too?
I tried a simple one here showing how we resolve (not reject) the npm script Promise for all exit codes
Oh my bad, I missed that, sorry 😞 . Now it does work nicely with the scenario I described before 🙌🏻 Looks good to go for me 😄
This PR was related to #2243 |
This PR does a few things:
gulp copy-assets
→gulp compile
for claritygulp copy-files
togulp copy:files
for consistencyChanges to running npm scripts
For npm scripts in particular I've updated
runTask()
→npmScriptTask()
to work with GulpWhich keeps friendly task names formatted for the CLI too
When do linting tasks now run?
gulp dev
via watch taskOpen for feedback of course. Pairs up nicely with #2862 for a bit of a speed increase and closes #2855