Skip to content
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

Example fs-extra #100

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions chapter-03/examples/npm/fs-extra.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
'use strict';

const mkdirp = require('mkdirp');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vu que tu utilises fs.mkdirp, cette dépendance n'est plus nécessaire.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh merci, un bel exemple de cargo culte 😉

const rm = require('rimraf');
const { join } = require('path');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L'intention initiale c'est de copier le répertoire contenant le script fs-extra.js dans /tmp/nodebook-examples.

const fs = require('fs-extra');

fs.copy(__dirname, '/tmp/nodebook-examples', (err) => {
const dirpath = join(__dirname, '..', '..', 'tmp', 'nodebook-examples');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du coup cette ligne change l'emplacement de copie.

Ce qui est un plus je pense car /tmp/nodebook-examples ne fonctionnerait pas sous Windows.

On est bien d'accord que tu veux copier vers la racine du repo ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oui, j'ai gardé la même logique que le script mkdirp


fs.ensureDir(dirpath, function (err) {
if (err) {
return console.error('Une erreur s\'est produite.', err);
fs.mkdirp(dirpath);
console.log('Dossier crée :', dirpath);
}
})

rm(dirpath, () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs-extra contient une méthode .remove() qui rend l'inclusion de rimraf superflue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top, je vais refactoriser ça.

fs.copy(__dirname, dirpath, (err) => {
if (err) {
return console.error('Une erreur s\'est produite.', err);
}
else {
return console.log('Dossier copié : ', dirpath);
}
});
});