npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hrm-common-script

v0.0.6

Published

通用型脚本模块

Downloads

2

Readme

设计思路 通过注入sequelize实例(以后支持mongoose、typeorm等)到脚本框架内,实现自动化脚本运维。


使用方法 1 编辑具体脚本文件,继承 BaseScript 这个抽象类就可以了。

*** aaa.script.ts ***
import { BaseScript } from 'hrm-common-script';

export class AaaScript extends BaseScript {
	// [执行后可修改] 是否可以重复执行脚本
	// 强调是否可以。仅作为标识而已
    public readonly isRepeatable: boolean = true;
	// [执行后可修改] 是否要重复执行脚本
	// [!!!] 若为true, 则每次执行命令, 均会执行该脚本
	public readonly repeatExec: boolean = true;
	// module 和 name, 两者一起需要绝对唯一
	// [执行后不可变] 脚本名称
    public readonly name: string = 'Aaa';
	// [执行后不可变] 脚本所在微服务名称
    public readonly module: string = 'hrm-api';
	// [执行后可修改] 脚本执行顺序, 最好也写在脚本文件名上, 方便识别
	// 值越高越后执行
	public readonly sequence: number = 1;

	// 执行脚本
	// 如果有异常, 直接 throw 出来即可
    public async execute() {
        console.log('do script');
    }
}

2 注入数据库实例到 ScriptFramework 里,并配置好相关参数,以及配置具体脚本文件(可以采用index.ts方式,或者一个一个填进对象里也可以)

*** script.ts ***
import { ScriptFramework } from 'hrm-common-script';
import { Sequelize } from 'sequelize';
import * as Scripts from './index';
import { SequelizeInstance } from '../database/sequelize';

class Script extends ScriptFramework {
    constructor(sequelizeInstance: Sequelize) {
        super({
            scripts: Scripts,
            sequelizeInstance,
            exitWhenExecuted: true,
        });
    }
}

const script = new Script(SequelizeInstance);
script.execute();

3 package.json 里的 scripts 属性,配置相应的目录即可

"script": "ts-node ./src/script/script.ts"

4 需要执行脚本的时候,输入命令即可

npm run script