Skip to content
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

Add semver2 support to npm #237

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 0 additions & 5 deletions init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ try {
if ($PSCmdlet.ShouldProcess("$PSScriptRoot\src\nerdbank-gitversioning.npm", "npm install")) {
npm install --loglevel error
}

Write-Host "Restoring Typings..." -ForegroundColor Yellow
if ($PSCmdlet.ShouldProcess("$PSScriptRoot\src\nerdbank-gitversioning.npm", "typings install")) {
.\node_modules\.bin\typings install
}
} finally {
Pop-Location
}
Expand Down
27 changes: 15 additions & 12 deletions src/nerdbank-gitversioning.npm/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ var del = require('del');
var path = require('path');

const outDir = 'out';
var tsProject = ts.createProject('tsconfig.json', { declarationFiles: true });
var tsProject = ts.createProject('tsconfig.json', {
declarationFiles: true,
typescript: require('typescript'),
});

gulp.task('tsc', function() {
var tsResult = gulp.src(['*.ts', 'ts/**/*.ts', 'typings/**/*.ts'])
gulp.task('tsc', function () {
var tsResult = gulp.src(['*.ts', 'ts/**/*.ts', 'node_modules/@types/**/index.d.ts'])
// .pipe(tslint())
.pipe(sourcemaps.init())
.pipe(ts(tsProject));
Expand All @@ -25,7 +28,7 @@ gulp.task('tsc', function() {
]);
});

gulp.task('copyPackageContents', ['tsc'], function() {
gulp.task('copyPackageContents', ['tsc'], function () {
return gulp
.src([
'package.json',
Expand All @@ -35,35 +38,35 @@ gulp.task('copyPackageContents', ['tsc'], function() {
.pipe(gulp.dest(outDir));
});

gulp.task('setPackageVersion', ['copyPackageContents'], function() {
gulp.task('setPackageVersion', ['copyPackageContents'], function () {
var nbgv = require(`./${outDir}`);
return nbgv.setPackageVersion(outDir, '.');
});

gulp.task('package', ['setPackageVersion'], function() {
gulp.task('package', ['setPackageVersion'], function () {
var afs = require('./out/asyncio');
var binDir = '../../bin/js';
var binDir = '../../bin/js';
return afs.mkdirIfNotExistAsync(binDir)
.then(function() {
.then(function () {
var ap = require('./out/asyncprocess');
return ap.execAsync(`npm pack "${path.join(__dirname, outDir)}"`, { cwd: binDir });
});
});

gulp.task('clean', function() {
gulp.task('clean', function () {
return del([
outDir
])
});

gulp.task('default', ['package'], function() {
gulp.task('default', ['package'], function () {
});

gulp.task('watch', ['tsc'], function() {
gulp.task('watch', ['tsc'], function () {
return gulp.watch('**/*.ts', ['tsc']);
});

gulp.task('test', ['tsc'], async function() {
gulp.task('test', ['tsc'], async function () {
var nbgv = require('./out');
var v = await nbgv.getVersion();
console.log(v);
Expand Down
4 changes: 2 additions & 2 deletions src/nerdbank-gitversioning.npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"versioning"
],
"devDependencies": {
"@types/node": "^10.12.0",
"del": "^2.2.0",
"gulp": "^3.9.1",
"gulp-sourcemaps": "1.6.0",
"gulp-typescript": "2.13.6",
"gulp-util": "^3.0.7",
"merge2": "1.0.2",
"path": "^0.12.7",
"typescript": "1.8.10",
"typings": "1.3.3"
"typescript": "^2.9.2"
},
"dependencies": {
"camel-case": "^3.0.0"
Expand Down
11 changes: 6 additions & 5 deletions src/nerdbank-gitversioning.npm/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';

import * as fs from 'fs';
import * as path from 'path';
var camelCase = require('camel-case')
import {execAsync} from './asyncprocess';
import { execAsync } from './asyncprocess';

const nbgvPath = 'nbgv.cli';

Expand Down Expand Up @@ -61,13 +60,15 @@ export async function getVersion(projectDirectory?: string): Promise<IGitVersion
* Sets an NPM package version based on the git height and version.json.
* @param packageDirectory The directory of the package about to be published.
* @param srcDirectory The directory of the source code behind the package, if different than the packageDirectory.
* @param semVer The version of semver to use in the package versioning.
*/
export async function setPackageVersion(packageDirectory?: string, srcDirectory?: string) {
export async function setPackageVersion(packageDirectory?: string, srcDirectory?: string, semVer: 1 | 2 = 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than a parameter, can we follow the pattern we use for NuGet packages, by adding a field to version.json to indicate which semver version to use?

https://github.com/AArnott/Nerdbank.GitVersioning/blob/master/doc/versionJson.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good; I'll look into it. In the meantime, I've opened #238 which just includes the typescript upgrade, typings removal and some other minor cleanup changes.

packageDirectory = packageDirectory || '.';
srcDirectory = srcDirectory || packageDirectory;
const gitVersion = await getVersion(srcDirectory);
console.log(`Setting package version to ${gitVersion.semVer1}`);
var result = await execAsync(`npm version ${gitVersion.semVer1} --no-git-tag-version`, { cwd: packageDirectory });
const version = semVer === 1 ? gitVersion.semVer1 : gitVersion.semVer2;
console.log(`Setting package version to ${version}`);
var result = await execAsync(`npm version ${version} --no-git-tag-version`, { cwd: packageDirectory });
if (result.stderr) {
console.log(result.stderr);
}
Expand Down
28 changes: 16 additions & 12 deletions src/nerdbank-gitversioning.npm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"compilerOptions": {
"target": "es6",
"declaration": true,
"module": "commonjs",
"sourceMap": true,
"noImplicitAny": false,
"outDir": "js"
},
"exclude": [
"node_modules",
"js"
]
"compilerOptions": {
"target": "es6",
"declaration": true,
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"noImplicitAny": false,
"outDir": "js"
},
"types": [
"node"
],
"exclude": [
"node_modules",
"js"
]
}
10 changes: 0 additions & 10 deletions src/nerdbank-gitversioning.npm/typings.json

This file was deleted.