Skip to content

Commit 1589ef7

Browse files
committed
feat: init source
1 parent 8de4e43 commit 1589ef7

File tree

9 files changed

+3163
-24
lines changed

9 files changed

+3163
-24
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: create-github-release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
create-github-release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/create-release@v1
14+
env:
15+
# This token is provided by Actions, you do not need to create your own token
16+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
17+
with:
18+
tag_name: ${{github.ref}}
19+
release_name: Release ${{github.ref}}

.github/workflows/publish-npm.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: publish-npm
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
publish-npm:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v1
14+
with:
15+
node-version: 12
16+
registry-url: https://registry.npmjs.org
17+
- name: Publish package
18+
run: yarn publish --access public
19+
env:
20+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.huskyrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hooks": {
3+
"pre-commit": "pretty-quick --staged --pattern \"**/*.*(json|js|ts|yml|md)\"",
4+
}
5+
}

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const config = require('@boringcodes/prettier-config');
2+
3+
module.exports = config;

README.md

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,73 @@
11
<div align="center">
2-
<h1>repo-template</h1>
3-
<p>Boring GitHub Repository Template</p>
2+
<h1>create-dotgithub</h1>
3+
<p>Boring GitHub Dotfiles Generator (download from <a href="https://github.com/boringcodes/dotgithub">boringcodes/dotgithub</a>)</p>
44

5-
<div>
6-
<a href="https://github.com/boringcodes/repo-template/commits" aria-label="Commitizen Friendly">
5+
<p>
6+
<a href="https://github.com/boringcodes/create-dotgithub/commits" aria-label="Commitizen Friendly">
77
<img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square">
88
</a>
9-
<a href="https://github.com/boringcodes/repo-template" aria-label="Prettier Code Style">
9+
<a href="https://github.com/boringcodes/create-dotgithub" aria-label="Prettier Code Style">
1010
<img src="https://img.shields.io/badge/code_style-prettier-brightgreen?style=flat-square">
1111
</a>
12-
<a href="https://github.com/boringcodes/repo-template/actions" aria-label="GitHub Workflow Status">
13-
<img src="https://img.shields.io/github/workflow/status/boringcodes/repo-template/main?style=flat-square">
12+
<a href="https://github.com/boringcodes/create-dotgithub/actions" aria-label="GitHub Workflow Status">
13+
<img src="https://img.shields.io/github/workflow/status/boringcodes/create-dotgithub/main?style=flat-square">
1414
</a>
15-
<a href="https://david-dm.org/boringcodes/repo-template" aria-label="Dependencies Status">
16-
<img src="https://img.shields.io/david/boringcodes/repo-template?style=flat-square">
15+
<a href="https://david-dm.org/boringcodes/create-dotgithub" aria-label="Dependencies Status">
16+
<img src="https://img.shields.io/david/boringcodes/create-dotgithub?style=flat-square">
1717
</a>
18-
<a href="https://www.npmjs.com/package/@boringcodes/repo-template" aria-label="NPM Version">
19-
<img src="https://img.shields.io/npm/v/@boringcodes/repo-template?color=brightgreen&style=flat-square">
18+
<a href="https://www.npmjs.com/package/generator-create-dotgithub" aria-label="NPM Version">
19+
<img src="https://img.shields.io/npm/v/generator-create-dotgithub?color=brightgreen&style=flat-square">
2020
</a>
21-
<a href="https://www.npmjs.com/package/@boringcodes/repo-template" aria-label="NPM Downloads">
22-
<img src="https://img.shields.io/npm/dm/@boringcodes/repo-template?style=flat-square">
21+
<a href="https://www.npmjs.com/package/generator-create-dotgithub" aria-label="NPM Downloads">
22+
<img src="https://img.shields.io/npm/dm/generator-create-dotgithub?style=flat-square">
2323
</a>
24-
<a href="https://github.com/boringcodes/repo-template/blob/master/LICENSE" aria-label="MIT License">
25-
<img src="https://img.shields.io/github/license/boringcodes/repo-template?color=brightgreen&style=flat-square">
24+
<a href="https://github.com/boringcodes/create-dotgithub/blob/master/LICENSE" aria-label="MIT License">
25+
<img src="https://img.shields.io/github/license/boringcodes/create-dotgithub?color=brightgreen&style=flat-square">
2626
</a>
2727
<a href="https://github.com/boringcodes" aria-label="BoringCodes Verified">
2828
<img src="https://img.shields.io/badge/boringcodes-verified-brightgreen?style=flat-square">
2929
</a>
30-
</div>
30+
</p>
31+
32+
<img src="banner.png">
3133
</div>
3234

33-
## Installation
35+
## Features
36+
37+
- [x] Workflows
38+
- [ ] Actions
39+
40+
## Install
41+
42+
Make sure `yeoman` is installed
43+
44+
```sh
45+
$ yarn global add yo
46+
```
3447

