Add quickstart commands

This commit is contained in:
lowlighter
2021-02-04 22:46:47 +01:00
parent 96d59e94c1
commit 5eaf603357
10 changed files with 154 additions and 3 deletions

43
.github/quickstart/index.mjs vendored Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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

View File

@@ -0,0 +1,5 @@
[
"base.header",
"base.activity+community",
"base.repositories"
]