Skip to content

Commit

Permalink
chore: migrate some scripts to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
C0ZEN committed Aug 3, 2022
1 parent a0d22b8 commit 8d4553b
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 131 deletions.
2 changes: 2 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ plugins:
- '.eslintcache'
- '!src/**/*.ts'
- '!src/**/*.js'
- '!src/**/*.mjs'
- '!tests/**/*.ts'
- '!scripts/**/*.ts'
- '!scripts/**/*.js'
- '!scripts/**/*.mjs'
exclude_patterns:
- '.cache/'
- '.cache-jest/'
Expand Down
11 changes: 3 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "typescript-sort-keys", "jest", "prettier", "progress", "jsdoc", "import", "typescript-sort-keys"],
"settings": {
"import/extensions": [".js", ".ts", ".tsx"],
"import/extensions": [".js", ".ts", ".tsx", ".mjs"],
"import/parsers": {
"@typescript-eslint/parser": [".ts"]
},
Expand All @@ -47,12 +47,7 @@
},
"rules": {
"@typescript-eslint/no-inferrable-types": "off",
"no-restricted-imports": [
"error",
{
"patterns": [".*"]
}
],
"no-restricted-imports": ["error"],
"progress/activate": 1,
"@typescript-eslint/member-ordering": [
"error",
Expand Down Expand Up @@ -459,7 +454,7 @@
},
"overrides": [
{
"files": ["*.js"],
"files": ["*.js", "*.mjs"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
"import/no-commonjs": "off"
Expand Down
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
*.htm text diff=html
*.html text diff=html
*.js text
*.mjs text
*.jsp text
*.jspf text
*.jspx text
Expand Down Expand Up @@ -146,6 +147,7 @@
*.inc text
*.ini text
*.js text
*.mjs text
*.json text
*.jsx text
*.less text
Expand Down
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
'test :test_tube:':
- src/**/*.spec.ts
- src/**/*.spec.js
- src/**/*.spec.mjs
- tests/**
- documentation/**/*.spec.ts
- documentation/**/*.spec.tsx
- documentation/**/*.spec.js
- documentation/**/*.spec.mjs

'CI :robot:':
- .github/workflows/**
Expand Down
2 changes: 1 addition & 1 deletion .idea/jsLinters/eslint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"*.{ts,js}": [
"*.{ts,js,mjs}": [
"npm run lint:ts:hook"
],
"*.{md,json,yml,html,mdx}": [
Expand Down
2 changes: 1 addition & 1 deletion documentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"write-heading-ids:changelog": "docusaurus write-heading-ids . docs/15-changelog.md",
"typecheck": "tsc",
"generate-files": "npm run generate-changelog",
"generate-changelog": "node ./scripts/generate-changelog.js"
"generate-changelog": "node scripts/generate-changelog.mjs"
},
"engines": {
"node": "16.15.1",
Expand Down
37 changes: 11 additions & 26 deletions documentation/scripts/chalk.js → documentation/scripts/chalk.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const CHALK_INSTANCE = require(`chalk`);
const CHALK = new CHALK_INSTANCE.Instance();
import { Chalk } from 'chalk';

const CHALK = new Chalk();
const COLOR_AURORA_GREEN = `#78E08F`;
const COLOR_BLUE_CARACAO = `#3DC1D3`;
const COLOR_DEEP_ROSE = `#C44569`;
Expand All @@ -15,92 +16,76 @@ const COLOR_SAWTOOTH_AAK = `#F19066`;
* @param {unknown} message The message to format
* @returns {string} The formatted message
*/
function success(message) {
export function success(message) {
return CHALK.hex(COLOR_AURORA_GREEN)(message);
}

module.exports.success = success;

/**
* @description
* Format a context message
* @param {unknown} message The message to format
* @returns {string} The formatted message
*/
function context(message) {
export function context(message) {
return CHALK.hex(COLOR_ROSY_HIGHLIGHT)(message);
}

module.exports.context = context;

/**
* @description
* Format a value message
* @param {unknown} message The message to format
* @returns {string} The formatted message
*/
function value(message) {
export function value(message) {
return CHALK.hex(COLOR_BLUE_CARACAO)(message);
}

module.exports.value = value;

/**
* @description
* Format an error message
* @param {unknown} message The message to format
* @returns {string} The formatted message
*/
function error(message) {
export function error(message) {
return CHALK.hex(COLOR_DEEP_ROSE)(message);
}

module.exports.error = error;

/**
* @description
* Format a warning message
* @param {unknown} message The message to format
* @returns {string} The formatted message
*/
function warning(message) {
export function warning(message) {
return CHALK.hex(COLOR_SAWTOOTH_AAK)(message);
}

module.exports.warning = warning;

/**
* @description
* Format a text message
* @param {unknown} message The message to format
* @returns {string} The formatted message
*/
function text(message) {
export function text(message) {
return CHALK.hex(COLOR_WHITE)(message);
}

module.exports.text = text;

/**
* @description
* Format a log message
* @param {unknown} message The message to format
* @returns {string} The formatted message
*/
function log(message) {
export function log(message) {
return CHALK.hex(COLOR_SOFT_BLUE)(message);
}

module.exports.log = log;

/**
* @description
* Format a debug message
* @param {unknown} message The message to format
* @returns {string} The formatted message
*/
function debug(message) {
export function debug(message) {
return CHALK.hex(COLOR_PURPLE_MOUNTAIN_MAJESTY)(message);
}

module.exports.debug = debug;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const CHALK = require(`./chalk`);
const FS = require(`fs-extra`);
const LOGGER = require(`./logger`);
// eslint-disable-next-line @typescript-eslint/naming-convention
const _ = require(`lodash`);
const { getDirectoryName } = require(`./get-directory-name`);
import * as CHALK from './chalk.mjs';
import { getDirectoryName } from './get-directory-name.mjs';
import * as LOGGER from './logger.mjs';
import FS from 'fs-extra';
import _ from 'lodash';
import { execSync } from 'child_process';

const CONTEXT = `generate-changelog`;
const { execSync } = require(`child_process`);
const CHANGELOG_PATH = `documentation/docs/15-changelog.md`;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const PATH = require(`path`);
import PATH from 'path';

/**
* @description
* Return the name of the directory of the given path
* @param {Readonly<string>} path The path to look into
* @returns {string} The name of the last directory from the given path
*/
function getDirectoryName(path) {
export function getDirectoryName(path) {
return PATH.basename(PATH.resolve(path));
}

module.exports.getDirectoryName = getDirectoryName;
39 changes: 18 additions & 21 deletions scripts/logger.js → documentation/scripts/logger.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
const CHALK = require(`./chalk`);
const MOMENT = require(`moment-timezone`);
// eslint-disable-next-line @typescript-eslint/naming-convention
const _ = require(`lodash`);
import * as CHALK from './chalk.mjs';
import _ from 'lodash';
import MOMENT from 'moment-timezone';

const LOG_PREFIX = `● `;
const LOG_TYPE_PREFIX_MAP = {
debug: () => CHALK.debug(LOG_PREFIX),
error: () => CHALK.error(LOG_PREFIX),
log: () => CHALK.log(LOG_PREFIX),
success: () => CHALK.success(LOG_PREFIX),
warning: () => CHALK.warning(LOG_PREFIX),
};

/**
* @description
* Format the given log type
* @param {Readonly<string>} logType The type of logger message
* @param {Readonly<'error' | 'warning' | 'success' | 'log' | 'debug'>} logType The type of logger message
* @returns {string} Return the formatted log type
*/
function getLogTypePrefix(logType) {
return CHALK[logType](LOG_PREFIX);
return LOG_TYPE_PREFIX_MAP[logType];
}

/**
Expand All @@ -34,56 +41,46 @@ function getContext(scope) {
* @param {Readonly<string>} scope The scope (usually the file name)
* @param {Readonly<string>} message The message to log
*/
function error(scope, message) {
export function error(scope, message) {
console.log(`${_.toString(getLogTypePrefix(`error`))}${getContext(scope)}${_.toString(message)}`);
}

module.exports.error = error;

/**
* @description
* Log a warning message
* @param {Readonly<string>} scope The scope (usually the file name)
* @param {Readonly<string>} message The message to log
*/
function warning(scope, message) {
export function warning(scope, message) {
console.log(`${_.toString(getLogTypePrefix(`warning`))}${getContext(scope)}${_.toString(message)}`);
}

module.exports.warning = warning;

/**
* @description
* Log a success message
* @param {Readonly<string>} scope The scope (usually the file name)
* @param {Readonly<string>} message The message to log
*/
function success(scope, message) {
export function success(scope, message) {
console.log(`${_.toString(getLogTypePrefix(`success`))}${getContext(scope)}${_.toString(message)}`);
}

module.exports.success = success;

/**
* @description
* Log a log message
* @param {Readonly<string>} scope The scope (usually the file name)
* @param {Readonly<string>} message The message to log
*/
function log(scope, message) {
export function log(scope, message) {
console.log(`${_.toString(getLogTypePrefix(`log`))}${getContext(scope)}${_.toString(message)}`);
}

module.exports.log = log;

/**
* @description
* Log a debug message
* @param {Readonly<string>} scope The scope (usually the file name)
* @param {Readonly<string>} message The message to log
*/
function debug(scope, message) {
export function debug(scope, message) {
console.log(`${_.toString(getLogTypePrefix(`debug`))}${getContext(scope)}${_.toString(message)}`);
}

module.exports.debug = debug;
22 changes: 18 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @description
* Return the Jest configuration for a given project
* @param {Readonly<string>} type The project type
* @returns {Object} The Jest configuration
* @returns {object} The Jest configuration
*/
const createProject = (type) => {
return {
Expand Down Expand Up @@ -86,7 +86,7 @@ const createProject = (type) => {
// modulePathIgnorePatterns: [],

// An array of file extensions your modules use
moduleFileExtensions: [`js`, `ts`, `tsx`],
moduleFileExtensions: [`js`, `ts`, `tsx`, `mjs`],

// A map from regular expressions to module names that allow to stub out resources with a single module
moduleNameMapper: {
Expand Down Expand Up @@ -226,24 +226,38 @@ function getTestMatch(type) {
`<rootDir>/tests/issues/**/*.spec.ts`,
`<rootDir>/tests/issues/**/*.spec.tsx`,
`<rootDir>/tests/issues/**/*.spec.js`,
`<rootDir>/tests/issues/**/*.spec.mjs`,
],
integrationIssuesCi: [
`<rootDir>/tests/issues/**/*.spec.ts`,
`<rootDir>/tests/issues/**/*.spec.tsx`,
`<rootDir>/tests/issues/**/*.spec.js`,
`<rootDir>/tests/issues/**/*.spec.mjs`,
],
integrationPullRequests: [
`<rootDir>/tests/pull-requests/**/*.spec.ts`,
`<rootDir>/tests/pull-requests/**/*.spec.tsx`,
`<rootDir>/tests/pull-requests/**/*.spec.js`,
`<rootDir>/tests/pull-requests/**/*.spec.mjs`,
],
integrationPullRequestsCi: [
`<rootDir>/tests/pull-requests/**/*.spec.ts`,
`<rootDir>/tests/pull-requests/**/*.spec.tsx`,
`<rootDir>/tests/pull-requests/**/*.spec.js`,
`<rootDir>/tests/pull-requests/**/*.spec.mjs`,
],
unit: [
`<rootDir>/src/**/*.spec.ts`,
`<rootDir>/src/**/*.spec.tsx`,
`<rootDir>/src/**/*.spec.js`,
`<rootDir>/src/**/*.spec.mjs`,
],
unitCi: [
`<rootDir>/src/**/*.spec.ts`,
`<rootDir>/src/**/*.spec.tsx`,
`<rootDir>/src/**/*.spec.js`,
`<rootDir>/src/**/*.spec.mjs`,
],
unit: [`<rootDir>/src/**/*.spec.ts`, `<rootDir>/src/**/*.spec.tsx`, `<rootDir>/src/**/*.spec.js`],
unitCi: [`<rootDir>/src/**/*.spec.ts`, `<rootDir>/src/**/*.spec.tsx`, `<rootDir>/src/**/*.spec.js`],
}[type];
}

Expand Down
Loading

0 comments on commit 8d4553b

Please sign in to comment.