-
Notifications
You must be signed in to change notification settings - Fork 339
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
Ensure shared task options
are mandatory unless specified
#3647
Changes from all commits
81f8421
1518cdb
4b9044a
aebb4a5
b464d62
aed596e
591311d
48f2b10
ab15994
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,7 @@ import gulp from 'gulp' | |
*/ | ||
export default (options) => gulp.series( | ||
task.name('clean', () => | ||
files.clean('*', { | ||
destPath: options.destPath | ||
}) | ||
files.clean('*', options) | ||
), | ||
|
||
// Copy GOV.UK Frontend static assets | ||
|
@@ -28,31 +26,33 @@ export default (options) => gulp.series( | |
// Compile GOV.UK Frontend JavaScript | ||
task.name('compile:js', () => | ||
scripts.compile('all.mjs', { | ||
...options, | ||
|
||
srcPath: join(options.srcPath, 'govuk'), | ||
destPath: options.destPath, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need to repeat ourselves. The destination is already in |
||
|
||
filePath (file) { | ||
return join(file.dir, `${file.name.replace(/^all/, pkg.name)}-${pkg.version}.min.js`) | ||
// Rename using package name (versioned) and `*.min.js` extension | ||
filePath ({ dir, name }) { | ||
return join(dir, `${name.replace(/^all/, pkg.name)}-${pkg.version}.min.js`) | ||
} | ||
}) | ||
), | ||
|
||
// Compile GOV.UK Frontend Sass | ||
task.name('compile:scss', () => | ||
styles.compile('**/[!_]*.scss', { | ||
...options, | ||
|
||
srcPath: join(options.srcPath, 'govuk'), | ||
destPath: options.destPath, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need to repeat ourselves. The destination is already in |
||
|
||
filePath (file) { | ||
return join(file.dir, `${file.name.replace(/^all/, pkg.name)}-${pkg.version}.min.css`) | ||
// Rename using package name (versioned) and `*.min.css` extension | ||
filePath ({ dir, name }) { | ||
return join(dir, `${name.replace(/^all/, pkg.name)}-${pkg.version}.min.css`) | ||
} | ||
}) | ||
), | ||
|
||
// Update GOV.UK Frontend version | ||
task.name("file:version 'VERSION.txt'", () => | ||
files.version('VERSION.txt', { | ||
destPath: options.destPath | ||
}) | ||
files.version('VERSION.txt', options) | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ export async function write (filePath, result) { | |
writeTasks.push(files.write(base, { | ||
destPath: dir, | ||
|
||
// Add source code | ||
async fileContents () { | ||
return code | ||
} | ||
|
@@ -47,6 +48,7 @@ export async function write (filePath, result) { | |
writeTasks.push(files.write(`${base}.map`, { | ||
destPath: dir, | ||
|
||
// Add source map as JSON | ||
async fileContents () { | ||
return JSON.stringify(map) | ||
} | ||
|
@@ -72,10 +74,10 @@ export async function write (filePath, result) { | |
* Asset path options | ||
* | ||
* @typedef {object} AssetPathOptions | ||
* @property {string} [basePath] - Base directory, for example `/path/to/package` | ||
* @property {string} [srcPath] - Input directory, for example `/path/to/package/src` | ||
* @property {string} [destPath] - Output directory, for example `/path/to/package/dist` | ||
* @property {string} [workspace] - Workspace directory (relative), for example `package/dist` | ||
* @property {string} basePath - Base directory, for example `/path/to/package` | ||
* @property {string} srcPath - Input directory, for example `/path/to/package/src` | ||
* @property {string} destPath - Output directory, for example `/path/to/package/dist` | ||
* @property {string} workspace - Workspace directory (relative), for example `package/dist` | ||
*/ | ||
|
||
/** | ||
|
@@ -84,7 +86,6 @@ export async function write (filePath, result) { | |
* @typedef {object} AssetFileOptions | ||
* @property {(file: import('path').ParsedPath) => string} [filePath] - File path formatter | ||
* @property {(contents?: string) => Promise<string>} [fileContents] - File contents formatter | ||
* @property {string[]} [ignore] - File path patterns to ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had to carefully ignore the published package.json and README.md in the past We haven't used this option since merging: |
||
*/ | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import { files } from './index.mjs' | |
* Generate fixtures.json from component data | ||
* | ||
* @param {AssetEntry[0]} pattern - Path to ${componentName}.yaml | ||
* @param {AssetEntry[1]} options - Asset options | ||
* @param {Pick<AssetEntry[1], "srcPath" | "destPath">} options - Asset options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This task already provides its own Here we're narrowing down the types to warn when passing in options that aren't picked |
||
*/ | ||
export async function generateFixtures (pattern, { srcPath, destPath }) { | ||
const componentDataPaths = await getListing(srcPath, pattern) | ||
|
@@ -22,15 +22,14 @@ export async function generateFixtures (pattern, { srcPath, destPath }) { | |
|
||
// Write to destination | ||
await files.write(componentDataPath, { | ||
srcPath, | ||
destPath, | ||
|
||
// Rename to fixtures.json | ||
filePath ({ dir }) { | ||
return join(dir, 'fixtures.json') | ||
}, | ||
|
||
// Replace contents with JSON | ||
// Add fixtures as JSON (formatted) | ||
async fileContents () { | ||
return JSON.stringify(fixture, null, 4) | ||
} | ||
|
@@ -44,7 +43,7 @@ export async function generateFixtures (pattern, { srcPath, destPath }) { | |
* Generate macro-options.json from component data | ||
* | ||
* @param {AssetEntry[0]} pattern - Path to ${componentName}.yaml | ||
* @param {AssetEntry[1]} options - Asset options | ||
* @param {Pick<AssetEntry[1], "srcPath" | "destPath">} options - Asset options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This task already provides its own Here we're narrowing down the types to warn when passing in options that aren't picked |
||
*/ | ||
export async function generateMacroOptions (pattern, { srcPath, destPath }) { | ||
const componentDataPaths = await getListing(srcPath, pattern) | ||
|
@@ -55,15 +54,14 @@ export async function generateMacroOptions (pattern, { srcPath, destPath }) { | |
|
||
// Write to destination | ||
await files.write(componentDataPath, { | ||
srcPath, | ||
destPath, | ||
|
||
// Rename to 'macro-options.json' | ||
filePath ({ dir }) { | ||
return join(dir, 'macro-options.json') | ||
}, | ||
|
||
// Replace contents with JSON | ||
// Add macro options as JSON (formatted) | ||
async fileContents () { | ||
return JSON.stringify(macroOption, null, 4) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { files } from './index.mjs' | |
* Write config to JSON | ||
* | ||
* @param {AssetEntry[0]} modulePath - File path to config | ||
* @param {AssetEntry[1]} options - Asset options | ||
* @param {Pick<AssetEntry[1], "srcPath" | "destPath">} options - Asset options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This task already provides its own Here we're narrowing down the types to warn when passing in options that aren't picked |
||
* @returns {Promise<void>} | ||
*/ | ||
export async function compile (modulePath, options) { | ||
|
@@ -17,7 +17,12 @@ export async function compile (modulePath, options) { | |
return files.write(modulePath, { | ||
...options, | ||
|
||
// Format config as JSON | ||
// Rename with `*.json` extension | ||
filePath ({ dir, name }) { | ||
return join(dir, `${name}.json`) | ||
}, | ||
|
||
// Add config as JSON (formatted) | ||
async fileContents () { | ||
return JSON.stringify(await configFn(), undefined, 2) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,25 +11,25 @@ import slash from 'slash' | |
* Delete path globs for a given destination | ||
* | ||
* @param {string} pattern - Pattern to remove | ||
* @param {AssetEntry[1]} options - Asset options | ||
* @param {Pick<AssetEntry[1], "destPath">} options - Asset options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The clean task only needs a Other properties can be passed in when not TypeScript |
||
*/ | ||
export async function clean (pattern, { destPath, ignore }) { | ||
export async function clean (pattern, { destPath }) { | ||
await deleteAsync(slash(join(destPath, pattern)), { | ||
cwd: paths.root, | ||
ignore | ||
cwd: paths.root | ||
}) | ||
} | ||
|
||
/** | ||
* Write `packages/govuk-frontend/package.json` version to file | ||
* | ||
* @param {AssetEntry[0]} assetPath - File path to asset | ||
* @param {AssetEntry[1]} options - Asset options | ||
* @param {Pick<AssetEntry[1], "destPath">} options - Asset options | ||
*/ | ||
export async function version (assetPath, options) { | ||
await write(assetPath, { | ||
...options, | ||
|
||
// Add package version | ||
async fileContents () { | ||
return pkg.version | ||
} | ||
|
@@ -40,13 +40,13 @@ export async function version (assetPath, options) { | |
* Write file task | ||
* | ||
* @param {AssetEntry[0]} assetPath - File path to asset | ||
* @param {AssetEntry[1]} options - Asset options | ||
* @param {Pick<AssetEntry[1], "destPath" | "filePath" | "fileContents">} options - Asset options | ||
*/ | ||
export async function write (assetPath, { destPath, filePath, fileContents }) { | ||
const assetDestPath = join(destPath, filePath ? filePath(parse(assetPath)) : assetPath) | ||
|
||
if (!fileContents) { | ||
throw new Error("Option 'fileContents' required") | ||
if (!destPath || !fileContents) { | ||
throw new Error("Options 'destPath' and 'fileContents' required") | ||
} | ||
|
||
await mkdir(dirname(assetDestPath), { recursive: true }) | ||
|
@@ -58,13 +58,10 @@ export async function write (assetPath, { destPath, filePath, fileContents }) { | |
* Copies files to destination | ||
* | ||
* @param {string} pattern - Minimatch pattern | ||
* @param {AssetEntry[1]} options - Asset options | ||
* @param {Pick<AssetEntry[1], "srcPath" | "destPath">} options - Asset options | ||
*/ | ||
export async function copy (pattern, { srcPath, destPath, ignore = [] }) { | ||
const srcPatterns = [slash(join(srcPath, pattern))] | ||
.concat(ignore.map((pattern) => `!${pattern}`)) | ||
|
||
await cpy(srcPatterns, destPath, { cwd: srcPath }) | ||
export async function copy (pattern, { srcPath, destPath }) { | ||
await cpy([slash(join(srcPath, pattern))], destPath, { cwd: srcPath }) | ||
} | ||
|
||
/** | ||
|
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'd accidentally put this in twice