diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..b0f5afa --- /dev/null +++ b/LICENCE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Jan Kuri + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 7620699..aae8c62 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,58 @@ # morose -Lightweight alternative for private npm registry. +Lightweight alternative for private npm registry heavily inspired by node-reggie. + +morose is currently in development mode. It currently supports: + +- registering/uploading packages +- supports basic semver wildcards (1.1.x) and ranges +- a few basic routes to see what's registered +- all packages info is saved in cache + +Here's what it doesn't do yet: + +- authentication on publish +- searching for packages + +## Installation + +```sh +$ npm install morose -g +``` + +## Usage + +#### Running a Server + +```sh +morose-server +``` + +#### Publishing package to registry + +`cd` into package root directory you want to publish (should have package.json file) and: + +```sh +morose publish [url:port] +``` +where `url` is the HTTP url where `morose-server` is running. ie: + +```sh +morose publish https://morose.example.com:4720 +``` + +you can ofc omit port if morose server is running on port 80. + +#### Installing package from morose server + +```sh +npm install https://morose.example.com:4720/package/[package-name]/latest +``` +or +```sh +npm install https://morose.example.com:4720/package/[package-name]/1.1.0 +``` + +#### LICENCE + +MIT diff --git a/lib/express.ts b/lib/express.ts index 7863bc4..773be7e 100644 --- a/lib/express.ts +++ b/lib/express.ts @@ -5,7 +5,7 @@ import * as busboy from 'busboy'; import * as chalk from 'chalk'; import * as os from 'os'; import * as fs from 'fs'; -import { savePackage, pkgVersions, getPkgData } from './package'; +import { savePackage, pkgVersions, getPkgData, getPkgInfo } from './package'; import { writeFile, rand, prepareRootDirectory, getMoroseVersion } from './utils'; import { initCache } from './cache'; import * as semver from 'semver'; @@ -44,6 +44,7 @@ export class ExpressServer { }); this.app.post('/package/:name/:version', this.publishVersion.bind(this)); this.app.get('/package/:name/:range', this.getPackage.bind(this)); + this.app.get('/info/:name', this.getPackageInfo.bind(this)); } private publishVersion(req: express.Request, res: express.Response) { @@ -88,4 +89,13 @@ export class ExpressServer { res.header('Content-Disposition', `filename=${path.basename(pkgData.file)}`); res.status(200).download(pkgData.file); } + + private getPackageInfo(req: express.Request, res: express.Response) { + let pkgInfo = getPkgInfo(req.params.name); + if (!pkgInfo) { + res.status(404).send(); + } else { + res.status(200).json(pkgInfo); + } + } } diff --git a/lib/package.ts b/lib/package.ts index cd86b13..aa6a560 100644 --- a/lib/package.ts +++ b/lib/package.ts @@ -132,6 +132,23 @@ export function publish(url: string): Observable { }); } +export function getPkgInfo(name: string): any { + let data = getCache(); + + if (!data[name]) { + return null; + } + + return Object.keys(data[name]).map(version => { + let date = new Date(data[name][version].time); + return { + version: version, + time: data[name][version].time, + timeReleased: `${date.toDateString()}, ${date.toTimeString()}` + } + }); +} + export function getPkgData(name: string, version: string): any { let data = getCache(); return data[name][version];