Skip to content

Commit

Permalink
Convert scripts to ES modules
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Koops <[email protected]>
  • Loading branch information
jonkoops committed Aug 23, 2024
1 parent 2e6837e commit 0d273ee
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 64 deletions.
6 changes: 3 additions & 3 deletions .github/split.js → .github/split.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
import fs from 'node:fs';
import path from 'node:path';

const BASE_DIR = path.join(__dirname, '../packages/react-integration/cypress/integration');
const BASE_DIR = path.resolve(import.meta.dirname, '../packages/react-integration/cypress/integration');
const WORKER_NUM = +process.env.WORKER_NUM;
const WORKER_COUNT = +process.env.WORKER_COUNT;

Expand Down
7 changes: 4 additions & 3 deletions .github/upload-preview.js → .github/upload-preview.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-console, camelcase */
const path = require('path');
const { Octokit } = require('@octokit/rest');
import { Octokit } from '@octokit/rest';
import path from 'node:path';
import surge from 'surge';

const octokit = new Octokit({ auth: process.env.GH_PR_TOKEN });
const surge = require('surge');
const publishFn = surge().publish();

// From github actions
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:

- name: Upload documentation
if: always()
run: node .github/upload-preview.js packages/react-docs/public
run: node .github/upload-preview.mjs packages/react-docs/public

- name: Run accessibility tests
run: yarn serve:docs & yarn test:a11y

- name: Upload accessibility results
if: always()
run: node .github/upload-preview.js packages/react-docs/coverage
run: node .github/upload-preview.mjs packages/react-docs/coverage
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
run: printenv

