Skip to content

Commit f796781

Browse files
committed
fix: various fixes
1 parent 1d1d4f4 commit f796781

19 files changed

+440
-279
lines changed

lib/commands/clean.ts

+63-21
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,79 @@ import { ICommand, ICommandParameter } from "../common/definitions/commands";
33
import { injector } from "../common/yok";
44
import { IFileSystem, IProjectHelper } from "../common/declarations";
55
import * as constants from "../constants";
6+
import { IProjectConfigService } from "../definitions/project";
67

78
export class CleanCommand implements ICommand {
89
public allowedParameters: ICommandParameter[] = [];
910

1011
constructor(
1112
private $fs: IFileSystem,
1213
private $logger: ILogger,
13-
private $projectHelper: IProjectHelper
14+
private $projectHelper: IProjectHelper,
15+
private $projectConfigService: IProjectConfigService,
16+
private $terminalSpinnerService: ITerminalSpinnerService
1417
) {}
1518

1619
public async execute(args: string[]): Promise<void> {
17-
this.$fs.deleteDirectory(
18-
path.join(this.$projectHelper.projectDir, constants.HOOKS_DIR_NAME)
19-
);
20-
this.$fs.deleteDirectory(
21-
path.join(this.$projectHelper.projectDir, constants.PLATFORMS_DIR_NAME)
22-
);
23-
this.$fs.deleteDirectory(
24-
path.join(
25-
this.$projectHelper.projectDir,
26-
constants.NODE_MODULES_FOLDER_NAME
27-
)
28-
);
29-
this.$fs.deleteFile(
30-
path.join(
31-
this.$projectHelper.projectDir,
32-
constants.PACKAGE_LOCK_JSON_FILE_NAME
33-
)
34-
);
35-
36-
this.$logger.info("Project successfully cleaned.");
20+
const spinner = this.$terminalSpinnerService.createSpinner();
21+
spinner.start("Cleaning project...");
22+
23+
const pathsToClean = [
24+
constants.HOOKS_DIR_NAME,
25+
constants.PLATFORMS_DIR_NAME,
26+
constants.NODE_MODULES_FOLDER_NAME,
27+
constants.PACKAGE_LOCK_JSON_FILE_NAME,
28+
];
29+
30+
try {
31+
const additionalPaths = this.$projectConfigService.getValue(
32+
"additionalPathsToClean"
33+
);
34+
if (Array.isArray(additionalPaths)) {
35+
pathsToClean.push(...additionalPaths);
36+
}
37+
38+
for (const pathToClean of pathsToClean) {
39+
const filePath = path.resolve(
40+
this.$projectHelper.projectDir,
41+
pathToClean
42+
);
43+
const displayPath = `${path.relative(
44+
this.$projectHelper.projectDir,
45+
filePath
46+
)}`.yellow;
47+
spinner.start(`Cleaning ${displayPath}`);
48+
this.$logger.trace(`Trying to clean '${filePath}'`);
49+
if (this.$fs.exists(filePath)) {
50+
const stat = this.$fs.getFsStats(filePath);
51+
52+
if (stat.isDirectory()) {
53+
this.$logger.trace(`Path '${filePath}' is a directory, deleting.`);
54+
this.$fs.deleteDirectorySafe(filePath);
55+
spinner.text = `Cleaned directory ${displayPath}`;
56+
spinner.succeed();
57+
} else {
58+
this.$logger.trace(`Path '${filePath}' is a file, deleting.`);
59+
this.$fs.deleteFile(filePath);
60+
spinner.text = `Cleaned file ${displayPath}`;
61+
spinner.succeed();
62+
}
63+
} else {
64+
spinner.text = `Skipping ${displayPath} because it doesn't exist.`;
65+
spinner.info();
66+
this.$logger.trace(`Path '${filePath}' not found, skipping.`);
67+
}
68+
}
69+
} catch (err) {
70+
// ignore any errors
71+
this.$logger.trace(
72+
`Encountered error while cleaning. Error is: ${err.message}.`,
73+
err
74+
);
75+
}
76+
77+
spinner.succeed("Project successfully cleaned.");
78+
// this.$logger.info("Project successfully cleaned.");
3779
}
3880
}
3981

lib/common/declarations.d.ts

+30-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { IOptions } from "../declarations";
22
import { IJsonFileSettingsService } from "./definitions/json-file-settings-service";
33
import {
4-
IGoogleAnalyticsData,
54
IEventActionData,
5+
IGoogleAnalyticsData,
66
} from "./definitions/google-analytics";
7+
import * as child_process from "child_process";
78

