-
Notifications
You must be signed in to change notification settings - Fork 0
Add ESLint configuration and refactor grefplus to use ES modules #169
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
base: master
Are you sure you want to change the base?
Changes from all commits
751ab5c
628cd6c
26ad0bc
97a6905
ed325f1
08d52cf
73d53f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
const { accessSync, constants, lstatSync } = require('fs'); | ||
const yargs = require('yargs'); | ||
const { DateTime } = require('luxon'); | ||
import { accessSync, constants, lstatSync } from 'node:fs'; | ||
import yargs from 'yargs/yargs'; | ||
import { DateTime } from 'luxon'; | ||
|
||
const options = { | ||
dateOptions: 'yyyy-MM-dd hh:mm:ss a' | ||
|
@@ -32,8 +32,7 @@ const cmdKeys = { | |
alias: 'r' | ||
, describe: 'root folder of development environment (/c/blah/blah). Default is DEVROOT' | ||
, type: 'array' | ||
// eslint-disable-next-line no-process-env | ||
, default: process.env.DEVROOT | ||
, default: [process.env.DEVROOT] | ||
} | ||
, 'date': { | ||
alias: 'd' | ||
|
@@ -46,13 +45,14 @@ const cmdKeys = { | |
/** | ||
* Validates from and to dates, | ||
* | ||
* @param {String} checkDate | ||
* @param {string} checkDate | ||
* @param {string} msg | ||
* @throws if date is not valid | ||
* @private | ||
*/ | ||
const validateDate = (checkDate, msg) => { | ||
try { | ||
const parsed = DateTime.fromFormat(checkDate, options.allowedFormat); | ||
const parsed = DateTime.fromFormat(checkDate.toString(), options.allowedFormat); | ||
if(!parsed.isValid) { | ||
throw new Error('unknown format'); | ||
} | ||
|
@@ -69,11 +69,11 @@ const validateDate = (checkDate, msg) => { | |
/** | ||
* Aborts build if dev root path does not exist | ||
* | ||
* @param {String} devRoot | ||
* @param {string[]} devRoot | ||
* @throws if path not accessible | ||
* @private | ||
*/ | ||
const validatePath = ({ devRoot }) => { | ||
const validatePath = (devRoot) => { | ||
let problematicRoot = null; | ||
|
||
devRoot.forEach(root => { | ||
|
@@ -108,24 +108,47 @@ const isFuture = (checkDate) => { | |
return _date > endOfToday; | ||
}; | ||
|
||
|
||
/** | ||
* | ||
* @param {string} argName | ||
* @param {boolean} [checkFuture] | ||
* @returns {boolean} | ||
* @throws if date is not valid | ||
*/ | ||
const validateArgDate = (argName, checkFuture) => { | ||
return (argv) => { | ||
const dt = `${argv[argName]}` || ''; | ||
if(dt) { | ||
validateDate(dt, `--${argName}`); | ||
if(checkFuture && isFuture(dt)) { | ||
throw new Error(`--${argName} cannot exceed current date`); | ||
} | ||
} | ||
return true; | ||
}; | ||
}; | ||
|
||
/** | ||
* Parse command line and configures options | ||
* | ||
* @param {Boolean} test - used for testing only | ||
* @param {Boolean} [test] - used for testing only | ||
*/ | ||
const setOptions = (test) => { | ||
const argv = test || yargs | ||
const argv = test || yargs(process.argv.slice(2)) | ||
// @ts-ignore | ||
.options(cmdKeys) | ||
Comment on lines
+138
to
+139
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. LGTM with a minor correction needed The updates to the
However, there's a small issue to address: There's a typo in one of the - .check(validateArgDate('fromDate', true))
+ .check(validateArgDate('toDate')) Please correct this to ensure proper validation of the 'toDate' argument. Also applies to: 164-178 |
||
.version(false) | ||
.help(true) | ||
.strict(true) | ||
.check((_argv) => { | ||
// super secret shortcut | ||
if(!_argv.date && !_argv.fromDate && !_argv.toDate && Number.isInteger(_argv._[0])) { | ||
const days = Number(_argv._[0]); | ||
const _date = DateTime | ||
.fromFormat(_argv._[0], options.allowedFormat) | ||
.plus({ days: _argv._[0] }) | ||
.format('MM/DD/YY'); | ||
.fromFormat(days.toString(), options.allowedFormat) | ||
.plus({ days }) | ||
.toFormat('MM/DD/YY'); | ||
_argv.date = _date; | ||
Comment on lines
+147
to
+151
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. Incorrect date calculation in shortcut The changes to the date shortcut calculation don't fully address the previous issue:
Here's a suggested fix: const days = Number(_argv._[0]);
const _date = DateTime
.now()
.plus({ days })
.toFormat(options.allowedFormat);
_argv.date = _date; This change:
This approach ensures correct date calculation and consistent formatting. |
||
} | ||
Comment on lines
+147
to
152
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. Logical Error: Incorrect date calculation in the shortcut The code attempts to parse Proposed fix: Start with the current date and add if(!_argv.date && !_argv.fromDate && !_argv.toDate && Number.isInteger(_argv._[0])) {
const days = Number(_argv._[0]);
const _date = DateTime
- .fromFormat(days.toString(), options.allowedFormat)
+ .now()
.plus({ days })
- .toFormat('MM/DD/YY');
+ .toFormat(options.allowedFormat);
_argv.date = _date;
} This change initializes the date from the current date and adds the specified number of days, then formats it using the allowed format.
|
||
else { | ||
|
@@ -138,53 +161,40 @@ const setOptions = (test) => { | |
} | ||
return true; | ||
}) | ||
.check(({ date }) => { | ||
if(date) { | ||
validateDate(date, '--date'); | ||
if(isFuture(date)) { | ||
throw new Error('--date cannot exceed current date'); | ||
} | ||
} | ||
return true; | ||
}) | ||
.check(({ fromDate }) => { | ||
if(fromDate) { | ||
validateDate(fromDate, '--from-date'); | ||
if(isFuture(fromDate)) { | ||
throw new Error('--from-date cannot exceed current date'); | ||
} | ||
} | ||
return true; | ||
}) | ||
.check(({ toDate }) => { | ||
if(toDate) { | ||
validateDate(toDate, '--to-date'); | ||
} | ||
return true; | ||
}) | ||
.check(({ folderNames }) => { | ||
.check(validateArgDate('date', true)) | ||
.check(validateArgDate('fromDate', true)) | ||
.check(validateArgDate('fromDate', true)) | ||
.check(validateArgDate('toDate')) | ||
.check((argv) => { | ||
const folderNames = Array.isArray(argv.folderNames) ? argv.folderNames : []; | ||
if(folderNames && !folderNames.length) { | ||
throw new Error('--folder-names requires at least one name'); | ||
} | ||
return true; | ||
}) | ||
.check(validatePath) | ||
.check(argv => { | ||
const devRoot = argv.devRoot; | ||
return validatePath(devRoot); | ||
}) | ||
.argv; | ||
|
||
// @ts-ignore | ||
if(argv.date) { | ||
// @ts-ignore | ||
const date = DateTime.fromFormat(argv.date, options.allowedFormat); | ||
module.exports.options.fromDate = date.startOf('day'); | ||
module.exports.options.toDate = date.endOf('day'); | ||
options.fromDate = date.startOf('day'); | ||
options.toDate = date.endOf('day'); | ||
} | ||
else { | ||
module.exports.options.fromDate = argv.fromDate ? DateTime.fromFormat(argv.fromDate, options.allowedFormat).startOf('day') : null; | ||
module.exports.options.toDate = argv.toDate ? DateTime.fromFormat(argv.toDate, options.allowedFormat).endOf('day') : null; | ||
// @ts-ignore | ||
options.fromDate = argv.fromDate ? DateTime.fromFormat(argv.fromDate, options.allowedFormat).startOf('day') : null; | ||
// @ts-ignore | ||
options.toDate = argv.toDate ? DateTime.fromFormat(argv.toDate, options.allowedFormat).endOf('day') : null; | ||
} | ||
module.exports.options.devRoot = argv.devRoot; | ||
module.exports.options.folderNames = argv.folderNames || []; | ||
// @ts-ignore | ||
options.devRoot = argv.devRoot; | ||
// @ts-ignore | ||
options.folderNames = argv.folderNames || []; | ||
}; | ||
|
||
module.exports = { | ||
options | ||
, setOptions | ||
}; | ||
export { options, setOptions }; |
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.
💡 Codebase verification
Incorrect path in
grefp
alias due to unset$DEVROOT
.src/alias.sh
to:🔗 Analysis chain
LGTM! The alias update aligns with the PR objectives.
The change from
grefp='node $DEVROOT/dev-tools/src/grefplus'
togrefp='node $DEVROOT/dev-tools/src/grefplus/index.mjs'
correctly reflects the transition to ES modules as mentioned in the PR objectives.To ensure this change doesn't introduce breaking changes, please run the following verification:
This script will verify the existence of the new file, check for ES module syntax, and attempt to run the
grefp
command.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 130
Script:
Length of output: 48
Script:
Length of output: 41