Skip to content

Commit cdf3c85

Browse files
committed
refactor: rename exists() to pathExists()
1 parent 4912ab4 commit cdf3c85

10 files changed

Lines changed: 35 additions & 35 deletions

File tree

lib/commands/docker/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import DockerBuilder from "#core/api/docker/builder";
22
import env from "#core/env";
3-
import { exists } from "#core/fs";
3+
import { pathExists } from "#core/fs";
44
import Command from "#lib/command";
55

66
export default class extends Command {
@@ -66,7 +66,7 @@ export default class extends Command {
6666
if ( !Array.isArray( composeFiles ) ) composeFiles = [ composeFiles ];
6767

6868
for ( const composeFile of composeFiles ) {
69-
if ( !( await exists( pkg.root + "/" + composeFile ) ) ) return result( [ 400, `Compose file "${ composeFile }" not found` ] );
69+
if ( !( await pathExists( pkg.root + "/" + composeFile ) ) ) return result( [ 400, `Compose file "${ composeFile }" not found` ] );
7070
}
7171

7272
for ( const composeFile of composeFiles ) {

lib/commands/git/install-hooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "node:fs";
22
import os from "node:os";
33
import path from "node:path";
44
import Git from "#core/api/git";
5-
import { chmodSync, exists } from "#core/fs";
5+
import { chmodSync, pathExists } from "#core/fs";
66
import * as utils from "#core/utils";
77
import Command from "#lib/command";
88

@@ -31,7 +31,7 @@ export default class extends Command {
3131
const { pkg, git, hooksPath } = res.data;
3232

3333
// create hooks dir
34-
if ( !( await exists( hooksPath ) ) ) {
34+
if ( !( await pathExists( hooksPath ) ) ) {
3535
fs.mkdirSync( hooksPath, {
3636
"recursive": true,
3737
} );

lib/commands/git/pre-commit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from "node:fs";
22
import File from "#core/file";
3-
import { exists } from "#core/fs";
3+
import { pathExists } from "#core/fs";
44
import { glob } from "#core/glob";
55
import Command from "#lib/command";
66
import Git from "#lib/git";
@@ -170,7 +170,7 @@ export default class extends Command {
170170
if ( !res1.ok ) throw result( [ 500, "Unable to update git index" ] );
171171

172172
// update working tree, if file wasn't modified after add and wasn't removed
173-
if ( !modified[ filename ] && ( await exists( filename ) ) ) {
173+
if ( !modified[ filename ] && ( await pathExists( filename ) ) ) {
174174
fs.writeFileSync( filename, res.data );
175175
}
176176
}

lib/commands/git/remove-hooks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "node:fs";
22
import os from "node:os";
33
import path from "node:path";
44
import Git from "#core/api/git";
5-
import { exists } from "#core/fs";
5+
import { pathExists } from "#core/fs";
66
import Command from "#lib/command";
77

88
export default class extends Command {
@@ -30,7 +30,7 @@ export default class extends Command {
3030
const { git, hooksPath, hooksPathInstalled } = res.data;
3131

3232
// remove "pre-commit" hook
33-
if ( await exists( path.join( hooksPath, "pre-commit" ) ) ) {
33+
if ( await pathExists( path.join( hooksPath, "pre-commit" ) ) ) {
3434
fs.rmSync( path.join( hooksPath, "pre-commit" ) );
3535
console.log( `Git "pre-commit" hook removed` );
3636
}
@@ -39,7 +39,7 @@ export default class extends Command {
3939
}
4040

4141
// remove "commit-msg" hook
42-
if ( await exists( path.join( hooksPath, "commit-msg" ) ) ) {
42+
if ( await pathExists( path.join( hooksPath, "commit-msg" ) ) ) {
4343
fs.rmSync( path.join( hooksPath, "commit-msg" ) );
4444
console.log( `Git "commit-msg" hook removed` );
4545
}

lib/commands/package/link.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import childProcess from "node:child_process";
22
import fs from "node:fs";
33
import path from "node:path";
44
import { readConfig } from "#core/config";
5-
import { exists } from "#core/fs";
5+
import { pathExists } from "#core/fs";
66
import { glob } from "#core/glob";
77
import { shellQuote } from "#core/utils";
88
import Command from "#lib/command";
@@ -120,7 +120,7 @@ export default class extends Command {
120120
if ( !process.cli.options[ "dry-run" ] ) {
121121

122122
// create node_modules
123-
if ( !( await exists( pkg.root + "/node_modules/" + path.dirname( dep.name ) ) ) ) {
123+
if ( !( await pathExists( pkg.root + "/node_modules/" + path.dirname( dep.name ) ) ) ) {
124124
fs.mkdirSync( pkg.root + "/node_modules/" + path.dirname( dep.name ), {
125125
"recursive": true,
126126
} );
@@ -140,7 +140,7 @@ export default class extends Command {
140140
}
141141

142142
// remove node modules
143-
if ( dep.removeNodeModules && ( await exists( dep.path + "/node_modules" ) ) ) {
143+
if ( dep.removeNodeModules && ( await pathExists( dep.path + "/node_modules" ) ) ) {
144144
console.log( `Remove "node_modules" for package: ${ dep.name }` );
145145

146146
if ( !process.cli.options[ "dry-run" ] ) {

lib/debian-repository.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { readConfigSync } from "#core/config";
1212
import ejs from "#core/ejs";
1313
import env from "#core/env";
1414
import File from "#core/file";
15-
import { exists } from "#core/fs";
15+
import { pathExists } from "#core/fs";
1616
import { glob, globSync } from "#core/glob";
1717
import SemanticVersion from "#core/semantic-version";
1818
import tar from "#core/tar";
@@ -75,7 +75,7 @@ export default class DebianRepository {
7575
var res;
7676

7777
// check dists
78-
if ( !( await exists( this.distsRoot ) ) ) {
78+
if ( !( await pathExists( this.distsRoot ) ) ) {
7979
const git = new Git( this.root ),
8080
upstream = git.upstream;
8181

lib/package.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { readConfig, readConfigSync, writeConfigSync } from "#core/config";
88
import env from "#core/env";
99
import File from "#core/file";
1010
import FileTree from "#core/file-tree";
11-
import { calculateMode, chmodSync, exists } from "#core/fs";
11+
import { calculateMode, chmodSync, pathExists, pathExistsSync } from "#core/fs";
1212
import { glob, globSync } from "#core/glob";
1313
import GlobPatterns from "#core/glob/patterns";
1414
import Locale from "#core/locale";
@@ -130,7 +130,7 @@ export default class Package {
130130
}
131131

132132
get hasDockerfile () {
133-
return fs.existsSync( this.root + "/dockerfile" ) || fs.existsSync( this.root + "/Dockerfile" );
133+
return pathExistsSync( this.root + "/dockerfile" ) || pathExistsSync( this.root + "/Dockerfile" );
134134
}
135135

136136
get git () {
@@ -305,11 +305,11 @@ export default class Package {
305305
}
306306

307307
get hasPackageLock () {
308-
return fs.existsSync( this.root + "/package-lock.json" );
308+
return pathExistsSync( this.root + "/package-lock.json" );
309309
}
310310

311311
get hasNpmShrinkwrap () {
312-
return fs.existsSync( this.root + "/npm-shrinkwrap.json" );
312+
return pathExistsSync( this.root + "/npm-shrinkwrap.json" );
313313
}
314314

315315
get dependencies () {
@@ -330,23 +330,23 @@ export default class Package {
330330
writeConfigSync( root + "/package.json", pkg, { "readable": true } );
331331

332332
// update npm-shrinkwrap.json
333-
if ( fs.existsSync( root + "/npm-shrinkwrap.json" ) ) {
333+
if ( pathExistsSync( root + "/npm-shrinkwrap.json" ) ) {
334334
const data = readConfigSync( root + "/npm-shrinkwrap.json" );
335335
data.version = version;
336336
if ( data.packages && data.packages[ "" ] ) data.packages[ "" ].version = version;
337337
writeConfigSync( root + "/npm-shrinkwrap.json", data, { "readable": true } );
338338
}
339339

340340
// update package-lock.json
341-
if ( fs.existsSync( root + "/package-lock.json" ) ) {
341+
if ( pathExistsSync( root + "/package-lock.json" ) ) {
342342
const data = readConfigSync( root + "/package-lock.json" );
343343
data.version = version;
344344
if ( data.packages && data.packages[ "" ] ) data.packages[ "" ].version = version;
345345
writeConfigSync( root + "/package-lock.json", data, { "readable": true } );
346346
}
347347

348348
// update cordova config.xml
349-
if ( fs.existsSync( root + "/config.xml" ) ) {
349+
if ( pathExistsSync( root + "/config.xml" ) ) {
350350
var xml = fs.readFileSync( root + "/config.xml", "utf8" ),
351351
replaced;
352352

@@ -1370,12 +1370,12 @@ export default class Package {
13701370
config,
13711371
updates = new Map();
13721372

1373-
if ( await exists( this.root + "/.github/dependabot.yaml" ) ) {
1373+
if ( await pathExists( this.root + "/.github/dependabot.yaml" ) ) {
13741374
filename = "dependabot.yaml";
13751375

13761376
config = await readConfig( this.root + "/.github/dependabot.yaml" );
13771377
}
1378-
else if ( await exists( this.root + "/.github/dependabot.yml" ) ) {
1378+
else if ( await pathExists( this.root + "/.github/dependabot.yml" ) ) {
13791379
filename = "dependabot.yml";
13801380

13811381
config = await readConfig( this.root + "/.github/dependabot.yml" );
@@ -1454,7 +1454,7 @@ export default class Package {
14541454
}
14551455

14561456
if ( !updates.size ) {
1457-
if ( await exists( this.root + "/.github" ) ) {
1457+
if ( await pathExists( this.root + "/.github" ) ) {
14581458
await fs.promises.rm( this.root + "/.github/" + filename, {
14591459
"force": true,
14601460
} );

lib/package/docs.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ejs from "#core/ejs";
77
import env from "#core/env";
88
import File from "#core/file";
99
import FileTree from "#core/file-tree";
10-
import { exists } from "#core/fs";
10+
import { pathExists, pathExistsSync } from "#core/fs";
1111
import { glob } from "#core/glob";
1212
import * as utils from "#core/utils";
1313
import { resolve } from "#core/utils";
@@ -48,7 +48,7 @@ export default class Docs {
4848
}
4949

5050
get isInitialized () {
51-
return Boolean( this.isEnabled && fs.existsSync( this.locationPath ) );
51+
return Boolean( this.isEnabled && pathExistsSync( this.locationPath ) );
5252
}
5353

5454
// public
@@ -123,7 +123,7 @@ export default class Docs {
123123
const fileTree = new FileTree();
124124

125125
// generate README.md
126-
if ( !( await exists( this.locationPath + "/README.md" ) ) ) {
126+
if ( !( await pathExists( this.locationPath + "/README.md" ) ) ) {
127127
const readmeTmpl = utils.resolve( "#resources/templates/docs/README-default.md", import.meta.url );
128128

129129
if ( this.location !== "/" ) {
@@ -137,7 +137,7 @@ export default class Docs {
137137
else {
138138

139139
// copy root readme
140-
if ( await exists( this.#package.root + "/README.md" ) ) {
140+
if ( await pathExists( this.#package.root + "/README.md" ) ) {
141141
fileTree.add( {
142142
"path": "README.md",
143143
"buffer": fs.readFileSync( this.#package.root + "/README.md" ),
@@ -155,7 +155,7 @@ export default class Docs {
155155
}
156156

157157
// generate default sidebar
158-
if ( !( await exists( this.locationPath + "/_sidebar.md" ) ) ) {
158+
if ( !( await pathExists( this.locationPath + "/_sidebar.md" ) ) ) {
159159
fileTree.add( {
160160
"path": "_sidebar.md",
161161
"buffer": await ejs.renderFile( utils.resolve( "#resources/templates/docs/_sidebar.md", import.meta.url ), options ),
@@ -248,7 +248,7 @@ export default class Docs {
248248
async #buildReadme ( options ) {
249249
const readmePath = this.locationPath + "/README.md";
250250

251-
if ( this.location === "/" || options.generateReadme === false || !( await exists( readmePath ) ) ) return;
251+
if ( this.location === "/" || options.generateReadme === false || !( await pathExists( readmePath ) ) ) return;
252252

253253
const template = utils.resolve( "#resources/templates/docs/README-wrapper.md.ejs", import.meta.url ),
254254
fileTree = new FileTree();

lib/package/localization.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from "node:path";
33
import url from "node:url";
44
import CloudTranslationApi from "#core/api/google/cloud/translation";
55
import env from "#core/env";
6-
import { exists } from "#core/fs";
6+
import { pathExists } from "#core/fs";
77
import { glob, globSync } from "#core/glob";
88
import GlobPatterns from "#core/glob/patterns";
99
import PoFile from "#core/locale/po-file";
@@ -103,7 +103,7 @@ export default class {
103103

104104
// find po file nearest package
105105
while ( true ) {
106-
if ( await exists( poFilePackageRoot + "/package.json" ) ) break;
106+
if ( await pathExists( poFilePackageRoot + "/package.json" ) ) break;
107107

108108
const parent = path.dirname( poFilePackageRoot );
109109
if ( parent === poFilePackageRoot ) break;
@@ -207,7 +207,7 @@ export default class {
207207
async #initTranslationMemory () {
208208
const location = url.pathToFileURL( env.getDataDir( "softvisio-cli" ) + "/translation-memory.sqlite" );
209209

210-
if ( !( await exists( path.dirname( url.fileURLToPath( location ) ) ) ) ) {
210+
if ( !( await pathExists( path.dirname( url.fileURLToPath( location ) ) ) ) ) {
211211
fs.mkdirSync( path.dirname( url.fileURLToPath( location ) ), {
212212
"recursive": true,
213213
} );

lib/package/release.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ansi from "#core/ansi";
55
import GitHub from "#core/api/github";
66
import env from "#core/env";
77
import File from "#core/file";
8-
import { exists } from "#core/fs";
8+
import { pathExists } from "#core/fs";
99
import SemanticVersion from "#core/semantic-version";
1010
import { TmpFile } from "#core/tmp";
1111
import { confirm, repeatAction, shellQuote } from "#core/utils";
@@ -416,7 +416,7 @@ ${ this.#changelog.linkifyMarkdown( changelogMarkdown ) }
416416
`.trim();
417417

418418
// patch CHANGELOG.md
419-
if ( await exists( this.#pkg.root + "/CHANGELOG.md" ) ) {
419+
if ( await pathExists( this.#pkg.root + "/CHANGELOG.md" ) ) {
420420
fullChangelog +=
421421
"\n" +
422422
fs

0 commit comments

Comments
 (0)