Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 3 additions & 4 deletions lib/git.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cp = require('child_process');
const fs = require('node:fs');
const path = require('path');
const fs = require('fs-extra');

/**
* @function Object() { [native code] }
Expand Down Expand Up @@ -89,12 +89,11 @@ class Git {
* @return {Promise<Git>} A promise.
*/
static async clone(repo, dir, branch, options) {
const exists = await fs.exists(dir);
if (exists) {
if (fs.existsSync(dir)) {
return new Git(dir, options.git);
}

await fs.mkdirp(path.dirname(path.resolve(dir)));
fs.mkdirSync(path.dirname(path.resolve(dir)), {recursive: true});

const args = [
'clone',
Expand Down
11 changes: 6 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const fs = require('node:fs');
const fsp = require('node:fs/promises');
const path = require('path');
const util = require('util');
const filenamify = require('filenamify');
const findCacheDir = require('find-cache-dir');
const fs = require('fs-extra');
const tinyglobby = require('tinyglobby');
const Git = require('./git.js');
const copy = require('./util.js').copy;
Expand All @@ -28,7 +29,7 @@ function getCacheDir(optPath) {
* Clean the cache directory.
*/
exports.clean = function clean() {
fs.removeSync(getCacheDir());
fs.rmSync(getCacheDir(), {recursive: true, force: true});
};

exports.defaults = {
Expand Down Expand Up @@ -69,7 +70,7 @@ async function publishInternal(basePath, options) {
options.remove = options.only;
}

if (!(await fs.stat(basePath)).isDirectory()) {
if (!(await fsp.stat(basePath)).isDirectory()) {
throw new Error('The "base" option must be an existing directory');
}

Expand Down Expand Up @@ -133,12 +134,12 @@ async function publishInternal(basePath, options) {

if (options.nojekyll) {
log('Creating .nojekyll');
await fs.createFile(path.join(git.cwd, '.nojekyll'));
await fsp.writeFile(path.join(git.cwd, '.nojekyll'), '');
}

if (options.cname) {
log('Creating CNAME for %s', options.cname);
await fs.writeFile(path.join(git.cwd, 'CNAME'), options.cname);
await fsp.writeFile(path.join(git.cwd, 'CNAME'), options.cname);
}

log('Copying files');
Expand Down
6 changes: 3 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fsp = require('node:fs/promises');
const path = require('path');
const fs = require('fs-extra');
const Git = require('./git.js');

/**
Expand Down Expand Up @@ -49,8 +49,8 @@ exports.copy = async function (files, base, dest) {
const src = path.resolve(base, file);
const relative = path.relative(base, src);
const target = path.join(dest, relative);
await fs.ensureDir(path.dirname(target));
await fs.copy(src, target);
await fsp.mkdir(path.dirname(target), {recursive: true});
await fsp.copyFile(src, target);
}
};

Expand Down
41 changes: 5 additions & 36 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 @@ -38,7 +38,6 @@
"email-addresses": "^5.0.0",
"filenamify": "^4.3.0",
"find-cache-dir": "^3.3.1",
"fs-extra": "^11.1.1",
"tinyglobby": "^0.2.14"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('node:fs');
const path = require('path');
const chai = require('chai');
const compare = require('dir-compare').compareSync;
const fs = require('fs-extra');
const tmp = require('tmp');
const Git = require('../lib/git.js');

Expand Down Expand Up @@ -48,7 +48,7 @@ async function setupRepo(fixtureName, options) {
const userName = (options.user && options.user.name) || 'User Name';
const dir = await mkdtemp();
const fixturePath = path.join(fixtures, fixtureName, 'remote');
await fs.copy(fixturePath, dir);
fs.cpSync(fixturePath, dir, {recursive: true});

const git = new Git(dir);
await git.init();
Expand Down