Skip to content

Commit

Permalink
chore: remove fs-extra dependency
Browse files Browse the repository at this point in the history
Manual rebase of #147.

Co-authored-by: Jeroen Engels <jfm.engels@gmail.com>
  • Loading branch information
lishaduck and jfmengels committed Nov 10, 2024
1 parent 692b52e commit 6f5fba8
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 94 deletions.
19 changes: 19 additions & 0 deletions lib/fs-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @import {Replacer, Reviver} from './types/json';
* @import {Path} from './types/path';
*/
const path = require('node:path');
const fs = require('graceful-fs');
const fsp = fs.promises;

Expand Down Expand Up @@ -95,6 +96,21 @@ async function remove(file) {
);
}

/**
* Copy files from srcFolder to destFolder.
* @param {Path} srcFolder
* @param {Path} destFolder
* @param {Path[]} files
* @returns {Promise<void>}
*/
async function copyFiles(srcFolder, destFolder, files) {
const promises = files.map(async (file) => {
await fsp.copyFile(path.join(srcFolder, file), path.join(destFolder, file));
});

await Promise.all(promises);
}

module.exports = {
readFile,
readJsonFile,
Expand All @@ -106,6 +122,9 @@ module.exports = {
mkdirp,
mkdirpSync,

// TODO(@lishaduck) [engine:node@>=16.7.0]: Use native `cp`.
copyFiles,

remove,

readdir: fsp.readdir,
Expand Down
4 changes: 1 addition & 3 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

const path = require('node:path');
const fs = require('graceful-fs');
// TODO(@lishaduck) [engine:node@>=16.7.0]: Use native `cp`.
const fsExtra = require('fs-extra');
const chalk = require('chalk');
const prompts = require('prompts');
const FS = require('./fs-wrapper');
Expand Down Expand Up @@ -197,7 +195,7 @@ async function createElmJson(options, directory) {
* @returns {void}
*/
function createReviewConfig(directory, template) {
fsExtra.copyFileSync(
fs.copyFileSync(
path.join(__dirname, '../init-templates/', template),
path.join(directory, 'ReviewConfig.elm')
);
Expand Down
34 changes: 19 additions & 15 deletions lib/new-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
const childProcess = require('node:child_process');
const path = require('node:path');
const chalk = require('chalk');
// TODO(@lishaduck) [engine:node@>=16.7.0]: Use native `cp`.
const fsExtra = require('fs-extra');
const prompts = require('prompts');
const ErrorMessage = require('./error-message');
const FS = require('./fs-wrapper');
Expand Down Expand Up @@ -293,10 +291,15 @@ ElmjutsuDumMyM0DuL3.elm
);

Spinner.succeedAndNowDo('Adding GitHub Actions');
await fsExtra.copy(
const githubDestFiles = path.join(dir, '.github/');
await Promise.all([
FS.mkdirp(path.join(githubDestFiles, 'ISSUE_TEMPLATE')),
FS.mkdirp(path.join(githubDestFiles, 'workflows'))
]);
await FS.copyFiles(
path.join(__dirname, '../new-package/github/'),
path.join(dir, '.github/'),
{overwrite: true}
githubDestFiles,
['ISSUE_TEMPLATE/new-rule-idea.md', 'workflows/test.yml']
);

Spinner.succeedAndNowDo(
Expand Down Expand Up @@ -334,26 +337,27 @@ ElmjutsuDumMyM0DuL3.elm
Spinner.succeedAndNowDo('Adding maintenance scripts');
const maintenancePath = path.join(process.cwd(), packageName, 'maintenance');
await FS.mkdirp(maintenancePath);
await fsExtra.copy(
await FS.copyFiles(
path.join(__dirname, '../new-package/maintenance/'),
maintenancePath,
{
overwrite: true
}
['MAINTENANCE.md', 'update-examples-from-preview.js']
);

const packageTests = path.join(
process.cwd(),
packageName,
'elm-review-package-tests'
);
await FS.mkdirp(packageTests);
await fsExtra.copy(
path.join(__dirname, '../new-package/elm-review-package-tests/'),
FS.mkdirpSync(path.join(packageTests, 'helpers'));
await FS.copyFiles(
path.join(__dirname, '../new-package/elm-review-package-tests'),
packageTests,
{
overwrite: true
}
[
'check-previews-compile.js',
'check-examples-were-updated.js',
'helpers/ansi.js',
'helpers/find-configurations.js'
]
);

const checkPreviewsCompile = path.join(
Expand Down
7 changes: 6 additions & 1 deletion new-package/maintenance/update-examples-from-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ function copyPreviewToExample(pathToPreviewFolder) {
/preview/g,
'example'
);
fs.removeSync(pathToExampleFolder);

fs.rmSync(pathToExampleFolder, {
recursive: true,
force: true,
maxRetries: 10
});
fs.copySync(pathToPreviewFolder, pathToExampleFolder, {overwrite: true});

const pathToElmJson = path.resolve(pathToExampleFolder, 'elm.json');
Expand Down
72 changes: 0 additions & 72 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"fastest-levenshtein": "^1.0.16",
"find-up": "^4.1.0 || ^5.0.0",
"folder-hash": "^3.3.0",
"fs-extra": "^9.0.0",
"glob": "^10.2.6",
"got": "^11.8.5",
"graceful-fs": "^4.2.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ function copyPreviewToExample(pathToPreviewFolder) {
/preview/g,
'example'
);
fs.removeSync(pathToExampleFolder);

fs.rmSync(pathToExampleFolder, {
recursive: true,
force: true,
maxRetries: 10
});
fs.copySync(pathToPreviewFolder, pathToExampleFolder, {overwrite: true});

const pathToElmJson = path.resolve(pathToExampleFolder, 'elm.json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ function copyPreviewToExample(pathToPreviewFolder) {
/preview/g,
'example'
);
fs.removeSync(pathToExampleFolder);

fs.rmSync(pathToExampleFolder, {
recursive: true,
force: true,
maxRetries: 10
});
fs.copySync(pathToPreviewFolder, pathToExampleFolder, {overwrite: true});

const pathToElmJson = path.resolve(pathToExampleFolder, 'elm.json');
Expand Down

0 comments on commit 6f5fba8

Please sign in to comment.