Skip to content

Commit 8a2ab32

Browse files
Fatme HavaluovaFatme Havaluova
authored andcommitted
Install runtime from local path
1 parent 5a520f9 commit 8a2ab32

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

lib/declarations.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
interface INodePackageManager {
22
cache: string;
33
load(config?: any): IFuture<void>;
4-
install(packageName: string, pathToSave?: string, version?: string): IFuture<string>;
4+
install(packageName: string, options?: INpmInstallOptions): IFuture<string>;
5+
}
6+
7+
interface INpmInstallOptions {
8+
pathToSave?: string;
9+
version?: string;
510
}
611

712
interface IStaticConfig extends Config.IStaticConfig { }

lib/node-package-manager.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import semver = require("semver");
77
import shell = require("shelljs");
88
import helpers = require("./common/helpers");
99
import constants = require("./constants");
10+
import options = require("./options");
1011

1112
export class NodePackageManager implements INodePackageManager {
1213
private static NPM_LOAD_FAILED = "Failed to retrieve data from npm. Please try again a little bit later.";
@@ -15,7 +16,8 @@ export class NodePackageManager implements INodePackageManager {
1516
constructor(private $logger: ILogger,
1617
private $errors: IErrors,
1718
private $httpClient: Server.IHttpClient,
18-
private $staticConfig: IStaticConfig) { }
19+
private $staticConfig: IStaticConfig,
20+
private $fs: IFileSystem) { }
1921

2022
public get cache(): string {
2123
return npm.cache;
@@ -33,46 +35,54 @@ export class NodePackageManager implements INodePackageManager {
3335
return future;
3436
}
3537

36-
public install(packageName: string, pathToSave?: string, version?: string): IFuture<string> {
38+
public install(packageName: string, opts?: INpmInstallOptions): IFuture<string> {
3739
return (() => {
3840
try {
3941
this.load().wait(); // It's obligatory to execute load before whatever npm function
40-
pathToSave = pathToSave || npm.cache;
4142
var packageToInstall = packageName;
43+
var pathToSave = (opts && opts.pathToSave) || npm.cache;
44+
var version = (opts && opts.version) || null;
45+
var isSemanticVersioningDisabled = options.frameworkPath ? true : false; // We need to disable sem versioning for local packages
4246

4347
if(version) {
4448
this.validateVersion(packageName, version).wait();
4549
packageToInstall = packageName + "@" + version;
4650
}
4751

48-
this.installCore(packageToInstall, pathToSave).wait();
52+
this.installCore(packageToInstall, pathToSave, isSemanticVersioningDisabled).wait();
4953
} catch(error) {
5054
this.$logger.debug(error);
5155
this.$errors.fail(NodePackageManager.NPM_LOAD_FAILED);
5256
}
5357

54-
return path.join(pathToSave, "node_modules", packageName);
58+
var pathToNodeModules = path.join(pathToSave, "node_modules");
59+
var folders = this.$fs.readDirectory(pathToNodeModules).wait();
60+
return path.join(pathToNodeModules, folders[0]);
5561

5662
}).future<string>()();
5763
}
5864

59-
private installCore(packageName: string, pathToSave: string): IFuture<void> {
65+
private installCore(packageName: string, pathToSave: string, isSemanticVersioningDisabled: boolean): IFuture<void> {
6066
var currentVersion = this.$staticConfig.version;
6167
if(!semver.valid(currentVersion)) {
6268
this.$errors.fail("Invalid version.");
6369
}
6470

65-
var incrementedVersion = semver.inc(currentVersion, constants.ReleaseType.MINOR);
66-
if(packageName.indexOf("@") < 0) {
67-
packageName = packageName + "@<" + incrementedVersion;
71+
if(!isSemanticVersioningDisabled) {
72+
var incrementedVersion = semver.inc(currentVersion, constants.ReleaseType.MINOR);
73+
if(packageName.indexOf("@") < 0) {
74+
packageName = packageName + "@<" + incrementedVersion;
75+
}
6876
}
69-
this.$logger.trace("Installing", packageName);
77+
78+
this.$logger.out("Installing ", packageName);
7079

7180
var future = new Future<void>();
7281
npm.commands["install"](pathToSave, packageName, (err: Error, data: any) => {
7382
if(err) {
7483
future.throw(err);
7584
} else {
85+
this.$logger.out("Installed ", packageName);
7686
future.return(data);
7787
}
7888
});

lib/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var knownOpts:any = {
88
"log" : String,
99
"verbose" : Boolean,
1010
"path" : String,
11+
"frameworkPath": String,
1112
"appid" : String,
1213
"copy-from": String,
1314
"link-to": String,

lib/services/platform-service.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,20 @@ export class PlatformService implements IPlatformService {
8181

8282
this.$logger.out("Copying template files...");
8383

84-
// get path to downloaded framework package
85-
var frameworkDir = this.$npm.install(platformData.frameworkPackageName,
86-
path.join(this.$projectData.platformsDir, platform), version).wait();
87-
frameworkDir = path.join(frameworkDir, constants.PROJECT_FRAMEWORK_FOLDER_NAME);
84+
var packageToInstall = "";
85+
var npmOptions = {
86+
pathToSave: path.join(this.$projectData.platformsDir, platform)
87+
};
88+
89+
if(options.frameworkPath) {
90+
packageToInstall = options.frameworkPath;
91+
} else {
92+
packageToInstall = platformData.frameworkPackageName;
93+
npmOptions["version"] = version;
94+
}
95+
96+
var downloadedPackagePath = this.$npm.install(packageToInstall, npmOptions).wait();
97+
var frameworkDir = path.join(downloadedPackagePath, constants.PROJECT_FRAMEWORK_FOLDER_NAME);
8898

8999
try {
90100
this.addPlatformCore(platformData, frameworkDir).wait();

resources/help.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ Platform-specific usage:
108108

109109
Configures the current project to target the selected platform. When you add a target platform, the Telerik NativeScript CLI adds a corresponding platform-specific subdirectory under the platforms directory. This platform-specific directory contains the necessary files to let you build your project for the target platform.
110110

111+
Options:
112+
--frameworkPath - specifies the path to local runtime. It should be npm package.
113+
111114
In this version of the Telerik NativeScript CLI, you can target iOS and Android, based on your system. You need to have your system configured for development with the target platform.
112115
On Windows systems, you can target Android.
113116
On OS X systems, you can target Android and iOS.

0 commit comments

Comments
 (0)