Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit c10c9de

Browse files
Merge pull request #853 from telerik/vladimirov/sync-api
Use sync api of fs
2 parents 7bec6ee + f8b7aae commit c10c9de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1033
-1030
lines changed

appbuilder/declarations.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ declare module Project {
8787

8888
interface IProjectBase {
8989
projectDir: string;
90-
getProjectDir(): IFuture<string>;
90+
91+
/**
92+
* Determines path to project dir.
93+
* @returns {string} Path to project directory.
94+
*/
95+
getProjectDir(): string;
96+
9197
projectData: IData;
9298
/**
9399
* Describes whether the project has separate debug/release build configurations.

appbuilder/project/project-base.ts

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {EOL} from "os";
2-
import Future = require("fibers/future");
32
import * as path from "path";
43
import { TARGET_FRAMEWORK_IDENTIFIERS } from "../../constants";
54

@@ -39,7 +38,7 @@ export abstract class ProjectBase implements Project.IProjectBase {
3938
}
4039

4140
public get projectData(): Project.IData {
42-
this.readProjectData().wait();
41+
this.readProjectData();
4342
return this._projectData;
4443
}
4544

@@ -48,8 +47,8 @@ export abstract class ProjectBase implements Project.IProjectBase {
4847
}
4948

5049
public projectDir: string;
51-
public getProjectDir(): IFuture<string> {
52-
return Future.fromResult(this.projectDir);
50+
public getProjectDir(): string {
51+
return this.projectDir;
5352
}
5453

5554
public get capabilities(): Project.ICapabilities {
@@ -89,7 +88,7 @@ export abstract class ProjectBase implements Project.IProjectBase {
8988
let pathToAndroidResources = path.join(this.projectDir, this.$staticConfig.APP_RESOURCES_DIR_NAME, this.$projectConstants.ANDROID_PLATFORM_NAME);
9089

9190
let pathToAndroidManifest = path.join(pathToAndroidResources, ProjectBase.ANDROID_MANIFEST_NAME);
92-
let appIdentifierInAndroidManifest = this.getAppIdentifierFromConfigFile(pathToAndroidManifest, /package\s*=\s*"(\S*)"/).wait();
91+
let appIdentifierInAndroidManifest = this.getAppIdentifierFromConfigFile(pathToAndroidManifest, /package\s*=\s*"(\S*)"/);
9392

9493
if (appIdentifierInAndroidManifest && appIdentifierInAndroidManifest !== ProjectBase.APP_IDENTIFIER_PLACEHOLDER) {
9594
this._platformSpecificAppIdentifier = appIdentifierInAndroidManifest;
@@ -110,53 +109,51 @@ export abstract class ProjectBase implements Project.IProjectBase {
110109
protected abstract validate(): void;
111110
protected abstract saveProjectIfNeeded(): void;
112111

113-
protected readProjectData(): IFuture<void> {
114-
return (() => {
115-
let projectDir = this.getProjectDir().wait();
116-
this.setShouldSaveProject(false);
117-
if (projectDir) {
118-
let projectFilePath = path.join(projectDir, this.$projectConstants.PROJECT_FILE);
119-
try {
120-
this.projectData = this.getProjectData(projectFilePath);
121-
this.validate();
122-
let debugProjectFile = path.join(projectDir, this.$projectConstants.DEBUG_PROJECT_FILE_NAME);
123-
if (this.$options.debug && !this.$fs.exists(debugProjectFile).wait()) {
124-
this.$fs.writeJson(debugProjectFile, {}).wait();
125-
}
112+
protected readProjectData(): void {
113+
let projectDir = this.getProjectDir();
114+
this.setShouldSaveProject(false);
115+
if (projectDir) {
116+
let projectFilePath = path.join(projectDir, this.$projectConstants.PROJECT_FILE);
117+
try {
118+
this.projectData = this.getProjectData(projectFilePath);
119+
this.validate();
120+
let debugProjectFile = path.join(projectDir, this.$projectConstants.DEBUG_PROJECT_FILE_NAME);
121+
if (this.$options.debug && !this.$fs.exists(debugProjectFile)) {
122+
this.$fs.writeJson(debugProjectFile, {});
123+
}
126124

127-
let releaseProjectFile = path.join(projectDir, this.$projectConstants.RELEASE_PROJECT_FILE_NAME);
128-
if (this.$options.release && !this.$fs.exists(releaseProjectFile).wait()) {
129-
this.$fs.writeJson(releaseProjectFile, {}).wait();
130-
}
125+
let releaseProjectFile = path.join(projectDir, this.$projectConstants.RELEASE_PROJECT_FILE_NAME);
126+
if (this.$options.release && !this.$fs.exists(releaseProjectFile)) {
127+
this.$fs.writeJson(releaseProjectFile, {});
128+
}
131129

132-
_.each(this.$fs.enumerateFilesInDirectorySync(projectDir), (configProjectFile: string) => {
133-
let configMatch = path.basename(configProjectFile).match(ProjectBase.CONFIGURATION_FROM_FILE_NAME_REGEX);
134-
if (configMatch && configMatch.length > 1) {
135-
let configurationName = configMatch[1];
136-
let configProjectContent = this.$fs.readJson(configProjectFile).wait(),
137-
configurationLowerCase = configurationName.toLowerCase();
138-
this.configurationSpecificData[configurationLowerCase] = <any>_.merge(_.cloneDeep(this._projectData), configProjectContent);
139-
this._hasBuildConfigurations = true;
140-
}
141-
});
142-
} catch (err) {
143-
if (err.message === "FUTURE_PROJECT_VER") {
144-
this.$errors.failWithoutHelp("This project is created by a newer version of AppBuilder. Upgrade AppBuilder CLI to work with it.");
130+
_.each(this.$fs.enumerateFilesInDirectorySync(projectDir), (configProjectFile: string) => {
131+
let configMatch = path.basename(configProjectFile).match(ProjectBase.CONFIGURATION_FROM_FILE_NAME_REGEX);
132+
if (configMatch && configMatch.length > 1) {
133+
let configurationName = configMatch[1];
134+
let configProjectContent = this.$fs.readJson(configProjectFile),
135+
configurationLowerCase = configurationName.toLowerCase();
136+
this.configurationSpecificData[configurationLowerCase] = <any>_.merge(_.cloneDeep(this._projectData), configProjectContent);
137+
this._hasBuildConfigurations = true;
145138
}
146-
147-
this.$errors.failWithoutHelp("The project file %s is corrupted." + EOL +
148-
"Consider restoring an earlier version from your source control or backup." + EOL +
149-
"To create a new one with the default settings, delete this file and run $ appbuilder init hybrid." + EOL +
150-
"Additional technical information: %s", projectFilePath, err.toString());
139+
});
140+
} catch (err) {
141+
if (err.message === "FUTURE_PROJECT_VER") {
142+
this.$errors.failWithoutHelp("This project is created by a newer version of AppBuilder. Upgrade AppBuilder CLI to work with it.");
151143
}
152144

153-
this.saveProjectIfNeeded();
145+
this.$errors.failWithoutHelp("The project file %s is corrupted." + EOL +
146+
"Consider restoring an earlier version from your source control or backup." + EOL +
147+
"To create a new one with the default settings, delete this file and run $ appbuilder init hybrid." + EOL +
148+
"Additional technical information: %s", projectFilePath, err.toString());
154149
}
155-
}).future<void>()();
150+
151+
this.saveProjectIfNeeded();
152+
}
156153
}
157154

158155
private getProjectData(projectFilePath: string): Project.IData {
159-
let data = this.$fs.readJson(projectFilePath).wait();
156+
let data = this.$fs.readJson(projectFilePath);
160157
if (data.projectVersion && data.projectVersion.toString() !== "1") {
161158
this.$errors.fail("FUTURE_PROJECT_VER");
162159
}
@@ -175,19 +172,17 @@ export abstract class ProjectBase implements Project.IProjectBase {
175172
return data;
176173
}
177174

178-
private getAppIdentifierFromConfigFile(pathToConfigFile: string, regExp: RegExp): IFuture<string> {
179-
return ((): string => {
180-
if (this.$fs.exists(pathToConfigFile).wait()) {
181-
let fileContent = this.$fs.readText(pathToConfigFile).wait();
175+
private getAppIdentifierFromConfigFile(pathToConfigFile: string, regExp: RegExp): string {
176+
if (this.$fs.exists(pathToConfigFile)) {
177+
let fileContent = this.$fs.readText(pathToConfigFile);
182178

183-
let matches = fileContent.match(regExp);
179+
let matches = fileContent.match(regExp);
184180

185-
if (matches && matches[1]) {
186-
return matches[1];
187-
}
181+
if (matches && matches[1]) {
182+
return matches[1];
188183
}
184+
}
189185

190-
return null;
191-
}).future<string>()();
186+
return null;
192187
}
193188
}

appbuilder/proton-bootstrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {installUncaughtExceptionListener} from "../errors";
1414
installUncaughtExceptionListener();
1515

1616
$injector.register("emulatorSettingsService", {
17-
canStart(platform: string): IFuture<boolean> {
18-
return Future.fromResult(true);
17+
canStart(platform: string): boolean {
18+
return true;
1919
},
2020
minVersion(): number {
2121
return 10;

appbuilder/providers/project-files-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class ProjectFilesProvider extends ProjectFilesProviderBase {
88
private get projectDir(): string {
99
if (!this._projectDir) {
1010
let project = this.$injector.resolve("project");
11-
this._projectDir = project.getProjectDir().wait();
11+
this._projectDir = project.getProjectDir();
1212
}
1313

1414
return this._projectDir;

appbuilder/services/livesync/ios-livesync-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class IOSLiveSyncService implements IDeviceLiveSyncService {
2424
return (() => {
2525
if (this.device.isEmulator) {
2626
let simulatorLogFilePath = path.join(osenv.home(), `/Library/Developer/CoreSimulator/Devices/${this.device.deviceInfo.identifier}/data/Library/Logs/system.log`);
27-
let simulatorLogFileContent = this.$fs.readText(simulatorLogFilePath).wait() || "";
27+
let simulatorLogFileContent = this.$fs.readText(simulatorLogFilePath) || "";
2828

2929
let simulatorCachePath = path.join(osenv.home(), `/Library/Developer/CoreSimulator/Devices/${this.device.deviceInfo.identifier}/data/Containers/Data/Application/`);
3030
let regex = new RegExp(`^(?:.*?)${deviceAppData.appIdentifier}(?:.*?)${simulatorCachePath}(.*?)$`, "gm");

appbuilder/services/livesync/livesync-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class ProtonLiveSyncService implements IProtonLiveSyncService {
5252
return result;
5353
}
5454

55-
if (!this.$fs.exists(this.$project.projectDir).wait()) {
55+
if (!this.$fs.exists(this.$project.projectDir)) {
5656
result.liveSyncToApp = result.liveSyncToCompanion = {
5757
isResolved: false,
5858
error: new Error(`Cannot execute LiveSync operation as the project dir ${this.$project.projectDir} does not exist on the file system.`)
@@ -62,7 +62,7 @@ export class ProtonLiveSyncService implements IProtonLiveSyncService {
6262
}
6363

6464
if (!isForDeletedFiles && filePaths && filePaths.length) {
65-
let missingFiles = filePaths.filter(filePath => !this.$fs.exists(filePath).wait());
65+
let missingFiles = filePaths.filter(filePath => !this.$fs.exists(filePath));
6666
if (missingFiles && missingFiles.length) {
6767
result.liveSyncToApp = result.liveSyncToCompanion = {
6868
isResolved: false,

appbuilder/services/npm-service.ts

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class NpmService implements INpmService {
3434
let npmMainJsFile = require.resolve(NpmService.NPM_MODULE_NAME);
3535
let pathToNpmBinary = path.join(npmMainJsFile.substring(0, npmMainJsFile.lastIndexOf(constants.NODE_MODULES_DIR_NAME) + constants.NODE_MODULES_DIR_NAME.length), ".bin", this.npmExecutableName);
3636

37-
if (!this.$fs.exists(pathToNpmBinary).wait()) {
37+
if (!this.$fs.exists(pathToNpmBinary)) {
3838
throw new Error(`The npm binary is not in ${pathToNpmBinary} as expected.`);
3939
}
4040

@@ -95,7 +95,7 @@ export class NpmService implements INpmService {
9595
}
9696
}
9797

98-
this.generateReferencesFile(projectDir).wait();
98+
this.generateReferencesFile(projectDir);
9999

100100
return npmInstallResult;
101101
}).future<INpmInstallResult>()();
@@ -104,7 +104,7 @@ export class NpmService implements INpmService {
104104
@exportedPromise("npmService")
105105
public uninstall(projectDir: string, dependency: string): IFuture<void> {
106106
return (() => {
107-
let packageJsonContent = this.getPackageJsonContent(projectDir).wait();
107+
let packageJsonContent = this.getPackageJsonContent(projectDir);
108108

109109
if (packageJsonContent && packageJsonContent.dependencies && packageJsonContent.dependencies[dependency]) {
110110
this.npmUninstall(projectDir, dependency, ["--save"]).wait();
@@ -114,7 +114,7 @@ export class NpmService implements INpmService {
114114
this.npmUninstall(projectDir, `${NpmService.TYPES_DIRECTORY}${dependency}`, ["--save-dev"]).wait();
115115
}
116116

117-
this.generateReferencesFile(projectDir).wait();
117+
this.generateReferencesFile(projectDir);
118118
}).future<void>()();
119119
}
120120

@@ -242,21 +242,18 @@ export class NpmService implements INpmService {
242242
}).future<string>()();
243243
}
244244

245-
private getPackageJsonContent(projectDir: string): IFuture<any> {
246-
return (() => {
247-
let pathToPackageJson = this.getPathToPackageJson(projectDir);
248-
249-
try {
250-
return this.$fs.readJson(pathToPackageJson).wait();
251-
} catch (err) {
252-
if (err.code === "ENOENT") {
253-
this.$errors.failWithoutHelp(`Unable to find ${this.$projectConstants.PACKAGE_JSON_NAME} in ${projectDir}.`);
254-
}
245+
private getPackageJsonContent(projectDir: string): any {
246+
let pathToPackageJson = this.getPathToPackageJson(projectDir);
255247

256-
throw err;
248+
try {
249+
return this.$fs.readJson(pathToPackageJson);
250+
} catch (err) {
251+
if (err.code === "ENOENT") {
252+
this.$errors.failWithoutHelp(`Unable to find ${this.$projectConstants.PACKAGE_JSON_NAME} in ${projectDir}.`);
257253
}
258254

259-
}).future<any>()();
255+
throw err;
256+
}
260257
}
261258

262259
private getPathToPackageJson(projectDir: string): string {
@@ -271,59 +268,56 @@ export class NpmService implements INpmService {
271268
return this.npmInstall(projectDir, `${NpmService.TYPES_DIRECTORY}${dependency}`, null, ["--save-dev", "--save-exact"]);
272269
}
273270

274-
private generateReferencesFile(projectDir: string): IFuture<void> {
275-
return (() => {
276-
let packageJsonContent = this.getPackageJsonContent(projectDir).wait();
271+
private generateReferencesFile(projectDir: string): void {
272+
let packageJsonContent = this.getPackageJsonContent(projectDir);
277273

278-
let pathToReferenceFile = this.getPathToReferencesFile(projectDir),
279-
lines: string[] = [];
274+
let pathToReferenceFile = this.getPathToReferencesFile(projectDir),
275+
lines: string[] = [];
280276

281-
if (packageJsonContent && packageJsonContent.dependencies && packageJsonContent.dependencies[constants.TNS_CORE_MODULES]) {
282-
let relativePathToTnsCoreModulesDts = `./${constants.NODE_MODULES_DIR_NAME}/${constants.TNS_CORE_MODULES}/${NpmService.TNS_CORE_MODULES_DEFINITION_FILE_NAME}`;
277+
if (packageJsonContent && packageJsonContent.dependencies && packageJsonContent.dependencies[constants.TNS_CORE_MODULES]) {
278+
let relativePathToTnsCoreModulesDts = `./${constants.NODE_MODULES_DIR_NAME}/${constants.TNS_CORE_MODULES}/${NpmService.TNS_CORE_MODULES_DEFINITION_FILE_NAME}`;
283279

284-
if (this.$fs.exists(path.join(projectDir, relativePathToTnsCoreModulesDts)).wait()) {
285-
lines.push(this.getReferenceLine(relativePathToTnsCoreModulesDts));
286-
}
280+
if (this.$fs.exists(path.join(projectDir, relativePathToTnsCoreModulesDts))) {
281+
lines.push(this.getReferenceLine(relativePathToTnsCoreModulesDts));
287282
}
283+
}
288284

289-
_(packageJsonContent.devDependencies)
290-
.keys()
291-
.each(devDependency => {
292-
if (this.isFromTypesRepo(devDependency)) {
293-
let nodeModulesDirectory = path.join(projectDir, constants.NODE_MODULES_DIR_NAME);
294-
let definitionFiles = this.$fs.enumerateFilesInDirectorySync(path.join(nodeModulesDirectory, devDependency),
295-
(file, stat) => _.endsWith(file, constants.FileExtensions.TYPESCRIPT_DEFINITION_FILE) || stat.isDirectory(), { enumerateDirectories: false });
285+
_(packageJsonContent.devDependencies)
286+
.keys()
287+
.each(devDependency => {
288+
if (this.isFromTypesRepo(devDependency)) {
289+
let nodeModulesDirectory = path.join(projectDir, constants.NODE_MODULES_DIR_NAME);
290+
let definitionFiles = this.$fs.enumerateFilesInDirectorySync(path.join(nodeModulesDirectory, devDependency),
291+
(file, stat) => _.endsWith(file, constants.FileExtensions.TYPESCRIPT_DEFINITION_FILE) || stat.isDirectory(), { enumerateDirectories: false });
296292

297-
let defs = _.map(definitionFiles, def => this.getReferenceLine(fromWindowsRelativePathToUnix(path.relative(projectDir, def))));
293+
let defs = _.map(definitionFiles, def => this.getReferenceLine(fromWindowsRelativePathToUnix(path.relative(projectDir, def))));
298294

299-
this.$logger.trace(`Adding lines for definition files: ${definitionFiles.join(", ")}`);
300-
lines = lines.concat(defs);
301-
}
302-
});
295+
this.$logger.trace(`Adding lines for definition files: ${definitionFiles.join(", ")}`);
296+
lines = lines.concat(defs);
297+
}
298+
});
303299

304-
// TODO: Make sure the android17.d.ts and ios.d.ts are added.
300+
// TODO: Make sure the android17.d.ts and ios.d.ts are added.
305301

306-
if (lines.length) {
307-
this.$logger.trace("Updating reference file with new entries...");
308-
this.$fs.writeFile(pathToReferenceFile, lines.join(os.EOL), "utf8").wait();
302+
if (lines.length) {
303+
this.$logger.trace("Updating reference file with new entries...");
304+
this.$fs.writeFile(pathToReferenceFile, lines.join(os.EOL), "utf8");
309305

310-
// Our old name for the file which contains the definitions imports was .abreferences.d.ts.
311-
// TypeScript 2.0 does not respect hidden definition files and we had to rename the file.
312-
this.removeOldAbReferencesFile(projectDir).wait();
313-
} else {
314-
this.$logger.trace(`Could not find any .d.ts files for ${this.$projectConstants.REFERENCES_FILE_NAME} file. Deleting the old file.`);
315-
this.$fs.deleteFile(pathToReferenceFile).wait();
316-
}
317-
}).future<void>()();
306+
// Our old name for the file which contains the definitions imports was .abreferences.d.ts.
307+
// TypeScript 2.0 does not respect hidden definition files and we had to rename the file.
308+
this.removeOldAbReferencesFile(projectDir);
309+
} else {
310+
this.$logger.trace(`Could not find any .d.ts files for ${this.$projectConstants.REFERENCES_FILE_NAME} file. Deleting the old file.`);
311+
this.$fs.deleteFile(pathToReferenceFile);
312+
}
318313
}
319314

320-
private removeOldAbReferencesFile(projectDir: string): IFuture<void> {
321-
return (() => {
322-
const pathToOldReferencesFile = path.join(projectDir, this.$projectConstants.OLD_REFERENCES_FILE_NAME);
323-
if (this.$fs.exists(pathToOldReferencesFile).wait()) {
324-
this.$fs.deleteFile(pathToOldReferencesFile).wait();
325-
}
326-
}).future<void>()();
315+
private removeOldAbReferencesFile(projectDir: string): void {
316+
const pathToOldReferencesFile = path.join(projectDir, this.$projectConstants.OLD_REFERENCES_FILE_NAME);
317+
318+
if (this.$fs.exists(pathToOldReferencesFile)) {
319+
this.$fs.deleteFile(pathToOldReferencesFile);
320+
}
327321
}
328322

329323
private isFromTypesRepo(dependency: string): boolean {

appbuilder/services/path-filtering.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class PathFilteringService implements IPathFilteringService {
99
let rules: string[] = [];
1010

1111
try {
12-
let fileContent = this.$fs.readText(fullFilePath).wait();
12+
let fileContent = this.$fs.readText(fullFilePath);
1313
rules = _.reject(fileContent.split(/[\n\r]/),
1414
(line: string) => line.length === 0 || line[0] === COMMENT_START);
1515

0 commit comments

Comments
 (0)