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 README file support to Projen #816

Merged
merged 6 commits into from
Jul 18, 2024
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
161 changes: 133 additions & 28 deletions .projenrc.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(project): Add `ReadmeFile` support",
"packageName": "@langri-sha/projen-project",
"email": "filip.dupanovic@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(readme): Add `ReadmeFile`",
"packageName": "@langri-sha/projen-readme",
"email": "filip.dupanovic@gmail.com",
"dependentChangeType": "patch"
}
5 changes: 5 additions & 0 deletions packages/projen-project/.projen/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
"version": "workspace:*",
"type": "runtime"
},
{
"name": "@langri-sha/projen-readme",
"version": "workspace:*",
"type": "runtime"
},
{
"name": "@langri-sha/projen-renovate",
"version": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions packages/projen-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@langri-sha/projen-lint-synthesized": "workspace:*",
"@langri-sha/projen-pnpm-workspace": "workspace:*",
"@langri-sha/projen-prettier": "workspace:*",
"@langri-sha/projen-readme": "workspace:*",
"@langri-sha/projen-renovate": "workspace:*",
"@langri-sha/projen-swcrc": "workspace:*",
"@langri-sha/projen-typescript-config": "workspace:*",
Expand Down
64 changes: 64 additions & 0 deletions packages/projen-project/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,69 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`With README options 1`] = `
{
".gitignore": "# ~~ Generated by projen. To modify, edit .projenrc.mts and run "npx projen".
.*
!.babelrc
!.dockerignore
!.editorconfig
!.gitattributes
!.gitignore
!.gitkeep
!.npmignore
!.openssl
!.prettierignore
*.db
*.log
!.github/
!.projen/
dist/
node_modules/
!/.gitattributes
!/.projen/tasks.json
!/.projen/deps.json
!/.projen/files.json
!/.projenrc.mts
",
".projen/files.json": {
"//": "~~ Generated by projen. To modify, edit .projenrc.mts and run "npx projen".",
"files": [
".gitattributes",
".gitignore",
".projen/deps.json",
".projen/files.json",
".projen/tasks.json",
],
},
".projen/tasks.json": {
"//": "~~ Generated by projen. To modify, edit .projenrc.mts and run "npx projen".",
"tasks": {
"default": {
"description": "Synthesize project files",
"name": "default",
"steps": [
{
"exec": "node --loader ts-node/esm/transpile-only .projenrc.mts",
},
],
},
"test": {
"description": "Run tests",
"name": "test",
},
},
},
".projenrc.mts": "import { Project } from '@langri-sha/projen-project'

const project = new Project()

project.synth()
",
"README.md": "# test-project
",
}
`;