- name: Run Cypress tests
run: yarn serve:integration & yarn test:integration -s $(node .github/split.js)
run: yarn serve:integration & yarn test:integration -s $(node .github/split.mjs)
env:
WORKER_NUM: ${{ matrix.worker }}
WORKER_COUNT: 5
2 changes: 1 addition & 1 deletion packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"build:single:packages": "node ../../scripts/build-single-packages.js --config single-packages.config.json",
"clean": "rimraf dist components layouts helpers next deprecated",
"generate": "node scripts/copyStyles.js",
"subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json",
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json",
"clean:exports": "node scripts/cleanDistExports.js"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"build:umd": "rollup -c --environment IS_PRODUCTION",
"build:single:packages": "node ../../scripts/build-single-packages.js --config single-packages.config.json",
"clean": "rimraf dist components deprecated",
"subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json"
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json"
},
"dependencies": {
"@patternfly/react-core": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build:umd": "rollup -c --environment IS_PRODUCTION",
"build:single:packages": "node ../../scripts/build-single-packages.js --config single-packages.config.json",
"clean": "rimraf dist components deprecated",
"subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json"
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json"
},
"dependencies": {
"@patternfly/react-core": "workspace:^",
Expand Down
12 changes: 0 additions & 12 deletions plopfile.js

This file was deleted.

12 changes: 12 additions & 0 deletions plopfile.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { setActionTypes } from './scripts/generators/actionTypes.mjs';
import { setHelpers } from './scripts/generators/helpers.mjs';
import setPFGenerators from './scripts/generators/patternfly-component/index.mjs';
import setPackageGenerators from './scripts/generators/package/index.mjs';

export default function (plop) {
setHelpers(plop);
setActionTypes(plop);

setPFGenerators(plop);
setPackageGenerators(plop);
}
8 changes: 4 additions & 4 deletions scripts/exportSubpaths.js → scripts/exportSubpaths.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable no-console */
const fse = require('fs-extra');
const path = require('path');
import fse from 'fs-extra';
import path from 'node:path';

const root = process.cwd();
const packageJson = require(`${root}/package.json`);
const packageJson = (await import(`${root}/package.json`, { with: { type: 'json' } })).default;

if (!(process.argv.includes('--config') && process.argv.indexOf('--config') + 1 < process.argv.length)) {
console.log('--config is required followed by the config file name');
process.exit(1);
}

const configJson = require(`${root}/${process.argv[process.argv.indexOf('--config') + 1]}`);
const configJson = (await import(`${root}/${process.argv[process.argv.indexOf('--config') + 1]}`, { with: { type: 'json' } })).default;

Check failure on line 13 in scripts/exportSubpaths.mjs

View workflow job for this annotation

GitHub Actions / Lint

Replace `await·import(`${root}/${process.argv[process.argv.indexOf('--config')·+·1]}`,·{·with:·{·type:·'json'·}·})` with `⏎··await·import(`${root}/${process.argv[process.argv.indexOf('--config')·+·1]}`,·{·with:·{·type:·'json'·}·})⏎`

if (!configJson.paths || configJson.paths.length === 0) {
console.log('directories are required');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path');
const fs = require('fs-extra');
import path from 'node:path';
import fs from 'fs-extra';

const ADD_TO_BARREL_FILE = 'addToBarrelFile';
export const ADD_TO_BARREL_FILE = 'addToBarrelFile';

function setActionTypes(plop) {
export function setActionTypes(plop) {
plop.setActionType(ADD_TO_BARREL_FILE, addToBarrelFile);
}

Expand All @@ -29,8 +29,3 @@ async function addToBarrelFile(answers, config, plop) {
await fs.outputFile(pathToFile, updatedLines.join('\n'));
return `-> ${pathToFile}`;
}

module.exports = {
setActionTypes,
ADD_TO_BARREL_FILE
};
10 changes: 0 additions & 10 deletions scripts/generators/helpers.js

This file was deleted.

5 changes: 5 additions & 0 deletions scripts/generators/helpers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const REMOVE_NPM_SCOPE = 'removeNPMScope';

export function setHelpers(plop) {
plop.setHelper(REMOVE_NPM_SCOPE, (text) => text.replace(/^@patternfly\//i, ''));
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { join, resolve } = require('path');
const { REMOVE_NPM_SCOPE } = require('../helpers');
import { join, resolve } from 'node:path';
import { REMOVE_NPM_SCOPE } from '../helpers.mjs';

const packagesRoot = resolve(__dirname, '../../../packages');
const packagesRoot = resolve(import.meta.dirname, '../../../packages');

function setPackageGenerators(plop) {
export default function setPackageGenerators(plop) {
plop.setGenerator('Package', {
description: 'A new package for the monorepo',
prompts: [
Expand All @@ -30,7 +30,7 @@ function setPackageGenerators(plop) {
{
type: 'add',
path: join(packageBaseTemplate, `package.json`),
templateFile: resolve(__dirname, './package.json.hbs')
templateFile: resolve(import.meta.dirname, './package.json.hbs')
},
{
type: 'add',
Expand All @@ -42,17 +42,17 @@ function setPackageGenerators(plop) {
answers.buildsWithTypescript && {
type: 'add',
path: join(packageBaseTemplate, `.npmignore`),
templateFile: resolve(__dirname, './.npmignore')
templateFile: resolve(import.meta.dirname, './.npmignore')
},
answers.buildsWithTypescript && {
type: 'add',
path: join(packageBaseTemplate, `tsconfig.json`),
templateFile: resolve(__dirname, './tsconfig.json')
templateFile: resolve(import.meta.dirname, './tsconfig.json')
},
answers.buildsWithTypescript && {
type: 'add',
path: join(packageBaseTemplate, `tsconfig.cjs.json`),
templateFile: resolve(__dirname, './tsconfig.cjs.json')
templateFile: resolve(import.meta.dirname, './tsconfig.cjs.json')
},
{
type: 'add',
Expand All @@ -63,5 +63,3 @@ function setPackageGenerators(plop) {
}
});
}

module.exports = setPackageGenerators;
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const { join, resolve } = require('path');
const { ADD_TO_BARREL_FILE } = require('../actionTypes');
import { join, resolve } from 'node:path';
import { ADD_TO_BARREL_FILE } from '../actionTypes.mjs';

const templatesDir = resolve(__dirname, './templates');
const reactCoreRoot = resolve(__dirname, '../../../packages/react-core');
const templatesDir = resolve(import.meta.dirname, './templates');
const reactCoreRoot = resolve(import.meta.dirname, '../../../packages/react-core');

const componentTypes = new Map([
['component', 'components'],
['layout', 'layouts'],
['internal', 'internal']
]);

function setPFGenerators(plop) {
export default function setPFGenerators(plop) {
plop.setGenerator('PatternFly Component', {
description: 'Component or Layout for PatternFly react-core package',
prompts: [
Expand Down Expand Up @@ -62,5 +62,3 @@ function setPFGenerators(plop) {
}
});
}

module.exports = setPFGenerators;

0 comments on commit 0d273ee

Please sign in to comment.