您的包裹可能需要更多的工作。我推荐 Sinopia Server 来托管你的内部 npm 包。
https://github.com/rlidwka/sinopia
要将其作为服务运行,请使用此处的 init.d 脚本。
https://github.com/ramiel/sinopia-scripts
配置文件位置/etc/sinopia/config.yaml
要创建 npm 包并将其发布到 sinopia,我建议使用 gulp 任务运行程序更改此脚本:
var bump = require('gulp-bump'),
del = require('del'),
exec = require('child_process').exec,
gulp = require('gulp'),
merge = require('merge2'),
typescript = require('gulp-typescript'),
fs = require('fs');
gulp.task('clean', function () {
del(['dist/*']);
});
gulp.task('bump', ['clean'], function () {
gulp.src('./package.json')
.pipe(bump({
type: 'patch'
}))
.pipe(gulp.dest('./'));
});
gulp.task('bundle', ['bump'], function () {
var tsResult = gulp.src('lib/*.ts')
.pipe(typescript({
module: "commonjs",
target: "es5",
noImplicitAny: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
outDir: "dist/",
rootDir: "lib/",
sourceMap: true,
declaration: true,
moduleResolution: "node",
removeComments: false,
"lib": [
"es2017",
"es2016.array.include",
"dom"
],
types: ["jasmine"]
}));
return merge([
tsResult.dts.pipe(gulp.dest('dist/')),
tsResult.js.pipe(gulp.dest('dist/'))
]);
});
gulp.task('copy', ['bundle'], () => {
gulp.src(['README.md'])
.pipe(gulp.dest('dist/'));
});
gulp.task('package', ['copy'], () => {
const pkgjson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
delete pkgjson.scripts;
delete pkgjson.devDependencies;
const filepath = './dist/package.json';
fs.writeFileSync(filepath, JSON.stringify(pkgjson, null, 2), 'utf-8');
});
gulp.task('git-add', ['package'], function (cb) {
exec('git add -A', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('git-commit', ['git-add'], function (cb) {
var package = require('./package.json');
exec('git commit -m "Version ' + package.version + ' release."', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('git-push', ['git-commit'], function (cb) {
exec('git push', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('publish', ['git-push'], function (cb) {
exec('npm publish ./dist', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
这定义了几个命令。
如果您运行 gulp publish,它将按顺序运行所有命令,清理构建目录,打包文件,提交,推送,然后发布包。