Skip to content

Basic semantic versioning #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ export var DEFAULT_PROJECT_NAME = "HelloNativescript";
export var APP_RESOURCES_FOLDER_NAME = "App_Resources";
export var PROJECT_FRAMEWORK_FOLDER_NAME = "framework";

export class ReleaseType {
static MAJOR = "major";
static PREMAJOR = "premajor";
static MINOR = "minor";
static PREMINOR = "preminor";
static PATCH = "patch";
static PREPATCH = "prepatch";
static PRERELEASE = "prerelease";
}


1 change: 1 addition & 0 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ interface INodePackageManager {
}

interface IStaticConfig extends Config.IStaticConfig { }

12 changes: 11 additions & 1 deletion lib/definitions/semver.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

declare module "semver" {
function gt(version1: string, version2: string): boolean;
function lt(version1: string, version2: string): boolean;
}
function valid(version: string): boolean;
function inc(version: string, release: string): string;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make the release string overload by constant will all correct values.

function inc(version: string, release: "major"): string;
function inc(version: string, release: 'premajor'): string;
function inc(version: string, release: 'minor'): string;
function inc(version: string, release: 'preminor'): string;
function inc(version: string, release: 'patch'): string;
function inc(version: string, release: 'prepatch'): string;
function inc(version: string, release: 'prerelease'): string;
}
21 changes: 16 additions & 5 deletions lib/node-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import Future = require("fibers/future");
import npm = require("npm");
import path = require("path");
import semver = require("semver");
import shell = require("shelljs");
import helpers = require("./common/helpers");
import constants = require("./constants");

export class NodePackageManager implements INodePackageManager {
private static NPM_LOAD_FAILED = "Failed to retrieve data from npm. Please try again a little bit later.";
private static NPM_REGISTRY_URL = "http://registry.npmjs.org/";

constructor(private $logger: ILogger,
private $errors: IErrors,
private $httpClient: Server.IHttpClient) { }
private $httpClient: Server.IHttpClient,
private $staticConfig: IStaticConfig) { }

public get cache(): string {
return npm.cache;
Expand Down Expand Up @@ -43,7 +46,6 @@ export class NodePackageManager implements INodePackageManager {
}

this.installCore(pathToSave, packageToInstall).wait();

} catch(error) {
this.$logger.debug(error);
this.$errors.fail(NodePackageManager.NPM_LOAD_FAILED);
Expand All @@ -54,9 +56,18 @@ export class NodePackageManager implements INodePackageManager {
}).future<string>()();
}

private installCore(where: string, what: string): IFuture<any> {
var future = new Future<any>();
npm.commands["install"](where, what, (err, data) => {
private installCore(packageName: string, pathToSave: string): IFuture<void> {
var currentVersion = this.$staticConfig.version;
if(!semver.valid(currentVersion)) {
this.$errors.fail("Invalid version.");
}

var incrementedVersion = semver.inc(currentVersion, constants.ReleaseType.MINOR);
packageName = packageName + "@" + "<" + incrementedVersion;
this.$logger.trace("Installing", packageName);

var future = new Future<void>();
npm.commands["install"](pathToSave, packageName, (err, data) => {
if(err) {
future.throw(err);
} else {
Expand Down