Skip to content

Commit ce93e02

Browse files
committed
Fix comments.
1 parent 82641ad commit ce93e02

File tree

2 files changed

+29
-36
lines changed

2 files changed

+29
-36
lines changed

lib/commands/update.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as path from "path";
2-
import * as shelljs from "shelljs";
32

43
export class UpdateCommand implements ICommand {
54
public allowedParameters: ICommandParameter[] = [];
@@ -25,7 +24,7 @@ export class UpdateCommand implements ICommand {
2524
this.backup(tmpDir);
2625
} catch (error) {
2726
this.$logger.error("Could not backup project folders!");
28-
shelljs.rm("-fr", tmpDir);
27+
this.$fs.deleteDirectory(tmpDir);
2928
return;
3029
}
3130

@@ -35,7 +34,7 @@ export class UpdateCommand implements ICommand {
3534
this.restoreBackup(tmpDir);
3635
this.$logger.error("Could not update the project!");
3736
} finally {
38-
shelljs.rm("-fr", tmpDir);
37+
this.$fs.deleteDirectory(tmpDir);
3938
}
4039
}
4140

@@ -64,7 +63,7 @@ export class UpdateCommand implements ICommand {
6463
await this.$pluginsService.remove("tns-core-modules-widgets", this.$projectData);
6564

6665
for (const folder of this.folders) {
67-
shelljs.rm("-rf", path.join(this.$projectData.projectDir, folder));
66+
this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, folder));
6867
}
6968

7069
if (args.length === 1) {
@@ -101,26 +100,26 @@ export class UpdateCommand implements ICommand {
101100
}
102101

103102
private restoreBackup(tmpDir: string): void {
104-
shelljs.cp("-f", path.join(tmpDir, "package.json"), this.$projectData.projectDir);
103+
this.$fs.copyFile(path.join(tmpDir, "package.json"), this.$projectData.projectDir);
105104
for (const folder of this.folders) {
106-
shelljs.rm("-rf", path.join(this.$projectData.projectDir, folder));
105+
this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, folder));
107106

108107
const folderToCopy = path.join(tmpDir, folder);
109108

110109
if (this.$fs.exists(folderToCopy)) {
111-
shelljs.cp("-fr", folderToCopy, this.$projectData.projectDir);
110+
this.$fs.copyFile(folderToCopy, this.$projectData.projectDir);
112111
}
113112
}
114113
}
115114

116115
private backup(tmpDir: string): void {
117-
shelljs.rm("-fr", tmpDir);
118-
shelljs.mkdir(tmpDir);
119-
shelljs.cp(path.join(this.$projectData.projectDir, "package.json"), tmpDir);
116+
this.$fs.deleteDirectory(tmpDir);
117+
this.$fs.createDirectory(tmpDir);
118+
this.$fs.copyFile(path.join(this.$projectData.projectDir, "package.json"), tmpDir);
120119
for (const folder of this.folders) {
121120
const folderToCopy = path.join(this.$projectData.projectDir, folder);
122121
if (this.$fs.exists(folderToCopy)) {
123-
shelljs.cp("-rf", folderToCopy, tmpDir);
122+
this.$fs.copyFile(folderToCopy, tmpDir);
124123
}
125124
}
126125
}

test/update.ts

+19-25
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { Options } from "../lib/options";
88
import { AndroidProjectService } from "../lib/services/android-project-service";
99
import {StaticConfig } from "../lib/config";
1010
import { SettingsService } from "../lib/common/test/unit-tests/stubs";
11-
import * as shelljs from "shelljs";
1211
const projectFolder = "test";
1312