exports[`add subproject > with options 1`] = `
{
".gitignore": "# ~~ Generated by projen. To modify, edit .projenrc.mts and run "npx projen".
Expand Down
12 changes: 12 additions & 0 deletions packages/projen-project/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { License } from '@langri-sha/projen-license'
import { LintStaged } from '@langri-sha/projen-lint-staged'
import { PnpmWorkspace } from '@langri-sha/projen-pnpm-workspace'
import { Prettier } from '@langri-sha/projen-prettier'
import { ReadmeFile } from '@langri-sha/projen-readme'
import { Renovate } from '@langri-sha/projen-renovate'
import { SWCConfig } from '@langri-sha/projen-swcrc'
import { TypeScriptConfig } from '@langri-sha/projen-typescript-config'
Expand Down Expand Up @@ -42,6 +43,7 @@ test('defaults', () => {
expect(project.pnpmWorkspace).toBeUndefined()
expect(project.prettier).toBeUndefined()
expect(project.projenrc).toBeInstanceOf(ProjenrcFile)
expect(project.readme).toBeUndefined()
expect(project.renovate).toBeUndefined()
expect(project.swcrc).toBeUndefined()
expect(project.typeScriptConfig).toBeUndefined()
Expand Down Expand Up @@ -482,6 +484,16 @@ describe('with Prettier options', () => {
})
})

test('With README options', () => {
const project = new Project({
name: 'test-project',
readme: {},
})

expect(synthSnapshot(project)).toMatchSnapshot()
expect(project.readme).toBeInstanceOf(ReadmeFile)
})

test('with Renovate options', () => {
const project = new Project({
name: 'test-project',
Expand Down
16 changes: 16 additions & 0 deletions packages/projen-project/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
PnpmWorkspaceOptions,
} from '@langri-sha/projen-pnpm-workspace'
import { Prettier, PrettierOptions } from '@langri-sha/projen-prettier'
import { ReadmeFile, type ReadmeFileOptions } from '@langri-sha/projen-readme'
import { Renovate, type RenovateOptions } from '@langri-sha/projen-renovate'
import { SWCConfig, type SWCConfigOptions } from '@langri-sha/projen-swcrc'
import {
Expand Down Expand Up @@ -117,6 +118,11 @@ export interface ProjectOptions
*/
npmIgnore?: IgnoreFileOptions

/*
* Add a sample `README`.
*/
readme?: ReadmeFileOptions

/*
* Pass in to configure Renovate.
*/
Expand Down Expand Up @@ -153,6 +159,7 @@ export class Project extends BaseProject {
pnpmWorkspace?: PnpmWorkspace
prettier?: Prettier
projenrc?: ProjenrcFile
readme?: ReadmeFile
renovate?: Renovate
swcrc?: SWCConfig
typeScriptConfig?: TypeScriptConfig
Expand Down Expand Up @@ -197,6 +204,7 @@ export class Project extends BaseProject {
this.#configureLintSynthesized(options)
this.#configureNpmIgnore(options)
this.#configurePnpmWorkspace(options)
this.#configureReadme(options)
this.#configureRenovate(options)
}

Expand Down Expand Up @@ -517,6 +525,14 @@ export class Project extends BaseProject {
}
}

#configureReadme({ readme }: ProjectOptions) {
if (!readme) {
return
}

this.readme = new ReadmeFile(this, readme)
}

#configureRenovate({ renovate: renovateOptions }: ProjectOptions) {
if (!renovateOptions || this.parent) {
return
Expand Down
3 changes: 3 additions & 0 deletions packages/projen-project/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
{
"path": "../projen-prettier"
},
{
"path": "../projen-readme"
},
{
"path": "../projen-renovate"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/projen-readme/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".
.*
tsconfig*.json
*.test.*
__snapshots__/
20 changes: 20 additions & 0 deletions packages/projen-readme/.projen/deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"dependencies": [
{
"name": "@langri-sha/tsconfig",
"version": "*",
"type": "build"
},
{
"name": "@langri-sha/vitest",
"version": "workspace:*",
"type": "build"
},
{
"name": "projen",
"version": "^0.82.0",
"type": "peer"
}
],
"//": "~~ Generated by projen. To modify, edit .projenrc.ts and run \"npx projen\"."
}
13 changes: 13 additions & 0 deletions packages/projen-readme/.projen/files.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"files": [
".gitattributes",
".npmignore",
".projen/deps.json",
".projen/files.json",
".projen/tasks.json",
"license",
"tsconfig.build.json",
"tsconfig.json"
],
"//": "~~ Generated by projen. To modify, edit .projenrc.ts and run \"npx projen\"."
}
21 changes: 21 additions & 0 deletions packages/projen-readme/.projen/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"tasks": {
"default": {
"name": "default",
"description": "Synthesize project files"
},
"install": {
"name": "install",
"description": "Install project dependencies and update lockfile (non-frozen)"
},
"install:ci": {
"name": "install:ci",
"description": "Install project dependencies using frozen lockfile"
},
"test": {
"name": "test",
"description": "Run tests"
}
},
"//": "~~ Generated by projen. To modify, edit .projenrc.ts and run \"npx projen\"."
}
10 changes: 10 additions & 0 deletions packages/projen-readme/license
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

MIT License

Copyright (c) 2024 Filip Dupanović <filip.dupanovic@gmail.com> (https://langri-sha.com)

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.
37 changes: 37 additions & 0 deletions packages/projen-readme/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@langri-sha/projen-readme",
"version": "0.0.0",
"bugs": {
"url": "https://github.com/langri-sha/langri-sha.com/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/langri-sha/langri-sha.com.git",
"directory": "packages/projen-readme"
},
"license": "MIT",
"author": {
"name": "Filip Dupanović",
"email": "filip.dupanovic@gmail.com",
"url": "https://langri-sha.com",
"organization": false
},
"type": "module",
"main": "src/index.ts",
"scripts": {
"prepublishOnly": "rm -rf dist; tsc --project tsconfig.build.json"
},
"devDependencies": {
"@langri-sha/tsconfig": "workspace:*",
"@langri-sha/vitest": "workspace:*"
},
"peerDependencies": {
"projen": "^0.82.0"
},
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"types": "dist/index.d.ts"
},
"//": "~~ Generated by projen. To modify, edit .projenrc.ts and run \"npx projen\"."
}
28 changes: 28 additions & 0 deletions packages/projen-readme/readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# @langri-sha/readme

A [projen] component for creating sample [`README` files].

## Usage

Install dependencies:

```sh
npm install -D @langri-sha/readme
```

Then, create a `README` component for your projects:

```js
import { Project } from 'projen'
import { ReadmeFile } from '@langri-sha/readme'

const project = new Project({
name: 'my-project',
})

new ReadmeFile(project)
```

[readme files]:
https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-readmes
[projen]: https://projen.io/
11 changes: 11 additions & 0 deletions packages/projen-readme/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`custom filename 1`] = `
"# test-project
"
`;

exports[`defaults 1`] = `
"# test-project
"
`;
25 changes: 25 additions & 0 deletions packages/projen-readme/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, test } from '@langri-sha/vitest'
import { Project } from 'projen'
import { synthSnapshot } from 'projen/lib/util/synth'

import { ReadmeFile } from '.'

test('defaults', () => {
const project = new Project({
name: 'test-project',
})

new ReadmeFile(project)

expect(synthSnapshot(project)['README.md']).toMatchSnapshot()
})

test('custom filename', () => {
const project = new Project({
name: 'test-project',
})

new ReadmeFile(project, { filename: 'readme' })

expect(synthSnapshot(project)['readme']).toMatchSnapshot()
})
Loading