Skip to content

Commit cacaa16

Browse files
committed
Add contents
1 parent 242dde2 commit cacaa16

37 files changed

+10050
-6567
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ node_modules
1010
!.github/
1111
/coverage
1212
/build
13+
.netlify

CODE_OF_CONDUCT.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ further defined and clarified by project maintainers.
5858
## Enforcement
5959

6060
Instances of abusive, harassing, or otherwise unacceptable behavior may be
61-
reported by contacting the project team at {{email}}. All complaints will be
62-
reviewed and investigated and will result in a response that is deemed necessary
63-
and appropriate to the circumstances. The project team is obligated to maintain
64-
confidentiality with regard to the reporter of an incident. Further details of
65-
specific enforcement policies may be posted separately.
61+
reported by contacting the project team at {{email}}.
62+
63+
All complaints will be reviewed and investigated and will result in a response
64+
that is deemed necessary and appropriate to the circumstances. The project team
65+
is obligated to maintain confidentiality with regard to the reporter of an
66+
incident. Further details of specific enforcement policies may be posted
67+
separately.
6668

6769
Project maintainers who do not follow or enforce the Code of Conduct in good
6870
faith may face temporary or permanent repercussions as determined by other

CONTRIBUTING.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,42 @@ Make sure everything is correctly setup with:
3434
```bash
3535
npm test
3636
```
37+
38+
# Development tasks
39+
40+
The following development tasks are available. Please check the
41+
[`package.json`](/package.json) `scripts` property for more information.
42+
43+
```bash
44+
npm run build
45+
```
46+
47+
Runs a Netlify Build locally with the current plugin. This can be used for
48+
debugging and manual tests.
49+
50+
The local Build configuration file is [`netlify.toml`](/netlify.toml) and can be
51+
modified.
52+
53+
```bash
54+
npm run ava
55+
```
56+
57+
Runs [unit tests](/test/main.js).
58+
59+
```bash
60+
npm run lint
61+
```
62+
63+
Lints and prettifies source files.
64+
65+
```bash
66+
npm test
67+
```
68+
69+
Runs both unit tests and linting.
70+
71+
```bash
72+
npm run release
73+
```
74+
75+
Publishes this plugin to `npm`.

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

