diff --git a/.github/quickstart/index.mjs b/.github/quickstart/index.mjs new file mode 100644 index 00000000..6df2f5c8 --- /dev/null +++ b/.github/quickstart/index.mjs @@ -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 -- "`) + 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})) + } + } + } diff --git a/.github/quickstart/plugin/README.md b/.github/quickstart/plugin/README.md new file mode 100644 index 00000000..18a0ff9e --- /dev/null +++ b/.github/quickstart/plugin/README.md @@ -0,0 +1,19 @@ +### 🧩 <%= `${name.charAt(0).toLocaleUpperCase()}${name.substring(1)}` %> + + + +
+ + +
+ +#### ℹ️ Examples workflows + +[➡️ Available options for this plugin](metadata.yml) + +```yaml +- uses: lowlighter/metrics@latest + with: + # ... other options + plugin_<%= name %>: yes +``` \ No newline at end of file diff --git a/.github/quickstart/plugin/index.mjs b/.github/quickstart/plugin/index.mjs new file mode 100644 index 00000000..f5cb2cbf --- /dev/null +++ b/.github/quickstart/plugin/index.mjs @@ -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}} + } + } \ No newline at end of file diff --git a/.github/quickstart/plugin/metadata.yml b/.github/quickstart/plugin/metadata.yml new file mode 100644 index 00000000..b99c23dd --- /dev/null +++ b/.github/quickstart/plugin/metadata.yml @@ -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 \ No newline at end of file diff --git a/.github/quickstart/plugin/tests.yml b/.github/quickstart/plugin/tests.yml new file mode 100644 index 00000000..01eb2c39 --- /dev/null +++ b/.github/quickstart/plugin/tests.yml @@ -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 \ No newline at end of file diff --git a/.github/quickstart/template/README.md b/.github/quickstart/template/README.md new file mode 100644 index 00000000..28ab23d4 --- /dev/null +++ b/.github/quickstart/template/README.md @@ -0,0 +1,18 @@ +### 📕 <%= `${name.charAt(0).toLocaleUpperCase()}${name.substring(1)}` %> template + + + +
+ + +
+ +#### ℹ️ Examples workflows + +```yaml +- uses: lowlighter/metrics@latest + with: + # ... other options + setup_community_templates: user/metrics@master:<%= name %> + template: "@<%= name %>" +``` \ No newline at end of file diff --git a/.github/quickstart/template/image.svg b/.github/quickstart/template/image.svg new file mode 100644 index 00000000..35eb3cf2 --- /dev/null +++ b/.github/quickstart/template/image.svg @@ -0,0 +1,16 @@ + + + + + + +
+ <%% for (const partial of [...partials]) { %> + <%%- await include(`partials/${partial}.ejs`) %> + <%% } %> + +
+
+
+ +
\ No newline at end of file diff --git a/.github/quickstart/template/partials/_.json b/.github/quickstart/template/partials/_.json new file mode 100644 index 00000000..bca1b076 --- /dev/null +++ b/.github/quickstart/template/partials/_.json @@ -0,0 +1,5 @@ +[ + "base.header", + "base.activity+community", + "base.repositories" +] \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 329b90d3..7372108e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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! +For a quick start, use: +```shell +npm run quickstart -- template +``` +
💬 Creating a new template from scratch @@ -248,7 +253,7 @@ It must contain at least the following:
- +
@@ -355,6 +360,11 @@ Plugins are self-sufficient and independant code functions that gather additiona
+For a quick start, use: +```shell +npm run quickstart -- plugin +``` +
💬 Creating a new plugin @@ -615,7 +625,7 @@ It must contain at least the following: - uses: lowlighter/metrics@latest with: # ... other options - plugin_gists: yes + plugin_custom: yes ''' ``` diff --git a/package.json b/package.json index d0cdfc66..6dd32792 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "start": "node source/app/web/index.mjs", "test": "npx jest", "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": { "type": "git",