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 template for npm package #40

Merged
merged 9 commits into from
Jun 11, 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
8 changes: 8 additions & 0 deletions .changeset/neat-lobsters-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'skuba': minor
---

Add template for private npm packages

This change also defaults TypeScript's `moduleResolution` to `node`.
This shouldn't break any existing consumers as it is the default resolution strategy for CommonJS.
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
- private-npm-package
steps:
- name: Check out repo
uses: actions/checkout@master
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ 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.

- `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.

- `github →` (experimental)

BYO starter repo!
Expand All @@ -174,7 +179,8 @@ skuba init << EOF
"destinationDir": "tmp-greeter",
"templateComplete": true,
"templateData": {
"gitHubTeamName": "@seek-jobs/my-team",
"teamName": "my-team",
"orgName": "my-org",
"prodBuildkiteQueueName": "my-team-prod:cicd",
"repoName": "tmp-greeter"
},
Expand Down
3 changes: 2 additions & 1 deletion config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"incremental": true
"incremental": true,
"moduleResolution": "node"
},
"extends": "tsconfig-seek"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"prettier": "2.0.5",
"read-pkg-up": "^7.0.1",
"runtypes": "^4.2.0",
"semantic-release": "^17.0.8",
"ts-jest": "^26.0.0",
"ts-node": "^8.10.1",
"ts-node-dev": "^1.0.0-pre.44",
Expand Down
4 changes: 3 additions & 1 deletion scripts/test-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ yarn skuba init << EOF
"description": "description",
"devBuildkiteQueueName": "my-account-dev:cicd",
"devGantryEnvironmentName": "dev",
"gitHubTeamName": "@my-org/my-team",
"teamName": "my-team",
"moduleName": "first-module",
"orgName": "my-org",
"prodAwsAccountId": "000000000000",
"prodBuildkiteQueueName": "my-account-prod:cicd",
"prodGantryEnvironmentName": "prod",
Expand Down
12 changes: 8 additions & 4 deletions src/cli/init/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ export const BASE_CHOICES = [
},
},
{
name: 'gitHubTeamName',
name: 'orgName',
message: 'Github org name',
initial: 'my-org',
},
{
name: 'teamName',
message: 'GitHub team',
initial: '@seek-jobs/my-team',
validate: (value: string) =>
/^@.+\/.+$/.test(value) || 'GitHub team is not valid',
initial: 'my-team',
},
] as const;

Expand All @@ -41,6 +44,7 @@ export const TEMPLATE_PROMPT = new Select({
'greeter',
'koa-rest-api',
'lambda-sqs-worker',
'private-npm-package',
'github →',
] as const,
message: 'Select a template:',
Expand Down
3 changes: 2 additions & 1 deletion src/cli/init/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export const InitConfig = t.Record({
templateComplete: t.Boolean,
templateData: t
.Record({
gitHubTeamName: t.String,
teamName: t.String,
repoName: t.String,
orgName: t.String,
})
.And(t.Dictionary(t.String, 'string')),
templateName: t.String,
Expand Down
5 changes: 5 additions & 0 deletions src/cli/release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { exec } from '../utils/exec';

export const release = async () => {
await exec('semantic-release', '--success', 'false');
};
1 change: 1 addition & 0 deletions src/utils/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const COMMAND_LIST = [
'help',
'init',
'lint',
'release',
'start',
'test',
'version',
Expand Down
2 changes: 1 addition & 1 deletion template/base/.github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* <%- gitHubTeamName %>
* @<%- orgName %>/<%- teamName %>

# Configured by Renovate
package.json
Expand Down
4 changes: 4 additions & 0 deletions template/private-npm-package/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
steps:
- command: aws s3 cp s3://seek-npm-package-buildkite-pipeline/pipeline-latest.sh - | bash | buildkite-agent pipeline upload
agents:
queue: artefacts:npm
64 changes: 64 additions & 0 deletions template/private-npm-package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# <%- moduleName %>

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

<!--

## Table of contents

- [Usage](#usage)
- [Design](#design)
- [Development](#development)
- [Support](#support)

## Usage

...

## Design

...

## Development

...

## Support

...

-->

To publish your module to npm and release notes to GitHub:

## Release

While a Buildkite pipeline for CI/CD is generated out of the box, there are some additional steps to get semantic-release working:

<https://github.com/SEEK-Jobs/npm-package-buildkite-pipeline#installing-on-your-repository>

### 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].

[distribution tags]: https://docs.npmjs.com/adding-dist-tags-to-packages

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:

<https://github.com/semantic-release/semantic-release/#triggering-a-release>
1 change: 1 addition & 0 deletions template/private-npm-package/_.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
26 changes: 26 additions & 0 deletions template/private-npm-package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "<%- moduleName %>",
"description": "<%- description %>",
"version": "0.0.0-semantically-released",
"main": "./lib-commonjs",
"module": "./lib-es2015",
"typings": "./lib-types",
"files": [
"lib*/**/*.d.ts",
"lib*/**/*.js",
"lib*/**/*.js.map"
],
"sideEffects": false,
lumishrestha marked this conversation as resolved.
Show resolved Hide resolved
"license": "UNLICENSED",
"scripts": {
"build": "skuba build-package",
"format": "skuba format",
"lint": "skuba lint",
"release": "yarn build && skuba release",
"test": "skuba test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/<%- orgName %>/<%- repoName %>.git"
}
}
22 changes: 22 additions & 0 deletions template/private-npm-package/skuba.template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Run `skuba configure` to finish templating and remove this file.
*/

module.exports = {
entryPoint: 'src/index.ts',
fields: [
{
name: 'moduleName',
message: 'Module name',
initial: '@seek/my-first-module',
validate: (value) =>
/^@seek\/.+$/.test(value) ||
`module must start with an ${chalk.bold('@seek/')} scope`,
},
{
name: 'description',
message: 'Description',
initial: 'This is my first module',
},
],
};
5 changes: 5 additions & 0 deletions template/private-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/private-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 %>');
Loading