chore: replace fs-extra by fs when possible

pull/356/head
Romain 5 months ago
parent f65afab9eb
commit 6535caab7d

@ -1,6 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require('fs-extra') const fs = require('node:fs')
const moment = require('moment') const moment = require('moment')
const dependencies = require('../src/cli/dependencies') const dependencies = require('../src/cli/dependencies')
const messages = require('../src/cli/messages') const messages = require('../src/cli/messages')
@ -13,7 +13,7 @@ const args = process.argv.slice(2)
const opts = options.get(args) const opts = options.get(args)
// Only require the index after logging options have been set // Only require the index after logging options have been set
fs.mkdirpSync(opts.output) fs.mkdirSync(opts.output, { recursive: true })
require('./log').init(opts.log, opts.logFile) require('./log').init(opts.log, opts.logFile)
const index = require('../src/index') const index = require('../src/index')

@ -1,8 +1,8 @@
const EventEmitter = require('node:events') const EventEmitter = require('node:events')
const fs = require('node:fs')
const path = require('node:path') const path = require('node:path')
const _ = require('lodash') const _ = require('lodash')
const Database = require('better-sqlite3') const Database = require('better-sqlite3')
const fs = require('fs-extra')
const moment = require('moment') const moment = require('moment')
const delta = require('./delta') const delta = require('./delta')
const exiftool = require('../exiftool/parallel') const exiftool = require('../exiftool/parallel')
@ -13,7 +13,7 @@ const EXIF_DATE_FORMAT = 'YYYY:MM:DD HH:mm:ssZ'
class Index { class Index {
constructor (indexPath) { constructor (indexPath) {
// create the database if it doesn't exist // create the database if it doesn't exist
fs.mkdirpSync(path.dirname(indexPath)) fs.mkdirSync(path.dirname(indexPath), { recursive: true })
this.db = new Database(indexPath, {}) this.db = new Database(indexPath, {})
this.db.exec('CREATE TABLE IF NOT EXISTS files (path TEXT PRIMARY KEY, timestamp INTEGER, metadata BLOB)') this.db.exec('CREATE TABLE IF NOT EXISTS files (path TEXT PRIMARY KEY, timestamp INTEGER, metadata BLOB)')
} }

@ -1,5 +1,5 @@
const fs = require('node:fs')
const downsize = require('thumbsup-downsize') const downsize = require('thumbsup-downsize')
const fs = require('fs-extra')
exports.createMap = function (opts) { exports.createMap = function (opts) {
const thumbSize = opts.thumbSize || 120 const thumbSize = opts.thumbSize || 120
@ -37,7 +37,7 @@ exports.createMap = function (opts) {
hwaccel: opts.videoHwaccel hwaccel: opts.videoHwaccel
} }
return { return {
'fs:copy': (task, done) => fs.copy(task.src, task.dest, done), 'fs:copy': (task, done) => fs.copyFile(task.src, task.dest, done),
'fs:symlink': (task, done) => fs.symlink(task.src, task.dest, done), 'fs:symlink': (task, done) => fs.symlink(task.src, task.dest, done),
'photo:thumbnail': (task, done) => downsize.image(task.src, task.dest, thumbnail, done), 'photo:thumbnail': (task, done) => downsize.image(task.src, task.dest, thumbnail, done),
'photo:small': (task, done) => downsize.image(task.src, task.dest, small, done), 'photo:small': (task, done) => downsize.image(task.src, task.dest, small, done),

@ -1,5 +1,5 @@
const path = require('node:path') const path = require('node:path')
const fs = require('fs-extra') const fs = require('node:fs')
const debug = require('debug')('thumbsup:debug') const debug = require('debug')('thumbsup:debug')
const error = require('debug')('thumbsup:error') const error = require('debug')('thumbsup:error')
const info = require('debug')('thumbsup:info') const info = require('debug')('thumbsup:info')
@ -46,7 +46,7 @@ exports.create = function (files, opts, problems) {
dest, dest,
rel: f.output[out].rel, rel: f.output[out].rel,
action: (done) => { action: (done) => {
fs.mkdirsSync(path.dirname(dest)) fs.mkdirSync(path.dirname(dest), { recursive: true })
debug(`${f.output[out].rel} from ${src} to ${dest}`) debug(`${f.output[out].rel} from ${src} to ${dest}`)
return action({ src, dest }, err => { return action({ src, dest }, err => {
if (err) { if (err) {

@ -1,7 +1,8 @@
const fs = require('node:fs')
const path = require('node:path') const path = require('node:path')
const async = require('async') const async = require('async')
const debug = require('debug')('thumbsup:debug') const debug = require('debug')('thumbsup:debug')
const fs = require('fs-extra') const fsextra = require('fs-extra')
const handlebars = require('handlebars') const handlebars = require('handlebars')
const less = require('less') const less = require('less')
@ -62,7 +63,7 @@ class Theme {
const fullPath = path.join(this.dest, targetPath) const fullPath = path.join(this.dest, targetPath)
debug(`Theme rendering ${targetPath}`) debug(`Theme rendering ${targetPath}`)
const contents = this.template(data) const contents = this.template(data)
fs.mkdirpSync(path.dirname(fullPath)) fs.mkdirSync(path.dirname(fullPath), { recursive: true })
fs.writeFile(fullPath, contents, next) fs.writeFile(fullPath, contents, next)
} }
@ -114,7 +115,7 @@ class Theme {
if (err) return done(err) if (err) return done(err)
const filename = this.opts.stylesheetName || 'theme.css' const filename = this.opts.stylesheetName || 'theme.css'
const dest = path.join(this.dest, 'public', filename) const dest = path.join(this.dest, 'public', filename)
fs.mkdirpSync(path.join(this.dest, 'public')) fs.mkdirSync(path.join(this.dest, 'public'), { recursive: true })
fs.writeFile(dest, output.css, done) fs.writeFile(dest, output.css, done)
}) })
} }
@ -137,7 +138,7 @@ class Theme {
// copy all files in the <public> folder // copy all files in the <public> folder
const src = path.join(this.dir, 'public') const src = path.join(this.dir, 'public')
const dest = path.join(this.dest, 'public') const dest = path.join(this.dest, 'public')
fs.copy(src, dest, done) fsextra.copy(src, dest, done)
} }
} }

@ -1,6 +1,6 @@
const fs = require('node:fs')
const path = require('node:path') const path = require('node:path')
const _ = require('lodash') const _ = require('lodash')
const fs = require('fs-extra')
const moment = require('moment') const moment = require('moment')
const tmp = require('tmp') const tmp = require('tmp')
const File = require('../src/model/file') const File = require('../src/model/file')
@ -66,7 +66,8 @@ exports.fromDisk = function (filename) {
exports.createTempStructure = function (files) { exports.createTempStructure = function (files) {
const tmpdir = tmp.dirSync({ unsafeCleanup: true }).name const tmpdir = tmp.dirSync({ unsafeCleanup: true }).name
_.each(files, (content, filepath) => { _.each(files, (content, filepath) => {
fs.ensureFileSync(`${tmpdir}/${filepath}`) const folder = path.dirname(`${tmpdir}/${filepath}`)
fs.mkdirSync(folder, { recursive: true })
fs.writeFileSync(`${tmpdir}/${filepath}`, content) fs.writeFileSync(`${tmpdir}/${filepath}`, content)
}) })
return tmpdir return tmpdir

@ -1,5 +1,5 @@
const fs = require('node:fs')
const downsize = require('thumbsup-downsize') const downsize = require('thumbsup-downsize')
const fs = require('fs-extra')
const should = require('should/as-function') const should = require('should/as-function')
const sinon = require('sinon') const sinon = require('sinon')
const actions = require('../../src/steps/actions') const actions = require('../../src/steps/actions')
@ -11,7 +11,7 @@ const ANY_TASK = {
describe('actions', () => { describe('actions', () => {
beforeEach(() => { beforeEach(() => {
sinon.stub(fs, 'copy').yields(null) sinon.stub(fs, 'copyFile').yields(null)
sinon.stub(fs, 'symlink').yields(null) sinon.stub(fs, 'symlink').yields(null)
sinon.stub(downsize, 'image').yields(null) sinon.stub(downsize, 'image').yields(null)
sinon.stub(downsize, 'video').yields(null) sinon.stub(downsize, 'video').yields(null)
@ -19,7 +19,7 @@ describe('actions', () => {
}) })
afterEach(() => { afterEach(() => {
fs.copy.restore() fs.copyFile.restore()
fs.symlink.restore() fs.symlink.restore()
downsize.image.restore() downsize.image.restore()
downsize.video.restore() downsize.video.restore()
@ -31,7 +31,7 @@ describe('actions', () => {
const action = map['fs:copy'] const action = map['fs:copy']
action(ANY_TASK, err => { action(ANY_TASK, err => {
should(err).eql(null) should(err).eql(null)
sinon.assert.calledWith(fs.copy, sinon.assert.calledWith(fs.copyFile,
ANY_TASK.src, ANY_TASK.src,
ANY_TASK.dest, ANY_TASK.dest,
sinon.match.func sinon.match.func

@ -1,5 +1,5 @@
const path = require('node:path') const path = require('node:path')
const fs = require('fs-extra') const fs = require('node:fs')
const should = require('should/as-function') const should = require('should/as-function')
const fixtures = require('../fixtures') const fixtures = require('../fixtures')
const Theme = require('../../src/website/theme') const Theme = require('../../src/website/theme')

Loading…
Cancel
Save