Add quickstart commands
This commit is contained in:
43
.github/quickstart/index.mjs
vendored
Normal file
43
.github/quickstart/index.mjs
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
//Imports
|
||||||
|
import fs from "fs"
|
||||||
|
import paths from "path"
|
||||||
|
import url from "url"
|
||||||
|
import ejs from "ejs"
|
||||||
|
|
||||||
|
//Mode
|
||||||
|
const [mode, name] = process.argv.slice(2)
|
||||||
|
|
||||||
|
//Paths
|
||||||
|
const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)), "../..")
|
||||||
|
const __quickstart = paths.join(__metrics, ".github/quickstart")
|
||||||
|
|
||||||
|
//Check arguments
|
||||||
|
if ((!mode)||(!name))
|
||||||
|
throw new Error(`Usage is "npm run quickstart -- <mode> <name>"`)
|
||||||
|
if (!["plugin", "template"].includes(mode))
|
||||||
|
throw new Error(`Unsupported mode ${mode}`)
|
||||||
|
|
||||||
|
//Check if target directory already exists
|
||||||
|
const target = paths.join(__metrics, `source/${mode}s`, name)
|
||||||
|
if (fs.existsSync(target))
|
||||||
|
throw new Error(`A ${mode} named ${name} already exists!`)
|
||||||
|
|
||||||
|
//Copy quickstart content
|
||||||
|
console.log(`quickstart for ${mode}`)
|
||||||
|
await fs.promises.mkdir(target)
|
||||||
|
await rcopy(paths.join(__quickstart, mode), target)
|
||||||
|
|
||||||
|
//Recursive copy
|
||||||
|
async function rcopy(from, to) {
|
||||||
|
for (const file of await fs.promises.readdir(from)) {
|
||||||
|
const path = paths.join(from, file)
|
||||||
|
if ((await fs.promises.lstat(path)).isDirectory()) {
|
||||||
|
await fs.promises.mkdir(paths.join(to, file))
|
||||||
|
await rcopy(path, paths.join(to, file))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log(`copying ${path} to ${paths.join(to, file)}`)
|
||||||
|
await fs.promises.writeFile(paths.join(to, file), await ejs.renderFile(path, {name}, {async:true}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
.github/quickstart/plugin/README.md
vendored
Normal file
19
.github/quickstart/plugin/README.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
### 🧩 <%= `${name.charAt(0).toLocaleUpperCase()}${name.substring(1)}` %>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<td align="center">
|
||||||
|
<img src="">
|
||||||
|
<img width="900" height="1" alt="">
|
||||||
|
</td>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
#### ℹ️ Examples workflows
|
||||||
|
|
||||||
|
[➡️ Available options for this plugin](metadata.yml)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: lowlighter/metrics@latest
|
||||||
|
with:
|
||||||
|
# ... other options
|
||||||
|
plugin_<%= name %>: yes
|
||||||
|
```
|
||||||
15
.github/quickstart/plugin/index.mjs
vendored
Normal file
15
.github/quickstart/plugin/index.mjs
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
//Setup
|
||||||
|
export default async function ({login, q, imports, data, computed, rest, graphql, queries, account}, {enabled = false} = {}) {
|
||||||
|
//Plugin execution
|
||||||
|
try {
|
||||||
|
//Check if plugin is enabled and requirements are met
|
||||||
|
if ((!enabled)||(!q.<%= name %>))
|
||||||
|
return null
|
||||||
|
//Results
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
//Handle errors
|
||||||
|
catch (error) {
|
||||||
|
throw {error:{message:"An error occured", instance:error}}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
.github/quickstart/plugin/metadata.yml
vendored
Normal file
19
.github/quickstart/plugin/metadata.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
name: "🧩 <%= `${name.charAt(0).toLocaleUpperCase()}${name.substring(1)}` %>"
|
||||||
|
|
||||||
|
# Estimate of how many GitHub requests will be used
|
||||||
|
cost: N/A
|
||||||
|
|
||||||
|
# Supported modes
|
||||||
|
supports:
|
||||||
|
- user
|
||||||
|
- organization
|
||||||
|
- repository
|
||||||
|
|
||||||
|
# Inputs list
|
||||||
|
inputs:
|
||||||
|
|
||||||
|
# Enable or disable plugin
|
||||||
|
plugin_<%= name %>:
|
||||||
|
description: description
|
||||||
|
type: boolean
|
||||||
|
default: no
|
||||||
5
.github/quickstart/plugin/tests.yml
vendored
Normal file
5
.github/quickstart/plugin/tests.yml
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
- name: <%= `${name.charAt(0).toLocaleUpperCase()}${name.substring(1)}` %> plugin (default)
|
||||||
|
uses: lowlighter/metrics@latest
|
||||||
|
with:
|
||||||
|
token: MOCKED_TOKEN
|
||||||
|
plugin_<%= name %>: yes
|
||||||
18
.github/quickstart/template/README.md
vendored
Normal file
18
.github/quickstart/template/README.md
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
### 📕 <%= `${name.charAt(0).toLocaleUpperCase()}${name.substring(1)}` %> template
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<td align="center">
|
||||||
|
<img src="">
|
||||||
|
<img width="900" height="1" alt="">
|
||||||
|
</td>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
#### ℹ️ Examples workflows
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: lowlighter/metrics@latest
|
||||||
|
with:
|
||||||
|
# ... other options
|
||||||
|
setup_community_templates: user/metrics@master:<%= name %>
|
||||||
|
template: "@<%= name %>"
|
||||||
|
```
|
||||||
16
.github/quickstart/template/image.svg
vendored
Normal file
16
.github/quickstart/template/image.svg
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="480" height="99999" class="<%%= !animated ? 'no-animations' : '' %>">
|
||||||
|
|
||||||
|
<defs><style><%%= fonts %></style></defs>
|
||||||
|
<style><%%= style %></style>
|
||||||
|
|
||||||
|
<foreignObject x="0" y="0" width="100%" height="100%">
|
||||||
|
<div xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<%% for (const partial of [...partials]) { %>
|
||||||
|
<%%- await include(`partials/${partial}.ejs`) %>
|
||||||
|
<%% } %>
|
||||||
|
|
||||||
|
<div id="metrics-end"></div>
|
||||||
|
</div>
|
||||||
|
</foreignObject>
|
||||||
|
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 538 B |
5
.github/quickstart/template/partials/_.json
vendored
Normal file
5
.github/quickstart/template/partials/_.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[
|
||||||
|
"base.header",
|
||||||
|
"base.activity+community",
|
||||||
|
"base.repositories"
|
||||||
|
]
|
||||||
@@ -216,6 +216,11 @@ Metrics does not really accept contributions on [default templates](https://gith
|
|||||||
|
|
||||||
If you make something awesome, don't hesistate to share it!
|
If you make something awesome, don't hesistate to share it!
|
||||||
|
|
||||||
|
For a quick start, use:
|
||||||
|
```shell
|
||||||
|
npm run quickstart -- template <template_name>
|
||||||
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>💬 Creating a new template from scratch</summary>
|
<summary>💬 Creating a new template from scratch</summary>
|
||||||
|
|
||||||
@@ -248,7 +253,7 @@ It must contain at least the following:
|
|||||||
|
|
||||||
<table>
|
<table>
|
||||||
<td align="center">
|
<td align="center">
|
||||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.terminal.svg">
|
<img src="">
|
||||||
<img width="900" height="1" alt="">
|
<img width="900" height="1" alt="">
|
||||||
</td>
|
</td>
|
||||||
</table>
|
</table>
|
||||||
@@ -355,6 +360,11 @@ Plugins are self-sufficient and independant code functions that gather additiona
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
For a quick start, use:
|
||||||
|
```shell
|
||||||
|
npm run quickstart -- plugin <plugin_name>
|
||||||
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>💬 Creating a new plugin</summary>
|
<summary>💬 Creating a new plugin</summary>
|
||||||
|
|
||||||
@@ -615,7 +625,7 @@ It must contain at least the following:
|
|||||||
- uses: lowlighter/metrics@latest
|
- uses: lowlighter/metrics@latest
|
||||||
with:
|
with:
|
||||||
# ... other options
|
# ... other options
|
||||||
plugin_gists: yes
|
plugin_custom: yes
|
||||||
'''
|
'''
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
"start": "node source/app/web/index.mjs",
|
"start": "node source/app/web/index.mjs",
|
||||||
"test": "npx jest",
|
"test": "npx jest",
|
||||||
"index": "node .github/index.mjs",
|
"index": "node .github/index.mjs",
|
||||||
"upgrade": "npm install @actions/core@latest @actions/github@latest @octokit/graphql@latest @octokit/rest@latest axios@latest compression@latest ejs@latest express@latest express-rate-limit@latest faker@latest image-to-base64@latest js-yaml@latest memory-cache@latest prismjs@latest puppeteer@latest svgo@latest vue@latest jest@latest libxmljs@latest"
|
"upgrade": "npm install @actions/core@latest @actions/github@latest @octokit/graphql@latest @octokit/rest@latest axios@latest compression@latest ejs@latest express@latest express-rate-limit@latest faker@latest image-to-base64@latest js-yaml@latest memory-cache@latest prismjs@latest puppeteer@latest svgo@latest vue@latest jest@latest libxmljs@latest",
|
||||||
|
"quickstart": "node .github/quickstart/index.mjs"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user