Skip to content

Commit 9d2077f

Browse files
committed
refactor out fileExists service for package
1 parent 23cdb3b commit 9d2077f

File tree

23 files changed

+32
-70
lines changed

23 files changed

+32
-70
lines changed

lib/modules/editor/actions/file.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var fs_1 = require('fs');
3-
var exists_1 = require('../../../services/exists');
3+
var node_file_exists_1 = require('node-file-exists');
44
var editor_1 = require('./editor');
55
var openTimeout = 200;
66
function openFolder() {
@@ -14,13 +14,11 @@ exports.save = save;
1414
function open(filePath, options) {
1515
if (options === void 0) { options = {}; }
1616
return new Promise(function (resolve, reject) {
17-
if (exists_1.fileExists(filePath)) {
17+
if (node_file_exists_1.default(filePath)) {
1818
fs_1.unlink(filePath);
1919
}
2020
atom.workspace.open(filePath, options);
21-
setTimeout(function () {
22-
resolve();
23-
}, openTimeout);
21+
setTimeout(function () { return resolve(); }, openTimeout);
2422
});
2523
}
2624
exports.open = open;

lib/modules/setup/package-json/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"use strict";
22
var path_1 = require('path');
33
var fs_1 = require('fs');
4-
var exists_1 = require('../../../services/exists');
4+
var node_file_exists_1 = require('node-file-exists');
55
function packageJson(pj, action) {
66
if (pj === void 0) { pj = null; }
77
switch (action.type) {
88
case 'SETUP_PACKAGE':
99
var dir = action.payload.dir;
1010
var pathToPackageJson = path_1.join(dir, 'package.json');
11-
if (exists_1.fileExists(pathToPackageJson)) {
11+
if (node_file_exists_1.default(pathToPackageJson)) {
1212
return JSON.parse(fs_1.readFileSync(pathToPackageJson, 'utf8'));
1313
}
1414
return null;

lib/modules/tutorial/utils/config-paths.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var path_1 = require('path');
3-
var system_1 = require('../../../services/system');
3+
var system_1 = require('./system');
44
function configTestString(dir, name, config, testPath) {
55
if (system_1.isWindows) {
66
testPath = testPath.split('/').join('\\');
File renamed without changes.

lib/modules/tutorial/utils/tutorial-config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
var path_1 = require('path');
3-
var exists_1 = require('../../../services/exists');
4-
var system_1 = require('../../../services/system');
3+
var node_file_exists_1 = require('node-file-exists');
4+
var system_1 = require('./system');
55
function tutorialConfig(tutorialPj, dir) {
66
var config = tutorialPj.config, name = tutorialPj.name;
77
var repo = loadRepo(tutorialPj.repo);
@@ -28,11 +28,11 @@ function loadRunner(name, runner, dir) {
2828
var treeDep = path_1.join(dir, 'node_modules', name, 'node_modules', runner, 'package.json');
2929
var runnerMain;
3030
var runnerRoot;
31-
if (exists_1.fileExists(flatDep)) {
31+
if (node_file_exists_1.default(flatDep)) {
3232
runnerMain = require(flatDep).main;
3333
runnerRoot = flatDep;
3434
}
35-
else if (exists_1.fileExists(treeDep)) {
35+
else if (node_file_exists_1.default(treeDep)) {
3636
runnerMain = require(treeDep).main;
3737
runnerRoot = treeDep;
3838
}

lib/modules/tutorials/utils/check.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
var path_1 = require('path');
33
var fs_1 = require('fs');
4-
var exists_1 = require('../../../services/exists');
4+
var node_file_exists_1 = require('node-file-exists');
55
var is_tutorial_1 = require('./is-tutorial');
66
var update_1 = require('./update');
77
function searchForTutorials(dir, deps) {
@@ -10,7 +10,7 @@ function searchForTutorials(dir, deps) {
1010
.filter(function (name) { return is_tutorial_1.isTutorial(dir, name); })
1111
.map(function (name) {
1212
var pathToTutorialPackageJson = path_1.join(dir, 'node_modules', name, 'package.json');
13-
if (!exists_1.fileExists(pathToTutorialPackageJson)) {
13+
if (!node_file_exists_1.default(pathToTutorialPackageJson)) {
1414
console.log("Error with " + name + ": no package.json file found. " + is_tutorial_1.tutorialError);
1515
return {
1616
name: name,

lib/modules/tutorials/utils/is-tutorial.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use strict";
22
var path_1 = require('path');
33
var fs_1 = require('fs');
4-
var exists_1 = require('../../../services/exists');
4+
var node_file_exists_1 = require('node-file-exists');
55
exports.tutorialError = 'This is an error with the tutorial itself';
66
function isTutorial(dir, name) {
77
var pathToTutorialPackageJson = path_1.join(dir, 'node_modules', name, 'package.json');
8-
if (!exists_1.fileExists(pathToTutorialPackageJson)) {
8+
if (!node_file_exists_1.default(pathToTutorialPackageJson)) {
99
console.log("Error with " + name + ": no package.json file found. " + exports.tutorialError);
1010
return false;
1111
}
@@ -15,7 +15,7 @@ function isTutorial(dir, name) {
1515
return false;
1616
}
1717
var pathToCoderoadJson = path_1.join(dir, 'node_modules', name, packageJson.main);
18-
if (!exists_1.fileExists(pathToCoderoadJson)) {
18+
if (!node_file_exists_1.default(pathToCoderoadJson)) {
1919
console.log("Error with " + name + ": no coderoad.json file. " + exports.tutorialError);
2020
return false;
2121
}

lib/services/command-line.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"use strict";
2-
var exists_1 = require('./exists');
2+
var node_file_exists_1 = require('node-file-exists');
33
var child_process_1 = require('child_process');
44
function commandLine(root, commands) {
55
if (process.platform === 'darwin' && process.resourcesPath) {
66
var localPath = '/usr/local/bin/' + root;
77
var globalPath = '/usr/bin/' + root;
8-
if (exists_1.fileExists(localPath)) {
8+
if (node_file_exists_1.default(localPath)) {
99
root = localPath;
1010
}
11-
else if (exists_1.fileExists(globalPath)) {
11+
else if (node_file_exists_1.default(globalPath)) {
1212
root = globalPath;
1313
}
1414
else {

lib/services/exists.js

-17
This file was deleted.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"highlights": "1.3.1",
4242
"marked": "0.3.5",
4343
"material-ui": "0.15.0",
44+
"node-file-exists": "^1.0.0",
4445
"react": "15.0.2",
4546
"react-dom": "15.0.2",
4647
"react-redux": "4.4.5",

src/modules/editor/actions/file.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {unlink} from 'fs';
2-
import {fileExists} from '../../../services/exists';
2+
import fileExists from 'node-file-exists';
33
import {getEditor} from './editor';
44

55
// delay necessary since opening a file is slow
@@ -19,9 +19,8 @@ export function open(filePath: string, options = {}): Promise<any> {
1919
if (fileExists(filePath)) {
2020
unlink(filePath);
2121
}
22+
2223
atom.workspace.open(filePath, options);
23-
setTimeout(() => {
24-
resolve();
25-
}, openTimeout);
24+
setTimeout(() => resolve(), openTimeout);
2625
});
2726
}

src/modules/setup/deps.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ components: ContentCard
22

33
atom
44

5-
services: commandLine, exists
5+
services: commandLine
66

77
tutorials/searchForTutorials
8+
editor/{open, set, openFolder, openTerminal}

src/modules/setup/package-json/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {join} from 'path';
22
import {readFileSync} from 'fs';
3-
import {fileExists} from '../../../services/exists';
3+
import fileExists from 'node-file-exists';
44

55
export default function packageJson(
66
pj = null, action: Action

src/modules/tutorial/deps.md

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
services/system
2-
services/exists
3-
41
actions: progressLoad, routeSet

src/modules/tutorial/utils/config-paths.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {join} from 'path';
2-
import {isWindows} from '../../../services/system';
2+
import {isWindows} from './system';
33

44
function configTestString(
55
dir: string, name: string, config: Tutorial.Config, testPath: string
File renamed without changes.

src/modules/tutorial/utils/tutorial-config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {join} from 'path';
2-
import {fileExists} from '../../../services/exists';
3-
import {isWindows} from '../../../services/system';
2+
import fileExists from 'node-file-exists';
3+
import {isWindows} from './system';
44

55
export function tutorialConfig(
66
tutorialPj: PackageJson, dir: string

src/modules/tutorials/deps.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
services/exists
21
services/commandLine
32

43
actions: alertOpen, tutorialSet

src/modules/tutorials/utils/check.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {join} from 'path';
22
import {readFileSync} from 'fs';
3-
import {fileExists} from '../../../services/exists';
3+
import fileExists from 'node-file-exists';
44
import {isTutorial, tutorialError} from './is-tutorial';
55
import {canUpdateTutorial} from './update';
66

src/modules/tutorials/utils/is-tutorial.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {join} from 'path';
22
import {readFileSync} from 'fs';
3-
import {fileExists} from '../../../services/exists';
3+
import fileExists from 'node-file-exists';
44

55
export const tutorialError = 'This is an error with the tutorial itself';
66

src/services/command-line.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {fileExists} from './exists';
1+
import fileExists from 'node-file-exists';
22
import {exec} from 'child_process';
33

44
export default function commandLine(root: string,

src/services/exists.ts

-15
This file was deleted.

tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"src/modules/tutorial/reducer.ts",
120120
"src/modules/tutorial/types.ts",
121121
"src/modules/tutorial/utils/config-paths.ts",
122+
"src/modules/tutorial/utils/system.ts",
122123
"src/modules/tutorial/utils/tutorial-config.ts",
123124
"src/modules/tutorials/actions.ts",
124125
"src/modules/tutorials/index.ts",
@@ -133,9 +134,7 @@
133134
"src/modules/window/types.ts",
134135
"src/reducers.ts",
135136
"src/services/command-line.ts",
136-
"src/services/exists.ts",
137137
"src/services/polyfills.ts",
138-
"src/services/system.ts",
139138
"src/store.ts",
140139
"src/subscriptions.ts",
141140
"src/components/App.tsx",

0 commit comments

Comments
 (0)