Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add oss-npm-package template #73

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/swift-dryers-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'skuba': minor
---

**template/oss-npm-package:** Add new template

This is intended for [seek-oss](https://github.com/seek-oss) projects.
1 change: 1 addition & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- greeter
- koa-rest-api
- lambda-sqs-worker
- oss-npm-package
- private-npm-package
steps:
- name: Check out repo
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,17 @@ This initialises a new directory and Git repository.
a message queue is employed between the source topic and the Lambda function,
and unprocessed events are sent to a dead-letter queue for manual triage.

- `oss-npm-package`

A public npm package published via [semantic-release] pipeline.

This is intended for [seek-oss] projects.

- `private-npm-package`

Set up a new private npm module published using a semantic release pipeline.
At the moment this only supports the `@seek` private npm org.
A private npm package published via [semantic-release] pipeline.

This is intended for [SEEK-Jobs] projects under the `@seek` npm org.

- `github →` (experimental)

Expand All @@ -167,6 +174,9 @@ This initialises a new directory and Git repository.
[aws lambda]: https://tech-strategy.ssod.skinfra.xyz/docs/v1/technology.html#lambda
[koa]: https://koajs.com/
[resource api]: https://tech-strategy.ssod.skinfra.xyz/docs/v1/components.html#resource-api
[seek-jobs]: https://github.com/SEEK-Jobs
[seek-oss]: https://github.com/seek-oss
[semantic-release]: https://github.com/semantic-release/semantic-release/
[serverless]: https://serverless.com/
[worker]: https://tech-strategy.ssod.skinfra.xyz/docs/v1/components.html#worker

Expand Down
1 change: 1 addition & 0 deletions src/cli/init/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const TEMPLATE_PROMPT = new Select({
'greeter',
'koa-rest-api',
'lambda-sqs-worker',
'oss-npm-package',
'private-npm-package',
'github →',
] as const,
Expand Down
34 changes: 34 additions & 0 deletions template/oss-npm-package/.github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
branches:
- beta
- master

jobs:
release:
name: Publish & Deploy
runs-on: ubuntu-latest
env:
CI: true
steps:
- name: Check out repo
uses: actions/checkout@master
with:
fetch-depth: 0
lfs: true

- name: Set up Node.js 12.x
uses: actions/setup-node@master
with:
node-version: 12.x

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Publish to npm
run: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.SEEK_OSS_CI_NPM_TOKEN }}
31 changes: 31 additions & 0 deletions template/oss-npm-package/.github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Validate

on:
- pull_request
- push

jobs:
validate:
name: Lint & Test
runs-on: ubuntu-latest
env:
CI: true
steps:
- name: Check out repo
uses: actions/checkout@master
with:
lfs: true

- name: Set up Node.js 12.x
uses: actions/setup-node@master
with:
node-version: 12.x

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint

- name: Test
run: yarn test
1 change: 1 addition & 0 deletions template/oss-npm-package/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
21 changes: 21 additions & 0 deletions template/oss-npm-package/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### MIT License

Copyright (c) 2020 SEEK

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
119 changes: 119 additions & 0 deletions template/oss-npm-package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# <%- moduleName %>

[![Powered by skuba](https://img.shields.io/badge/🤿%20skuba-powered-009DC4)](https://github.com/seek-oss/skuba)

This package is intended to be public on [seek-oss].
To create an internal package,
run `skuba init` and select the `private-npm-package` template.

Please read [SEEK's Open Source RFC] before proceeding.

## Table of contents

- [API](#api)
- [Development](#development)
- [Release](#release)

## API

### `log`

Writes "<%- moduleName %>" to stdout.
Thrilling stuff.

```typescript
import { log } from '<%- moduleName %>';

log();
```

## Development

### Prerequisites

- Node.js LTS
- Yarn 1.x

```shell
yarn install
```

### Test

```shell
yarn test
```

### Lint

```shell
# fix
yarn format

# check
yarn lint
```

### Package

```shell
# compile source
yarn build

# review bundle
npm pack
```

## Release

This package is published to the public npm registry with a GitHub Actions [release workflow].

The workflow runs on select branches:

```yaml
on:
push:
branches:
# add others as necessary
- beta
- master
# - alpha
```

It depends on this repo being hosted on [seek-oss] with access to the `SEEK_OSS_CI_NPM_TOKEN` GitHub secret.

Request access in `#open-source` on Slack:

```text
Hi, I’m publishing a new package from seek-oss/<%- moduleName %>. May I have access to the SEEK_OSS_CI_NPM_TOKEN organisation secret?
```

### Releasing latest

Commits to the `master` branch will be released with the `latest` tag,
which is the default used when running `npm install` or `yarn install`.

### Releasing other dist-tags

**[semantic-release]** prescribes a branch-based workflow for managing [distribution tags].

You can push to other branches to manage betas, maintenance updates to prior major versions, and more.

Here are some branches that **semantic-release** supports by default:

| Git branch | npm dist-tag |
| :--------- | :----------- |
| master | latest |
| alpha | alpha |
| beta | beta |
| next | next |
| 1.x | release-1.x |

For more information, see the **semantic-release** docs on [triggering a release].

[distribution tags]: https://docs.npmjs.com/adding-dist-tags-to-packages
[release workflow]: .github/workflows/release.yml
[seek-oss]: https://github.com/seek-oss
[seek's open source rfc]: https://rfc.skinfra.xyz/RFC016-Open-Source.html
[semantic-release]: https://github.com/semantic-release/semantic-release
[triggering a release]: https://github.com/semantic-release/semantic-release/#triggering-a-release
26 changes: 26 additions & 0 deletions template/oss-npm-package/_package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"dependencies": {},
"description": "<%- description %>",
"devDependencies": {
"skuba": "*"
},
"files": ["lib*/**/*.d.ts", "lib*/**/*.js", "lib*/**/*.js.map"],
"license": "MIT",
"main": "./lib-commonjs/index.js",
"module": "./lib-es2015/index.js",
"name": "<%- moduleName %>",
"repository": {
"type": "git",
"url": "git+https://github.com/<%- orgName %>/<%- repoName %>.git"
},
"scripts": {
"build": "skuba build-package",
"format": "skuba format",
"lint": "skuba lint",
"release": "yarn build && skuba release",
"test": "skuba test"
},
"sideEffects": false,
"types": "./lib-types/index.d.ts",
"version": "0.0.0-semantically-released"
}
20 changes: 20 additions & 0 deletions template/oss-npm-package/skuba.template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Run `skuba configure` to finish templating and remove this file.
*/

module.exports = {
entryPoint: 'src/index.ts',
fields: [
{
name: 'moduleName',
message: 'Module name',
initial: 'my-first-module',
},
{
name: 'description',
message: 'Description',
initial: 'This is my first module',
},
],
type: 'package',
};
5 changes: 5 additions & 0 deletions template/oss-npm-package/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { log } from './index';

describe('app', () => {
it('defines a log function', () => expect(log).toBeDefined());
});
3 changes: 3 additions & 0 deletions template/oss-npm-package/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const log = () =>
/* eslint-disable-next-line no-console */
console.log('<%- moduleName %>');