9+
// tslint:disable-next-line:interface-name
810
interface Object {
911
[key: string]: any;
1012
}
@@ -14,6 +16,7 @@ interface IStringDictionary extends IDictionary<string> {}
1416
/**
1517
* Describes iTunes Connect application types
1618
*/
19+
// tslint:disable-next-line:interface-name
1720
interface IiTunesConnectApplicationType {
1821
/**
1922
* Applications developed for iOS
@@ -40,6 +43,7 @@ declare const enum GoogleAnalyticsDataType {
4043
/**
4144
* Descibes iTunes Connect applications
4245
*/
46+
// tslint:disable-next-line:interface-name
4347
interface IiTunesConnectApplication {
4448
/**
4549
* Unique Apple ID for each application. Automatically generated and assigned by Apple.
@@ -68,7 +72,7 @@ interface IiTunesConnectApplication {
6872
sku: string;
6973
/**
7074
* Application's type
71-
* @type {IItunesConnectApplicationTypes}
75+
* @type {string}
7276
*/
7377
type: string;
7478
/**
@@ -128,7 +132,7 @@ interface IContentDeliveryBody {
128132
result: {
129133
/**
130134
* A list of the user's applications.
131-
* @type {IItunesConnectApplication[]}
135+
* @type {IiTunesConnectApplication[]}
132136
*/
133137
Applications: IiTunesConnectApplication[];
134138
/**
@@ -365,23 +369,23 @@ interface IFileSystem {
365369
/**
366370
* Reads the entire contents of a file.
367371
* @param {string} filename Path to the file that has to be read.
368-
* @param {string} @optional options Options used for reading the file - encoding and flags.
372+
* @param {string} options Options used for reading the file - encoding and flags.
369373
* @returns {string|Buffer} Content of the file as buffer. In case encoding is specified, the content is returned as string.
370374
*/
371375
readFile(filename: string, options?: IReadFileOptions): string | Buffer;
372376

373377
/**
374378
* Reads the entire contents of a file and returns the result as string.
375379
* @param {string} filename Path to the file that has to be read.
376-
* @param {string} @optional options Options used for reading the file - encoding and flags. If options are not passed, utf8 is used.
380+
* @param {IReadFileOptions | string} encoding Options used for reading the file - encoding and flags. If options are not passed, utf8 is used.
377381
* @returns {string} Content of the file as string.
378382
*/
379383
readText(filename: string, encoding?: IReadFileOptions | string): string;
380384

381385
/**
382386
* Reads the entire content of a file and parses it to JSON object.
383387
* @param {string} filename Path to the file that has to be read.
384-
* @param {string} @optional encoding File encoding, defaults to utf8.
388+
* @param {string} encoding File encoding, defaults to utf8.
385389
* @returns {string} Content of the file as JSON object.
386390
*/
387391
readJson(filename: string, encoding?: string): any;
@@ -498,7 +502,7 @@ interface IFileSystem {
498502
* or directory.
499503
* @param {string} sourcePath The original path of the file/dir.
500504
* @param {string} destinationPath The destination where symlink will be created.
501-
* @param {string} @optional type "file", "dir" or "junction". Default is 'file'.
505+
* @param {string} type "file", "dir" or "junction". Default is 'file'.
502506
* Type option is only available on Windows (ignored on other platforms).
503507
* Note that Windows junction points require the destination path to be absolute.
504508
* When using 'junction', the target argument will automatically be normalized to absolute path.
@@ -556,8 +560,8 @@ interface IFileSystem {
556560

557561
// shell.js wrappers
558562
/**
559-
* @param (string) options Options, can be undefined or a combination of "-r" (recursive) and "-f" (force)
560-
* @param (string[]) files files and direcories to delete
563+
* @param {string} options Options, can be undefined or a combination of "-r" (recursive) and "-f" (force)
564+
* @param {string[]} files files and direcories to delete
561565
*/
562566
rm(options: string, ...files: string[]): void;
563567

@@ -689,7 +693,11 @@ interface IChildProcess extends NodeJS.EventEmitter {
689693
execOptions?: IExecOptions
690694
): Promise<any>;
691695
execFile<T>(command: string, args: string[]): Promise<T>;
692-
spawn(command: string, args?: string[], options?: any): any; // it returns child_process.ChildProcess you can safely cast to it
696+
spawn(
697+
command: string,
698+
args?: string[],
699+
options?: any
700+
): child_process.ChildProcess; // it returns child_process.ChildProcess you can safely cast to it
693701
spawnFromEvent(
694702
command: string,
695703
args: string[],
@@ -987,7 +995,7 @@ interface IProxyLibSettings extends IRejectUnauthorized, ICredentials {
987995
interface IProxyService {
988996
/**
989997
* Caches proxy data.
990-
* @param cacheData {IProxyLibSettings} Data to be cached.
998+
* @param {IProxyLibSettings} settings Data to be cached.
991999
* @returns {Promise<void>} The cache.
9921000
*/
9931001
setCache(settings: IProxyLibSettings): Promise<void>;
@@ -1039,14 +1047,14 @@ interface IHelpService {
10391047

10401048
/**
10411049
* Finds the html help for specified command and opens it in the browser.
1042-
* @param {IComandData} commandData Data describing searched command - name and arguments.
1050+
* @param {ICommandData} commandData Data describing searched command - name and arguments.
10431051
* @returns {Promise<void>}
10441052
*/
10451053
openHelpForCommandInBrowser(commandData: ICommandData): Promise<void>;
10461054

10471055
/**
10481056
* Shows command line help for specified command.
1049-
* @param {string} commandName The name of the command for which to show the help.
1057+
* @param {string} commandData The name of the command for which to show the help.
10501058
* @returns {Promise<void>}
10511059
*/
10521060
showCommandLineHelp(commandData: ICommandData): Promise<void>;
@@ -1159,6 +1167,7 @@ interface IHostInfo {
11591167
getMacOSVersion(): Promise<string>;
11601168
}
11611169

1170+
// tslint:disable-next-line:interface-name
11621171
interface GenericFunction<T> extends Function {
11631172
(...args: any[]): T;
11641173
}
@@ -1312,8 +1321,8 @@ interface IDoctorService {
13121321
runSetupScript(): Promise<ISpawnResult>;
13131322
/**
13141323
* Checks if the envrironment is properly configured and it is possible to execute local builds
1315-
* @param platform @optional The current platform
13161324
* @returns {Promise<boolean>} true if the environment is properly configured for local builds
1325+
* @param {object} configuration
13171326
*/
13181327
canExecuteLocalBuild(configuration?: {
13191328
platform?: string;
@@ -1353,8 +1362,8 @@ interface IUserSettingsService extends IJsonFileSettingsService {
13531362
}
13541363

13551364
/**
1356-
* Used for interaction with various resources located in a resources folder.
1357-
* @interface
1365+
* Used for interaction with various resources located in a resources folder.
1366+
* @interface
13581367
*/
13591368
interface IResourceLoader {
13601369
/**
@@ -1471,6 +1480,7 @@ interface IProjectFilesManager {
14711480
* Handle platform specific files.
14721481
* @param {string} directoryPath Directory from which to start looking for platform specific files. All subdirectories will be included.
14731482
* @param {string} platform Mobile platform - only platform specific files for this platform will be included.
1483+
* @param {IProjectFilesConfig} projectFilesConfig
14741484
* @param {string[]} excludedDirs Directories which should be skipped.
14751485
* @returns {void}
14761486
*/
@@ -1512,6 +1522,7 @@ interface IProjectFilesProvider {
15121522
/**
15131523
* Parses file by removing platform or configuration from its name.
15141524
* @param {string} filePath Path to the project file.
1525+
* @param {IProjectFilesConfig} projectFilesConfig
15151526
* @return {string} Parsed file name or original file name in case it does not have platform/configuration in the filename.
15161527
*/
15171528
getPreparedFilePath(
@@ -1600,7 +1611,7 @@ interface INet {
16001611
/**
16011612
* Returns the first available port in the provided range.
16021613
* @param {number} startPort the first port to check.
1603-
* @param {number} @optional endPort the last port to check. The default value is 65534.
1614+
* @param {number} endPort the last port to check. The default value is 65534.
16041615
* @return {Promise<number>} returns the first available prot in the given range.
16051616
*/
16061617
getAvailablePortInRange(startPort: number, endPort?: number): Promise<number>;
@@ -1674,6 +1685,7 @@ interface IDeferPromise<T> extends IPromiseActions<T> {
16741685
/**
16751686
* Describes service used for interaction with Notification Center
16761687
*/
1688+
// tslint:disable-next-line:interface-name
16771689
interface IiOSNotificationService {
16781690
/**
16791691
* Posts a notification and waits for a response.
@@ -1692,7 +1704,7 @@ interface IiOSNotificationService {
16921704
* Posts a notification.
16931705
* @param {string} deviceIdentifier Device's identifier.
16941706
* @param {string} notification The xml value of the Name key of the notification to be post.
1695-
* @param {string} @optional commandType The xml value of the Command key of the notification to be post.
1707+
* @param {string} commandType The xml value of the Command key of the notification to be post.
16961708
* @return {Promise<number>} A socket which can be queried for a response.
16971709
*/
16981710
postNotification(

0 commit comments

Comments
 (0)