1413
function createTestInjector(
@@ -72,7 +71,7 @@ function createTestInjector(
7271
return testInjector;
7372
}
7473

75-
describe("update command method tests", () => {
74+
describe.only("update command method tests", () => {
7675
describe("canExecute", () => {
7776
it("calls platform service validate", async () => {
7877
let validated = false;
@@ -129,7 +128,6 @@ describe("update command method tests", () => {
129128
});
130129

131130
it("calls backup and executeCore", async () => {
132-
sandbox.stub(shelljs);
133131
const testInjector = createTestInjector();
134132
const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
135133
const executeCoreStub: sinon.SinonStub = sinon.stub(updateCommand as any, "executeCore");
@@ -141,16 +139,16 @@ describe("update command method tests", () => {
141139
});
142140

143141
it("if backup fails, execute core not called and temp removed", async () => {
144-
sandbox.stub(shelljs);
145-
const rmStub: sinon.SinonStub = shelljs.rm as sinon.SinonStub;
146142
const testInjector = createTestInjector();
143+
const fs = testInjector.resolve("fs");
144+
const deleteDirectory: sinon.SinonStub = sandbox.stub(fs, "deleteDirectory");
147145
const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
148146
sandbox.stub(updateCommand as any, "backup").throws();
149147
const executeCoreStub: sinon.SinonStub = sinon.stub(updateCommand as any, "executeCore");
150148
updateCommand.execute(["3.3.0"]);
151149

152150
assert.isFalse(executeCoreStub.called);
153-
assert.isTrue(rmStub.calledWith("-fr", path.join(projectFolder, (updateCommand as any).tempFolder)));
151+
assert.isTrue(deleteDirectory.calledWith(path.join(projectFolder, (updateCommand as any).tempFolder)));
154152
});
155153
});
156154

@@ -166,16 +164,16 @@ describe("update command method tests", () => {
166164
});
167165

168166
it("calls copy to temp for package.json and folders", async () => {
169-
sandbox.stub(shelljs);
170-
const cpStub: sinon.SinonStub = shelljs.cp as sinon.SinonStub;
171167
const testInjector = createTestInjector();
168+
const fs = testInjector.resolve("fs");
169+
const copyFileStub = sandbox.stub(fs, "copyFile");
172170
const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
173171
sinon.stub(updateCommand as any, "executeCore");
174172
updateCommand.execute(["3.3.0"]);
175173

176-
assert.isTrue(cpStub.calledWith(path.join(projectFolder, "package.json")));
174+
assert.isTrue(copyFileStub.calledWith(path.join(projectFolder, "package.json")));
177175
for (const folder of (updateCommand as any).folders) {
178-
assert.isTrue(cpStub.calledWith("-rf", path.join(projectFolder, folder)));
176+
assert.isTrue(copyFileStub.calledWith(path.join(projectFolder, folder)));
179177
}
180178
});
181179
});
@@ -192,17 +190,17 @@ describe("update command method tests", () => {
192190
});
193191

194192
it("calls copy to temp for package.json and folders", async () => {
195-
sandbox.stub(shelljs);
196-
const cpStub: sinon.SinonStub = shelljs.cp as sinon.SinonStub;
197193
const testInjector = createTestInjector();
194+
const fs = testInjector.resolve("fs");
195+
const copyFileStub = sandbox.stub(fs, "copyFile");
198196
const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
199197
const tempDir = path.join(projectFolder, (updateCommand as any).tempFolder);
200198
sinon.stub(updateCommand as any, "executeCore");
201199
(updateCommand as any).backup(tempDir);
202200

203-
assert.isTrue(cpStub.calledWith(path.join(projectFolder, "package.json")));
201+
assert.isTrue(copyFileStub.calledWith(path.join(projectFolder, "package.json")));
204202
for (const folder of (updateCommand as any).folders) {
205-
assert.isTrue(cpStub.calledWith("-rf", path.join(projectFolder, folder)));
203+
assert.isTrue(copyFileStub.calledWith(path.join(projectFolder, folder)));
206204
}
207205
});
208206
});
@@ -219,17 +217,17 @@ describe("update command method tests", () => {
219217
});
220218

221219
it("calls copy to temp for package.json and folders", async () => {
222-
sandbox.stub(shelljs);
223-
const cpStub: sinon.SinonStub = shelljs.cp as sinon.SinonStub;
224220
const testInjector = createTestInjector();
221+
const fs = testInjector.resolve("fs");
222+
const copyFileStub = sandbox.stub(fs, "copyFile");
225223
const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
226224
const tempDir = path.join(projectFolder, (updateCommand as any).tempFolder, projectFolder);
227225
sinon.stub(updateCommand as any, "executeCore");
228226
(updateCommand as any).restoreBackup(tempDir);
229227

230-
assert.isTrue(cpStub.calledWith("-f", path.join(tempDir, "package.json"), projectFolder));
228+
assert.isTrue(copyFileStub.calledWith(path.join(tempDir, "package.json"), projectFolder));
231229
for (const folder of (updateCommand as any).folders) {
232-
assert.isTrue(cpStub.calledWith("-fr", path.join(tempDir, folder), projectFolder));
230+
assert.isTrue(copyFileStub.calledWith(path.join(tempDir, folder), projectFolder));
233231
}
234232
});
235233
});
@@ -246,19 +244,18 @@ describe("update command method tests", () => {
246244
});
247245

248246
it("calls remove for all falders", async () => {
249-
sandbox.stub(shelljs);
250-
const rmStub: sinon.SinonStub = shelljs.rm as sinon.SinonStub;
251247
const testInjector = createTestInjector();
248+
const fs = testInjector.resolve("fs");
249+
const deleteDirectory: sinon.SinonStub = sandbox.stub(fs, "deleteDirectory");
252250
const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
253251
return (updateCommand as any).executeCore([]).then(() => {
254252
for (const folder of (updateCommand as any).folders) {
255-
assert.isTrue(rmStub.calledWith("-rf", path.join(projectFolder, folder)));
253+
assert.isTrue(deleteDirectory.calledWith(path.join(projectFolder, folder)));
256254
}
257255
});
258256
});
259257

260258
it("calls remove platforms and add platforms", async () => {
261-
sandbox.stub(shelljs);
262259
const installedPlatforms: string[] = ["android"];
263260
const testInjector = createTestInjector(installedPlatforms);
264261
const platformService = testInjector.resolve("platformService");
@@ -272,7 +269,6 @@ describe("update command method tests", () => {
272269
});
273270

274271
it("call add platforms with specific verison", async () => {
275-
sandbox.stub(shelljs);
276272
const version = "3.3.0";
277273
const installedPlatforms: string[] = ["android"];
278274
const testInjector = createTestInjector(installedPlatforms);
@@ -286,7 +282,6 @@ describe("update command method tests", () => {
286282
});
287283

288284
it("calls remove and add of core modules and widgets", async () => {
289-
sandbox.stub(shelljs);
290285
const testInjector = createTestInjector();
291286
const pluginsService = testInjector.resolve("pluginsService");
292287
sandbox.spy(pluginsService, "remove");
@@ -302,7 +297,6 @@ describe("update command method tests", () => {
302297
});
303298

304299
it("calls add of core modules with specific version", async () => {
305-
sandbox.stub(shelljs);
306300
const version = "3.3.0";
307301
const testInjector = createTestInjector();
308302
const pluginsService = testInjector.resolve("pluginsService");

0 commit comments

Comments
 (0)