35-
Use the package manager to install foobar
48+
Then install the generator
3649

37-
```bash
38-
yarn add foobar
50+
```sh
51+
$ yarn global add generator-create-dotgithub
3952
```
4053

4154
## Usage
4255

43-
```javascript
44-
import foobar from 'foobar';
56+
Then navigate to the root directory and run the following command to generate source
57+
58+
```sh
59+
$ yo create-dotgithub
60+
```
4561

46-
foobar();
62+
This scaffolds out
63+
64+
```
65+
├── .github
66+
│ └── actions
67+
│ │   └── generated-action.yml
68+
│ └── workflows
69+
│    └── generated-workflow.yml
70+
└── ...
4771
```
4872

4973
## Contributing
@@ -58,4 +82,4 @@ Please make sure to update tests as appropriate.
5882

5983
## License
6084

61-
[MIT](https://github.com/boringcodes/repo-template/blob/master/LICENSE)
85+
[MIT](https://github.com/boringcodes/create-dotgithub/blob/master/LICENSE)

banner.png

67.9 KB
Loading

generators/app/index.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const Generator = require('yeoman-generator');
2+
const chalk = require('chalk');
3+
const yosay = require('yosay');
4+
const axios = require('axios').default;
5+
6+
const pkg = require('../../package.json');
7+
8+
const orgName = 'boringcodes';
9+
const repoName = 'dotgithub';
10+
const getApiUrl = (type, sha) => {
11+
const ghApiUrl = 'https://api.github.com';
12+
13+
return `${ghApiUrl}/repos/${orgName}/${repoName}/git/${type}/${sha}`;
14+
};
15+
const findWorkflowsFromTree = (tree) => {
16+
return tree.find(({ path, type }) => path === 'workflows' && type === 'tree');
17+
};
18+
19+
module.exports = class extends Generator {
20+
async prompting() {
21+
this.log(yosay(`Welcome to the ${chalk.red(pkg.name)} generator!`));
22+
23+
console.log(
24+
chalk.greenBright(
25+
`Checking https://github.com/${orgName}/${repoName} repo...\n`,
26+
),
27+
);
28+
const { data: rootDir } = await axios.get(getApiUrl('trees', 'master'));
29+
const { sha } = findWorkflowsFromTree(rootDir.tree);
30+
const { data: workflowsDir } = await axios(getApiUrl('trees', sha));
31+
32+
const prompts = [
33+
{
34+
type: 'list',
35+
name: 'elementSelectedWorkflow',
36+
message: 'Please select the workflow you want to add?',
37+
choices: workflowsDir.tree.map((item) => ({
38+
name: item.path,
39+
value: item,
40+
})),
41+
},
42+
];
43+
44+
const props = await this.prompt(prompts);
45+
this.props = props;
46+
}
47+
48+
async writing() {
49+
const { data: workflowFile } = await axios(
50+
getApiUrl('blobs', this.props.elementSelectedWorkflow.sha),
51+
);
52+
53+
this.fs.write(
54+
`.github/workflows/${this.props.elementSelectedWorkflow.path}`,
55+
Buffer.from(workflowFile.content, 'base64').toString('utf-8'),
56+
);
57+
}
58+
};

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "generator-create-dotgithub",
3+
"version": "0.0.0",
4+
"description": "Boring GitHub Dotfiles Generator (download from boringcodes/dotgithub)",
5+
"homepage": "https://github.com/boringcodes/create-dotgithub",
6+
"bugs": "https://github.com/boringcodes/create-dotgithub/issues",
7+
"license": "MIT",
8+
"author": "BoringCodes <hi@boringcodes.com> (https://boringcodes.com)",
9+
"repository": "https://github.com/boringcodes/create-dotgithub.git",
10+
"main": "generators/app/index.js",
11+
"files": [
12+
"generators"
13+
],
14+
"scripts": {
15+
"purge": "rm -rf node_modules",
16+
"format": "prettier --write \"**/*.*(json|js|ts|yml|md)\"",
17+
"format:check": "prettier --check \"**/*.*(json|js|ts|yml|md)\"",
18+
"release": "standard-version --no-verify",
19+
"release:major": "yarn release --release-as major",
20+
"release:minor": "yarn release --release-as minor",
21+
"release:patch": "yarn release --release-as patch"
22+
},
23+
"keywords": [
24+
"yeoman-generator",
25+
"create-dotgithub"
26+
],
27+
"dependencies": {
28+
"axios": "^0.19.2",
29+
"chalk": "^3.0.0",
30+
"yeoman-generator": "^4.5.0",
31+
"yosay": "^2.0.2"
32+
},
33+
"devDependencies": {
34+
"@boringcodes/prettier-config": "^1.0.0",
35+
"husky": "^4.2.3",
36+
"prettier": "^2.0.2",
37+
"pretty-quick": "^2.0.1",
38+
"standard-version": "^7.1.0"
39+
}
40+
}

0 commit comments

Comments
 (0)