Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a3c3fa3
Use sync version of fs.exists
rosen-vladimirov Dec 9, 2016
2591b76
Use sync version of fs.unlink
rosen-vladimirov Dec 9, 2016
6e698e9
Make fs.deleteDirectory sync
rosen-vladimirov Dec 9, 2016
b7be851
Use sync version of fs.getFsStats
rosen-vladimirov Dec 9, 2016
9a9d1ad
Make getFileSize sync
rosen-vladimirov Dec 9, 2016
7c2355a
Make createDirectory sync (use mkdirp.sync)
rosen-vladimirov Dec 9, 2016
727e5f8
Rebase on latest master
rosen-vladimirov Dec 9, 2016
7cfb218
Make ensureDirectoryExists sync
rosen-vladimirov Dec 10, 2016
2f519e6
Use sync version of fs.rename
rosen-vladimirov Dec 10, 2016
f279430
Use sync version of fs.symlink
rosen-vladimirov Dec 10, 2016
9a2f2ea
Remove closeStream method from fs
rosen-vladimirov Dec 10, 2016
d169bc5
Use sync version of fs.readdir
rosen-vladimirov Dec 10, 2016
13df2a0
Use sync version of fs.readFile
rosen-vladimirov Dec 10, 2016
822969b
Make fs.readText, IEmulatorPlatformServices.checkAvailability, IAutoC…
rosen-vladimirov Dec 11, 2016
981d19c
Make fs.readJson and config.loadConfig sync
rosen-vladimirov Dec 11, 2016
9373722
Use sync version of fs.writeFile
rosen-vladimirov Dec 12, 2016
0ea5d07
Make IAutoCompletionService.disableAutoCompletion and IProjectFilesMa…
rosen-vladimirov Dec 12, 2016
5a8e036
Use sync version of fs.appendFile
rosen-vladimirov Dec 12, 2016
9d4bf13
Make fs.writeJson sync
rosen-vladimirov Dec 12, 2016
8007d43
Remove fs.tryExecuteFileOperation
rosen-vladimirov Dec 13, 2016
d4e94d5
Make fs.copyFile sync
rosen-vladimirov Dec 13, 2016
7aeab47
Use sync version of fs.chmod
rosen-vladimirov Dec 13, 2016
8ab23f8
Use sync version of fs.lstat
rosen-vladimirov Dec 13, 2016
8856e4c
Rebase on latest master
rosen-vladimirov Dec 13, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 41 additions & 45 deletions lib/android-tools-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
this.showWarningsAsErrors = options.showWarningsAsErrors;
}
if (!this.pathToAndroidExecutable) {
if (this.validateAndroidHomeEnvVariable(this.androidHome).wait()) {
if (this.validateAndroidHomeEnvVariable(this.androidHome)) {
let androidPath = path.join(this.androidHome, "tools", this.androidExecutableName);
if (!this.trySetAndroidPath(androidPath).wait() && !this.trySetAndroidPath(this.androidExecutableName).wait()) {
this.printMessage(`Unable to find "${this.androidExecutableName}" executable file. Make sure you have set ANDROID_HOME environment variable correctly.`);
Expand Down Expand Up @@ -100,7 +100,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
let detectedErrors = false;
this.showWarningsAsErrors = options && options.showWarningsAsErrors;
let toolsInfoData = this.getToolsInfo().wait();
let isAndroidHomeValid = this.validateAndroidHomeEnvVariable(toolsInfoData.androidHomeEnvVar).wait();
let isAndroidHomeValid = this.validateAndroidHomeEnvVariable(toolsInfoData.androidHomeEnvVar);
if (!toolsInfoData.compileSdkVersion) {
this.printMessage(`Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK ${AndroidToolsInfo.MIN_REQUIRED_COMPILE_TARGET} or later.`,
"Run `$ android` to manage your Android SDK versions.");
Expand Down Expand Up @@ -258,32 +258,30 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
}).future<number>()();
}

private getMatchingDir(pathToDir: string, versionRange: string): IFuture<string> {
return ((): string => {
let selectedVersion: string;
if (this.$fs.exists(pathToDir).wait()) {
let subDirs = this.$fs.readDirectory(pathToDir).wait();
this.$logger.trace(`Directories found in ${pathToDir} are ${subDirs.join(", ")}`);

let subDirsVersions = subDirs
.map(dirName => {
let dirNameGroups = dirName.match(AndroidToolsInfo.VERSION_REGEX);
if (dirNameGroups) {
return dirNameGroups[1];
}
private getMatchingDir(pathToDir: string, versionRange: string): string {
let selectedVersion: string;
if (this.$fs.exists(pathToDir)) {
let subDirs = this.$fs.readDirectory(pathToDir);
this.$logger.trace(`Directories found in ${pathToDir} are ${subDirs.join(", ")}`);

let subDirsVersions = subDirs
.map(dirName => {
let dirNameGroups = dirName.match(AndroidToolsInfo.VERSION_REGEX);
if (dirNameGroups) {
return dirNameGroups[1];
}

return null;
})
.filter(dirName => !!dirName);
this.$logger.trace(`Versions found in ${pathToDir} are ${subDirsVersions.join(", ")}`);
let version = semver.maxSatisfying(subDirsVersions, versionRange);
if (version) {
selectedVersion = _.find(subDirs, dir => dir.indexOf(version) !== -1);
}
return null;
})
.filter(dirName => !!dirName);
this.$logger.trace(`Versions found in ${pathToDir} are ${subDirsVersions.join(", ")}`);
let version = semver.maxSatisfying(subDirsVersions, versionRange);
if (version) {
selectedVersion = _.find(subDirs, dir => dir.indexOf(version) !== -1);
}
this.$logger.trace("Selected version is: ", selectedVersion);
return selectedVersion;
}).future<string>()();
}
this.$logger.trace("Selected version is: ", selectedVersion);
return selectedVersion;
}

private getBuildToolsRange(): string {
Expand All @@ -296,7 +294,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
if (this.androidHome) {
let pathToBuildTools = path.join(this.androidHome, "build-tools");
let buildToolsRange = this.getBuildToolsRange();
buildToolsVersion = this.getMatchingDir(pathToBuildTools, buildToolsRange).wait();
buildToolsVersion = this.getMatchingDir(pathToBuildTools, buildToolsRange);
}

return buildToolsVersion;
Expand All @@ -321,7 +319,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
let requiredAppCompatRange = this.getAppCompatRange().wait();
if (this.androidHome && requiredAppCompatRange) {
let pathToAppCompat = path.join(this.androidHome, "extras", "android", "m2repository", "com", "android", "support", "appcompat-v7");
selectedAppCompatVersion = this.getMatchingDir(pathToAppCompat, requiredAppCompatRange).wait();
selectedAppCompatVersion = this.getMatchingDir(pathToAppCompat, requiredAppCompatRange);
}

this.$logger.trace(`Selected AppCompat version is: ${selectedAppCompatVersion}`);
Expand Down Expand Up @@ -366,25 +364,23 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
}

private _cachedAndroidHomeValidationResult: boolean = null;
private validateAndroidHomeEnvVariable(androidHomeEnvVar: string): IFuture<boolean> {
return ((): boolean => {
if (this._cachedAndroidHomeValidationResult === null) {
this._cachedAndroidHomeValidationResult = true;
let expectedDirectoriesInAndroidHome = ["build-tools", "tools", "platform-tools", "extras"];
if (!androidHomeEnvVar || !this.$fs.exists(androidHomeEnvVar).wait()) {
this.printMessage("The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.",
"To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory.");
this._cachedAndroidHomeValidationResult = false;
} else if (!_.some(expectedDirectoriesInAndroidHome.map(dir => this.$fs.exists(path.join(androidHomeEnvVar, dir)).wait()))) {
this.printMessage("The ANDROID_HOME environment variable points to incorrect directory. You will not be able to perform any build-related operations for Android.",
"To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory, " +
"where you will find `tools` and `platform-tools` directories.");
this._cachedAndroidHomeValidationResult = false;
}
private validateAndroidHomeEnvVariable(androidHomeEnvVar: string): boolean {
if (this._cachedAndroidHomeValidationResult === null) {
this._cachedAndroidHomeValidationResult = true;
let expectedDirectoriesInAndroidHome = ["build-tools", "tools", "platform-tools", "extras"];
if (!androidHomeEnvVar || !this.$fs.exists(androidHomeEnvVar)) {
this.printMessage("The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.",
"To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory.");
this._cachedAndroidHomeValidationResult = false;
} else if (!_.some(expectedDirectoriesInAndroidHome.map(dir => this.$fs.exists(path.join(androidHomeEnvVar, dir))))) {
this.printMessage("The ANDROID_HOME environment variable points to incorrect directory. You will not be able to perform any build-related operations for Android.",
"To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory, " +
"where you will find `tools` and `platform-tools` directories.");
this._cachedAndroidHomeValidationResult = false;
}
}

return this._cachedAndroidHomeValidationResult;
}).future<boolean>()();
return this._cachedAndroidHomeValidationResult;
}
}
$injector.register("androidToolsInfo", AndroidToolsInfo);
2 changes: 1 addition & 1 deletion lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class BuildCommandBase {
let platform = args[0].toLowerCase();
this.$platformService.buildPlatform(platform, null, true).wait();
if(this.$options.copyTo) {
this.$platformService.copyLastOutput(platform, this.$options.copyTo, {isForDevice: this.$options.forDevice}).wait();
this.$platformService.copyLastOutput(platform, this.$options.copyTo, {isForDevice: this.$options.forDevice});
}
}).future<void>()();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class InstallCommand implements ICommand {
this.$projectDataService.initialize(this.$projectData.projectDir);
_.each(this.$platformsData.platformsNames, platform => {
let platformData = this.$platformsData.getPlatformData(platform);
let frameworkPackageData = this.$projectDataService.getValue(platformData.frameworkPackageName).wait();
let frameworkPackageData = this.$projectDataService.getValue(platformData.frameworkPackageName);
if (frameworkPackageData && frameworkPackageData.version) {
try {
this.$platformService.addPlatforms([`${platform}@${frameworkPackageData.version}`]).wait();
Expand All @@ -49,7 +49,7 @@ export class InstallCommand implements ICommand {
let projectDir = this.$projectData.projectDir;

let devPrefix = 'nativescript-dev-';
if (!this.$fs.exists(moduleName).wait() && moduleName.indexOf(devPrefix) !== 0) {
if (!this.$fs.exists(moduleName) && moduleName.indexOf(devPrefix) !== 0) {
moduleName = devPrefix + moduleName;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/commands/list-platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ export class ListPlatformsCommand implements ICommand {

execute(args: string[]): IFuture<void> {
return (() => {
let installedPlatforms = this.$platformService.getInstalledPlatforms().wait();
let installedPlatforms = this.$platformService.getInstalledPlatforms();

if(installedPlatforms.length > 0) {
let preparedPlatforms = this.$platformService.getPreparedPlatforms().wait();
let preparedPlatforms = this.$platformService.getPreparedPlatforms();
if(preparedPlatforms.length > 0) {
this.$logger.out("The project is prepared for: ", helpers.formatListOfNames(preparedPlatforms, "and"));
} else {
this.$logger.out("The project is not prepared for any platform");
}
this.$logger.out("Installed platforms: ", helpers.formatListOfNames(installedPlatforms, "and"));
} else {
let formattedPlatformsList = helpers.formatListOfNames(this.$platformService.getAvailablePlatforms().wait(), "and");
let formattedPlatformsList = helpers.formatListOfNames(this.$platformService.getAvailablePlatforms(), "and");
this.$logger.out("Available platforms for this OS: ", formattedPlatformsList);
this.$logger.out("No installed platforms found. Use $ tns platform add");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/platform-clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class CleanCommand implements ICommand {

public execute(args: string[]): IFuture<void> {
return (() => {
this.$platformService.removePlatforms(args).wait();
this.$platformService.removePlatforms(args);
this.$platformService.addPlatforms(args).wait();
}).future<void>()();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/plugin/list-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class ListPluginsCommand implements ICommand {

public execute(args: string[]): IFuture<void> {
return (() => {
let installedPlugins: IPackageJsonDepedenciesResult = this.$pluginsService.getDependenciesFromPackageJson().wait();
let installedPlugins: IPackageJsonDepedenciesResult = this.$pluginsService.getDependenciesFromPackageJson();

let headers: string[] = ["Plugin", "Version"];
let dependenciesData: string[][] = this.createTableCells(installedPlugins.dependencies);
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/remove-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class RemovePlatformCommand implements ICommand {

execute(args: string[]): IFuture<void> {
return (() => {
this.$platformService.removePlatforms(args).wait();
this.$platformService.removePlatforms(args);
}).future<void>()();
}

Expand Down
12 changes: 6 additions & 6 deletions lib/commands/test-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ class TestInitCommand implements ICommand {

let testsDir = path.join(projectDir, 'app/tests');
let shouldCreateSampleTests = true;
if (this.$fs.exists(testsDir).wait()) {
if (this.$fs.exists(testsDir)) {
this.$logger.info('app/tests/ directory already exists, will not create an example test project.');
shouldCreateSampleTests = false;
}

this.$fs.ensureDirectoryExists(testsDir).wait();
this.$fs.ensureDirectoryExists(testsDir);

let karmaConfTemplate = this.$resources.readText('test/karma.conf.js').wait();
let karmaConfTemplate = this.$resources.readText('test/karma.conf.js');
let karmaConf = _.template(karmaConfTemplate)({
frameworks: [frameworkToInstall].concat(dependencies)
.map(fw => `'${fw}'`)
.join(', ')
});

this.$fs.writeFile(path.join(projectDir, 'karma.conf.js'), karmaConf).wait();
this.$fs.writeFile(path.join(projectDir, 'karma.conf.js'), karmaConf);

let exampleFilePath = this.$resources.resolvePath(`test/example.${frameworkToInstall}.js`);

if (shouldCreateSampleTests && this.$fs.exists(exampleFilePath).wait()) {
this.$fs.copyFile(exampleFilePath, path.join(testsDir, 'example.js')).wait();
if (shouldCreateSampleTests && this.$fs.exists(exampleFilePath)) {
this.$fs.copyFile(exampleFilePath, path.join(testsDir, 'example.js'));
this.$logger.info('\nExample test file created in app/tests/'.yellow);
} else {
this.$logger.info('\nPlace your test files under app/tests/'.yellow);
Expand Down
60 changes: 31 additions & 29 deletions lib/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class UpdateCommand implements ICommand {
}

try {
this.executeCore(args, folders);
this.executeCore(args, folders).wait();
} catch (error) {
shelljs.cp("-f", path.join(tmpDir, "package.json"), this.$projectData.projectDir);
for (let folder of folders) {
Expand All @@ -51,40 +51,42 @@ export class UpdateCommand implements ICommand {
}).future<boolean>()();
}

private executeCore(args: string[], folders: string[]) {
let platforms = this.$platformService.getInstalledPlatforms().wait();
let availablePlatforms = this.$platformService.getAvailablePlatforms().wait();
let packagePlatforms: string[] = [];
private executeCore(args: string[], folders: string[]): IFuture<void> {
return (() => {
let platforms = this.$platformService.getInstalledPlatforms();
let availablePlatforms = this.$platformService.getAvailablePlatforms();
let packagePlatforms: string[] = [];

this.$projectDataService.initialize(this.$projectData.projectDir);
for (let platform of availablePlatforms) {
let platformData = this.$platformsData.getPlatformData(platform);
let platformVersion = this.$projectDataService.getValue(platformData.frameworkPackageName).wait();
if (platformVersion) {
packagePlatforms.push(platform);
this.$projectDataService.removeProperty(platformData.frameworkPackageName).wait();
this.$projectDataService.initialize(this.$projectData.projectDir);
for (let platform of availablePlatforms) {
let platformData = this.$platformsData.getPlatformData(platform);
let platformVersion = this.$projectDataService.getValue(platformData.frameworkPackageName);
if (platformVersion) {
packagePlatforms.push(platform);
this.$projectDataService.removeProperty(platformData.frameworkPackageName);
}
}
}

this.$platformService.removePlatforms(platforms).wait();
this.$pluginsService.remove("tns-core-modules").wait();
this.$pluginsService.remove("tns-core-modules-widgets").wait();
this.$platformService.removePlatforms(platforms);
this.$pluginsService.remove("tns-core-modules").wait();
this.$pluginsService.remove("tns-core-modules-widgets").wait();

for (let folder of folders) {
shelljs.rm("-fr", folder);
}
for (let folder of folders) {
shelljs.rm("-fr", folder);
}

platforms = platforms.concat(packagePlatforms);
if (args.length === 1) {
for (let platform of platforms) {
this.$platformService.addPlatforms([ platform+"@"+args[0] ]).wait();
platforms = platforms.concat(packagePlatforms);
if (args.length === 1) {
for (let platform of platforms) {
this.$platformService.addPlatforms([ platform+"@"+args[0] ]).wait();
}
this.$pluginsService.add("tns-core-modules@" + args[0]).wait();
} else {
this.$platformService.addPlatforms(platforms).wait();
this.$pluginsService.add("tns-core-modules").wait();
}
this.$pluginsService.add("tns-core-modules@" + args[0]).wait();
} else {
this.$platformService.addPlatforms(platforms).wait();
this.$pluginsService.add("tns-core-modules").wait();
}
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
}).future<void>()();
}

allowedParameters: ICommandParameter[] = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/common
Submodule common updated 50 files
+7 −1 appbuilder/declarations.d.ts
+48 −53 appbuilder/project/project-base.ts
+2 −2 appbuilder/proton-bootstrap.ts
+1 −1 appbuilder/providers/project-files-provider.ts
+1 −1 appbuilder/services/livesync/ios-livesync-service.ts
+2 −2 appbuilder/services/livesync/livesync-service.ts
+51 −57 appbuilder/services/npm-service.ts
+1 −1 appbuilder/services/path-filtering.ts
+7 −7 commands/autocompletion.ts
+2 −2 commands/generate-messages.ts
+1 −1 commands/help.ts
+1 −1 commands/preuninstall.ts
+1 −1 config-base.ts
+266 −44 declarations.d.ts
+15 −3 definitions/mobile.d.ts
+1 −1 dispatchers.ts
+110 −263 file-system.ts
+5 −5 mobile/android/android-device-file-system.ts
+6 −6 mobile/android/android-device-hash-service.ts
+75 −89 mobile/android/android-emulator-services.ts
+1 −1 mobile/ios/device/ios-device-file-system.ts
+5 −5 mobile/ios/device/ios-device.ts
+1 −1 mobile/ios/device/ios-proxy-services.ts
+9 −11 mobile/ios/simulator/ios-emulator-services.ts
+4 −3 mobile/ios/simulator/ios-simulator-application-manager.ts
+1 −1 mobile/ios/simulator/ios-simulator-file-system.ts
+9 −11 mobile/mobile-core/ios-device-discovery.ts
+13 −15 mobile/wp8/wp8-emulator-services.ts
+2 −2 project-helper.ts
+2 −2 resource-loader.ts
+101 −117 services/auto-completion-service.ts
+4 −4 services/cancellation.ts
+6 −9 services/commands-service.ts
+12 −14 services/dynamic-help-service.ts
+42 −49 services/hooks-service.ts
+19 −22 services/html-help-service.ts
+2 −2 services/livesync-service-base.ts
+1 −2 services/message-contract-generator.ts
+7 −10 services/messages-service.ts
+1 −1 services/micro-templating-service.ts
+35 −39 services/project-files-manager.ts
+36 −42 services/typescript-service.ts
+5 −4 services/user-settings-service.ts
+2 −2 static-config-base.ts
+10 −11 sys-info-base.ts
+34 −37 test/unit-tests/file-system.ts
+4 −5 test/unit-tests/messages-service.ts
+15 −16 test/unit-tests/mobile/android-device-file-system.ts
+14 −14 test/unit-tests/mobile/project-files-manager.ts
+33 −37 validators/iTunes-validator.ts
2 changes: 1 addition & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Configuration extends ConfigBase implements IConfiguration { // Use
/*don't require logger and everything that has logger as dependency in config.js due to cyclic dependency*/
constructor(protected $fs: IFileSystem) {
super($fs);
_.extend(this, this.loadConfig("config").wait());
_.extend(this, this.loadConfig("config"));
}
}
$injector.register("config", Configuration);
Expand Down
8 changes: 4 additions & 4 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,16 @@ interface IXmlValidator {
/**
* Checks the passed xml files for errors and if such exists, print them on the stdout.
* @param {string[]} sourceFiles Files to be checked. Only the ones that ends with .xml are filtered.
* @return {IFuture<boolean>} true in case there are no errors in specified files and false in case there's at least one error.
* @return {boolean} true in case there are no errors in specified files and false in case there's at least one error.
*/
validateXmlFiles(sourceFiles: string[]): IFuture<boolean>;
validateXmlFiles(sourceFiles: string[]): boolean;

/**
* Checks the passed xml file for errors and returns them as a result.
* @param {string} sourceFile File to be checked.
* @return {IFuture<string>} The errors detected (as a single string) or null in case there are no errors.
* @return {string} The errors detected (as a single string) or null in case there are no errors.
*/
getXmlFileErrors(sourceFile: string): IFuture<string>;
getXmlFileErrors(sourceFile: string): string;
}

/**
Expand Down
Loading