LICENSE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MIT License
2+
3+
Copyright (c) {{year}} {{author}}
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,81 @@
1-
<img src="static/logo.png" width="400"/><br>
2-
3-
<!-- START -->
1+
[![Netlify Status](https://api.netlify.com/api/v1/badges/79deda3b-d696-4878-b15d-d9f3a862bdfc/deploy-status)](https://app.netlify.com/sites/awesome-swanson-e132b6/deploys)
42

53
Template repository to create new Netlify Build plugins.
64

7-
## Usage
5+
The main Build plugins documentation can be found
6+
[here](https://docs.netlify.com/configure-builds/build-plugins/).
7+
8+
# Initialization
9+
10+
To create a repository with a new Netlify Build plugin, click on the
11+
["Use this template" button](https://github.com/netlify/build-plugin-template/generate)
12+
on top of the page.
813

9-
To create a repository with a new Netlify Build plugin, click on the following
10-
button:
14+
The repository name should start with `netlify-plugin-`, for example
15+
`netlify-plugin-gatsby`.
1116

12-
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/netlify/build-plugin-template)
17+
[Clone the repository](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository)
18+
locally.
1319

14-
Clone the repository locally. Go to the new repository directory then run the
15-
following command:
20+
Inside the new repository directory, run the following command.
1621

1722
```
1823
npm run init
1924
```
2025

21-
After answering few questions, the Netlify Build plugin will be ready. You can
22-
add any logic to the main file at `src/main.js`. This file's comments will guide
23-
through the creation of a Build plugin.
26+
Some questions will be asked. Make sure the plugin's name matches the repository
27+
name.
2428

25-
The following development tasks are already setup:
29+
Among other things, this will replace this `README.md` with the plugin's user
30+
documentation. Development documentation will still be available in the
31+
[`CONTRIBUTING.md`](/CONTRIBUTING.md#development-tasks).
2632

27-
- `npm run ava` runs unit tests.
28-
- `npm run lint` lints source files.
29-
- `npm test` runs both unit tests and linting.
30-
- `npm run release` publishes this plugin to `npm`.
33+
Finally, create a Netlify Site with the repository. This will automatically run
34+
your Build plugins in Netlify Build on every `git push`, as a smoke test.
3135

32-
## Plugin documentation
36+
You can also add a
37+
[Netlify status badge](https://docs.netlify.com/monitor-sites/status-badges/).
3338

34-
<!-- END -->
39+
# Usage
3540

36-
Netlify Build plugin - {{description}}.
41+
The plugin's logic should be added to [`./src/main.js`](/src/main.js). Comments
42+
in that file will guide you through the creation of a Build plugin.
3743

38-
## Install
44+
## Development tasks
3945

40-
```
41-
npm install netlify-plugin-{{name}}
46+
The following development tasks are available. Please check the
47+
[`package.json`](/package.json) `scripts` property for more information.
48+
49+
```bash
50+
npm run build
4251
```
4352

44-
## Usage
53+
Runs a Netlify Build locally with the current plugin. This can be used for
54+
debugging and manual tests.
4555

46-
Add this plugin to the `plugins` array in your
47-
[`netlify.yml` configuration file](https://docs.netlify.com/configure-builds/file-based-configuration):
56+
The local Build configuration file is [`netlify.toml`](/netlify.toml) and can be
57+
modified.
4858

49-
```yml
50-
plugins:
51-
- package: netlify-plugin-{{name}}
52-
config: {}
59+
```bash
60+
npm run ava
5361
```
5462

55-
## Configuration
63+
Runs [unit tests](/test/main.js).
5664

57-
The following `config` options are available:
65+
```bash
66+
npm run lint
67+
```
68+
69+
Lints and prettifies source files.
5870

59-
### foo
71+
```bash
72+
npm test
73+
```
6074

61-
_Type_: `string`\
62-
_Default_: `bar`
75+
Runs both unit tests and linting.
76+
77+
```bash
78+
npm run release
79+
```
6380

64-
Example description of the `foo` option.
81+
Publishes this plugin to `npm`.

ava.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
timeout: '100s',
3+
verbose: true,
4+
}

init/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Netlify Build plugin {{name}} - {{description}}.
2+
3+
# Install
4+
5+
Please install this plugin from the Netlify app.
6+
7+
# Configuration
8+
9+
The following `inputs` options are available.

scripts/init/bin.js renamed to init/bin.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,33 @@ const { init } = require('./main.js')
99
const { VARIABLES } = require('./variables/main.js')
1010

1111
// CLI entry point of `npm run init`
12-
const runCli = async function() {
12+
const runCli = async function () {
1313
const flags = parseFlags()
1414
const flagsA = filterObj(flags, isUserFlag)
1515

1616
try {
1717
await init(flagsA)
1818
} catch (error) {
19-
console.error(error.message)
19+
console.error(`${error.message}\n`)
2020
exit(1)
2121
}
2222
}
2323

2424
// Parse CLI flags
25-
const parseFlags = function() {
26-
return yargs
27-
.options(FLAGS)
28-
.usage(USAGE)
29-
.parse()
25+
const parseFlags = function () {
26+
return yargs.options(FLAGS).usage(USAGE).parse()
3027
}
3128

3229
// Retrieve CLI flags
33-
const getVariablesFlags = function() {
30+
const getVariablesFlags = function () {
3431
return Object.assign(...VARIABLES.map(getVariableFlag))
3532
}
3633

37-
const getVariableFlag = function({ name, description, default: defaultValue }) {
34+
const getVariableFlag = function ({
35+
name,
36+
description,
37+
default: defaultValue,
38+
}) {
3839
return {
3940
[name]: {
4041
string: true,
@@ -51,7 +52,7 @@ const FLAGS = {
5152
const USAGE = ``
5253

5354
// Remove `yargs`-specific options, shortcuts, dash-cased and aliases
54-
const isUserFlag = function(key, value) {
55+
const isUserFlag = function (key, value) {
5556
return (
5657
value !== undefined &&
5758
!INTERNAL_KEYS.includes(key) &&

init/clean.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const { readFile, writeFile } = require('fs')
2+
const { promisify } = require('util')
3+
4+
const del = require('del')
5+
const omit = require('omit.js').default
6+
const filterObj = require('filter-obj')
7+
8+
const PACKAGE_ROOT = `${__dirname}/..`
9+
const SCRIPTS_DIR = `${PACKAGE_ROOT}/init`
10+
const PACKAGE_JSON = `${PACKAGE_ROOT}/package.json`
11+
12+
const pReadFile = promisify(readFile)
13+
const pWriteFile = promisify(writeFile)
14+
15+
// Remove all files, properties and logic needed by `npm run init` once
16+
// `npm run init` is done.
17+
const cleanRepo = async function () {
18+
await Promise.all([del(SCRIPTS_DIR, { force: true }), cleanPackageJson()])
19+
}
20+
21+
// Remove `npm run init` in `package.json` and all `devDependencies`.
22+
const cleanPackageJson = async function () {
23+
const content = await pReadFile(PACKAGE_JSON, 'utf8')
24+
const { scripts, dependencies, devDependencies, ...packageJson } = JSON.parse(
25+
content,
26+
)
27+
28+
const scriptsA = omit(scripts, ['init'])
29+
const devDependenciesA = filterObj(devDependencies, shouldKeepDevDependency)
30+
const packageJsonA = {
31+
...packageJson,
32+
scripts: scriptsA,
33+
dependencies,
34+
devDependencies: devDependenciesA,
35+
}
36+
37+
const contentA = JSON.stringify(packageJsonA, null, 2)
38+
await pWriteFile(PACKAGE_JSON, contentA)
39+
}
40+
41+
// Remove devDependencies used only for initialization
42+
const shouldKeepDevDependency = function (key) {
43+
return DEV_DEPENDENCIES.includes(key)
44+
}
45+
46+
const DEV_DEPENDENCIES = [
47+
'@netlify/build',
48+
'ava',
49+
'cross-env',
50+
'eslint',
51+
'eslint-config-prettier',
52+
'eslint-plugin-import',
53+
'eslint-plugin-node',
54+
'eslint-plugin-prettier',
55+
'execa',
56+
'netlify-cli',
57+
'prettier',
58+
'release-it',
59+
]
60+
61+
module.exports = { cleanRepo }

init/copy.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const cpy = require('cpy')
2+
3+
const PACKAGE_ROOT = `${__dirname}/..`
4+
5+
// Copy some files during initialization
6+
const copyFiles = async function () {
7+
const files = FILES.map((file) => `${__dirname}/${file}`)
8+
await cpy(files, PACKAGE_ROOT)
9+
}
10+
11+
const FILES = ['README.md']
12+
13+
module.exports = { copyFiles }

0 commit comments

Comments
 (0)