Skip to content

Commit

Permalink
feat: add new module creation CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
bgatellier committed Jun 2, 2024
1 parent a10af3c commit f03792a
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 27 deletions.
5 changes: 0 additions & 5 deletions modules/tpl/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions modules/tpl/src/index.ts

This file was deleted.

9 changes: 9 additions & 0 deletions templates/package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
force: true
---

# Heart {{ name | capitalize }}

_Heart {{ name | capitalize }}_ is a template module which goal is to serve as a codebase for new module creation.

To create a new module, see the _[Create a new module](../../docs/CREATE_NEW_MODULE.md)_ guide.
File renamed without changes.
24 changes: 9 additions & 15 deletions modules/tpl/package.json → templates/package/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@fabernovel/heart-tpl",
"name": "@fabernovel/heart-{{ name | slugify }}",
"version": "4.0.0",
"description": "",
"description": "{{ name }}",
"homepage": "https://heart.fabernovel.com",
"bugs": {
"url": "https://github.com/faberNovel/heart/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/faberNovel/heart.git",
"directory": "modules/tpl"
"directory": "modules/{{ name | slugify }}"
},
"license": "MIT",
"contributors": [],
Expand All @@ -20,16 +20,10 @@
"lib": "lib"
},
"files": [
"lib/**/*",
".env.default",
".env.schema.json"
"lib/**/*"
],
"scripts": {
"build": "rimraf lib && tsc --project tsconfig.build.json",
"build:watch": "npm run build --watch",
"lint": "eslint .",
"prepublishOnly": "npm run build",
"test": "NODE_OPTIONS='--experimental-vm-modules' jest --passWithNoTests"
"prepublishOnly": "moon run common:build"
},
"dependencies": {
"@fabernovel/heart-common": "workspace:^4.0.0"
Expand All @@ -44,11 +38,11 @@
"node": ">=18 <22"
},
"heart": {
"id": "tpl",
"name": "Heart Tpl",
"id": "{{ name | slugify }}",
"name": "Heart {{ name }}",
"service": {
"name": "Tpl",
"logoUrl": "https://raw.githubusercontent.com/faberNovel/heart/main/assets/images/logos/Tpl.png?v=20221126"
"name": "{{ name }}",
"logoUrl": "https://raw.githubusercontent.com/faberNovel/heart/main/assets/images/logos/{{ name | pascal_case }}.png?v=20221126"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{% set class_name = name ~ 'Module' | pascal_case %}

---
to: src//{{ class_name }}.ts
---

import { Module, logger, type ModuleMetadata } from "@fabernovel/heart-common"

export class TplModule extends Module {
export class {{ class_name }} extends Module {
constructor(moduleMetadata: ModuleMetadata, verbose: boolean) {
super(moduleMetadata, verbose)

Expand Down
12 changes: 12 additions & 0 deletions templates/package/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% set class_name = name ~ 'Module' | pascal_case %}

---
to: src//index.ts
---

import type { ModuleIndex, ModuleMetadata } from "@fabernovel/heart-common"
import { {{ class_name }} } from "./{{ class_name }}.js"

export const initialize: ModuleIndex["initialize"] = (moduleMetadata: ModuleMetadata, verbose: boolean) => {
return new {{ class_name }}(moduleMetadata, verbose)
}
31 changes: 31 additions & 0 deletions templates/package/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# https://moonrepo.dev/docs/config/template
$schema: 'https://moonrepo.dev/schemas/template.json'

# REQUIRED: Name of the template in a human readable format.
title: 'Title'

# REQUIRED: Description of what the template is for and other relevant information.
description: 'Description of the template.'

destination: modules/[name | slugify]

# Mapping of variables that will be interpolated and rendered within template files.
# Users will be prompted to provide a value when running the generator.
variables:
name:
prompt: 'Name of your package'
type: 'string'
required: true
order: 1
type:
prompt: 'What does your module do?'
type: 'enum'
values:
- label: Analyzes URLs using a third-party service
value: analysis
- label: Do thing with the results of the analysis
value: listener
- label: Trigger an analysis
value: runner
default: analysis
order: 2
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f03792a

Please sign in to comment.