Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
light-generator
Advanced tools
一个非常轻量的脚手架生成器,用于各种脚手架的生成。
核心功能:
在很多时候,我们希望自己的模板在不同的脚手架(CLI)工具中都能够调用,基于这个需求,我们开发了比较轻量级的生成器,可以嵌入到不同的脚手架工具中。
这个包只提供生成模板的能力和所希望的 API,外部可以对接不同的 CLI 工具。
import {LightGenerator} from 'light-generator';
const generator = new LightGenerator().defineNpmPackage({
npmPackage: 'egg-boilerplate-simple',
targetPath,
npmInstall: true,
});
await generator.run({
name: 'demo'
});
默认会将模板中的下划线前缀的文件替换为正常文件名,并替换模板中的 {{xxx}}
变量为传入的参数。
LightGenerator
通过定义一系列格式,返回一个特定格式的生成器,执行该生成器即可拿到相应的结果。
interface LightGenerator {
defineLocalPath(options): CommonGenerator;
defineNpmPackage(options): CommonGenerator;
}
interface CommonGenerator {
async getParameterList(): object;
async run(replaceParameter?: object);
}
生成本地路径的模板
示例
const localGenerator = new LightGenerator().defineLocalPath({
templatePath: join(__dirname, './fixtures/boilerplate-2'),
targetPath
});
生成一个 npm 包资源类型的模板
示例
const npmGenerator = new LightGenerator().defineNpmPackage({
npmPackage: 'egg-boilerplate-simple',
targetPath
});
由于本模块会下载 npm 包到本地特定的临时目录,可以通过暴露的方法清理该目录。
注意,此方法为静态方法。
await LightGenerator.cleanCache();
生成器可以在生成完模板文件后,做一些自定义的操作,比如替换内容,修改文件名等。
简单的来说,规则是一个函数,参数为当前文件路径,用于对当前文件进行操作。
示例
import {LightGenerator} from 'light-generator';
const customRule = async (currentFilePath) => {
// TODO
}
const generator = new LightGenerator({
rules: [customRule]
});
内置了一些默认规则,比如
这些规则默认已经内置,并且生效。
示例
import {LightGenerator, ignoreRule} from 'light-generator';
const generator = new LightGenerator({
rules: [ignoreRule]
});
如果不希望这些规则生效,请在初始化时关闭,并自行传递规则。
示例
import {LightGenerator, ignoreRule} from 'light-generator';
const generator = new LightGenerator({
disableDefaultRule: true,
rules: [ignoreRule]
});
默认情况下,会拷贝整个模板目录的内容到目标目录,但是在 package.json
中加入 boilerplateConfig
段落可以额外配置这个行为。
{
"boilerplateConfig": {
"root": "template",
"replaceParameter": "index.js",
"replaceFile": [
"src/index.ts"
],
"rule": []
}
}
也可以支持通配符
{
"boilerplateConfig": {
"root": "template",
"replaceParameter": "index.js",
"replaceFile": [
"*.ts"
]
}
}
参数
boilerplateConfig
字段,默认为 boilerplate
目录index.js
README.md
,相对于 root,请一定填写规则修改前的文件名,支持 minimatch 格式的通配符module.exports = async () => {}
boilerplateConfig
配置内容const generator = new LightGenerator().defineNpmPackage({
npmPackage: 'egg-boilerplate-simple',
targetPath
});
/**
* 模板下载完毕,准备创建
*/
generator.onTemplateReady(() => {
// log
});
/**
* 每个文件被拷贝时触发
*/
generator.onFileCreated((data: {
sourceFullFilePath: string;
targetFullFilePath: string;
destDir: string;
relativeFilePath: string;
}) => {
// log
});
await generator.run({
name: 'demo'
});
此模块部分核心代码从 serverless 模块中抽取。
FAQs
light generator for generate a boilerplate
The npm package light-generator receives a total of 21 weekly downloads. As such, light-generator popularity was classified as not popular.
We found that light-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.