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

Generate nicer READMEs inside new projects / apps / views / packages #2253

Merged
merged 53 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4aafc87
Start documenting package types
Jan 3, 2023
4655c35
Describe App and ESM View types
Jan 3, 2023
048f7e3
Packages
Jan 4, 2023
8d2848c
Views, sources and templates
Jan 4, 2023
56ecf0d
Link add command page
Jan 4, 2023
a724457
Link package types in index
Jan 5, 2023
e82dbc1
Update docs/commands/add.md
cristiano-belloni Jan 5, 2023
286fd60
Update docs/concepts/package-types.md
cristiano-belloni Jan 5, 2023
35114b0
Update docs/concepts/package-types.md
cristiano-belloni Jan 5, 2023
7bb2648
Merge remote-tracking branch 'origin/feature/v4' into feature/documen…
Jan 5, 2023
e9d18f3
Link esm-views section in add page
Jan 5, 2023
ea4774d
Update docs/commands/add.md
cristiano-belloni Jan 5, 2023
77d3643
Link app section for more info
Jan 5, 2023
0b72782
Update docs/concepts/package-types.md
cristiano-belloni Jan 5, 2023
1a8aafe
Clarify manifest -> package.json + fix incorrect description
Jan 5, 2023
89302d2
Merge branch 'feature/document-package-types' of https://github.com/j…
Jan 5, 2023
71e12a4
Add reasons why we don't support things
Jan 5, 2023
9cbd85b
Disambiguate words
Jan 5, 2023
c0a46c7
Phrase 'default export' concept better
Jan 5, 2023
217ae18
Update docs/concepts/package-types.md
cristiano-belloni Jan 5, 2023
137d28a
Update docs/concepts/package-types.md
cristiano-belloni Jan 5, 2023
96565ad
Update docs/commands/add.md
cristiano-belloni Jan 5, 2023
35fbad8
Reword tricky sentence
Jan 5, 2023
b8a7aa6
Update docs/commands/add.md
cristiano-belloni Jan 5, 2023
e08ef2a
Update docs/concepts/package-types.md
cristiano-belloni Jan 5, 2023
db62b30
Split long sentence
Jan 5, 2023
faeb1f1
Add all package types to configuration docs
Jan 5, 2023
bad4cba
Various typos
Jan 5, 2023
2f7b79f
Split packge types and move template page
Jan 6, 2023
09e501d
Fix links to package types and fix table layout
Jan 6, 2023
b44505b
Slim down table
Jan 6, 2023
af864c7
build/start/entrypoint/template sections
Jan 6, 2023
9779803
Add root project README
Jan 9, 2023
83d4f60
Add per-package READMEs + fix docs
Jan 9, 2023
4308a84
Merge branch 'feature/v4' into feature/better-readmes
cristiano-belloni Jan 10, 2023
dab1eb6
Lint view documentation
Jan 10, 2023
cdadc52
Update snapshots
Jan 10, 2023
c330811
Upddate app snapshots
Jan 10, 2023
6e912d0
Update snapshots in index test
Jan 10, 2023
c1e7632
Update app.esbuild.test snapshots
Jan 10, 2023
e7726da
update cmra tests
Jan 10, 2023
e208d81
Correct snapshots for cmra
Jan 10, 2023
8ab9b31
Update snapshots for cli.test.ts
AlbertoBrusa Jan 11, 2023
53289fc
Remove packages README + fix all READMEs
Jan 11, 2023
419396a
Merge branch 'feature/better-readmes' of https://github.com/jpmorganc…
Jan 11, 2023
df551c9
Add README to fixtures + update snapshots
Jan 11, 2023
d20faba
Update various snapshots
Jan 11, 2023
ef9042d
Update app.esbuild.test snapshots
Jan 11, 2023
85b1652
Add default workspace README
Jan 11, 2023
ea47860
Update index snapshots
Jan 11, 2023
1005cb4
Create odd-bees-speak.md
cristiano-belloni Jan 11, 2023
6bdf317
Update fixture READMEs
Jan 12, 2023
bc6a2f4
Merge branch 'feature/better-readmes' of https://github.com/jpmorganc…
Jan 12, 2023
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
12 changes: 12 additions & 0 deletions .changeset/odd-bees-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"create-modular-react-app": minor
"modular-scripts": minor
"modular-template-app": minor
"modular-template-esm-view": minor
"modular-template-package": minor
"modular-template-source": minor
"modular-template-view": minor
---

Generate README inside newly created packages
Improve root and default workspaces container README
1 change: 1 addition & 0 deletions __fixtures__/templates/modular-template-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a README placeholder for this template fixture
1 change: 1 addition & 0 deletions __fixtures__/templates/modular-template-filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a README placeholder for this template fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a README placeholder for this template fixture
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {

**Default**: `false` - Uses [Webpack](https://webpack.js.org/)

Use esbuild instead of default Webpack. Only affects Views and ESM Views.
Use esbuild instead of default Webpack. Only affects Apps and ESM Views.

### **externalCdnTemplate**

Expand Down
6 changes: 3 additions & 3 deletions docs/package-types/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ To run your app locally on a development server, run
modular start my-app-name
```

This causes a developer server to run on port 3000, serving the app with an
additional runtime layer that provides developer experience functionalities like
hot reloading and on-screen error overlay.
This starts a developer server on port 3000, serving the app with an additional
runtime layer that provides developer experience functionalities like hot
reloading and on-screen error overlay.

## Entry-point

Expand Down
4 changes: 2 additions & 2 deletions docs/package-types/esm-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ To run your ESM View locally on a development server, run
[start](../commands/start.md):

```bash
modular start my-app-name
modular start my-esm-view-name
```

This causes a developer server to run on port 3000, serving the ESM View with an
This starts a developer server on port 3000, serving the ESM View with an
additional runtime layer that provides a trampoline module to load the generated
files, plus developer experience functionalities like hot reloading and
on-screen error overlay. Please make sure that your ESM View entry-point exports
Expand Down
23 changes: 11 additions & 12 deletions docs/package-types/view.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ title: view

Modular `view`s are Modular [`package`s](./package.md) that, by convention,
export a default React component. They are [created](../commands/add.md) with a
default entry-point is `src/index.tsx` in their `package.json` and they are
default entry-point of `src/index.tsx` in their `package.json` and they are
built exactly like [`package`](./package.md) types. The only difference is that,
since `view`s should always export a React component, they can be
[`start`ed](../commands/start.md) to spawn a local developer server and render
Expand All @@ -20,25 +20,24 @@ Same as [`package`](./package.md/#build).

## Start

To run your package locally on a development server, run
To run your view locally on a development server, run
[start](../commands/start.md):

```bash
modular start my-package-name
modular start my-view-name
```

This causes a developer server to run on port 3000, serving the default export
of the package entry-point with an additional runtime layer that provides
developer experience functionalities like hot reloading and on-screen error
overlay.
This starts a developer server on port 3000, serving the default export of the
View entry-point with an additional runtime layer that provides developer
experience functionalities like hot reloading and on-screen error overlay.

## Entry-point

The entry-point for a package is configurable; Modular discovers it by looking
at the `main` field in the package's `package.json`; by default,
`modular add`ing a new package sets it as `"./src/index.tsx"`, but it's possible
to manually modify it. The entry-point of a View needs to export a React
component as default for the start command to work.
The entry-point for a View is configurable; Modular discovers it by looking at
the `main` field in the View's `package.json`; by default, `modular add`ing a
new View sets it as `"./src/index.tsx"`, but it's possible to manually modify
it. The entry-point of a View needs to export a React component as default for
the `start` command to work.

## Template

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ exports[`Creating a new modular app via the CLI should create the right tree 1`]
│ ├─ launch.json #1kk1omt
│ └─ settings.json #xes41c
├─ .yarnrc #1orkcoz
├─ README.md #1nksyzj
├─ README.md #5vircs
├─ modular
│ ├─ setupEnvironment.ts #m0s4vb
│ └─ setupTests.ts #bnjknz
├─ package.json
├─ packages
│ ├─ README.md #14bthrh
│ ├─ README.md #11apaz5
│ └─ app
│ ├─ package.json
│ ├─ public
Expand Down Expand Up @@ -52,13 +52,13 @@ exports[`Creating a new modular app via the CLI with --empty should create the r
│ ├─ launch.json #1kk1omt
│ └─ settings.json #xes41c
├─ .yarnrc #1orkcoz
├─ README.md #1nksyzj
├─ README.md #5vircs
├─ modular
│ ├─ setupEnvironment.ts #m0s4vb
│ └─ setupTests.ts #bnjknz
├─ package.json
├─ packages
│ └─ README.md #14bthrh
│ └─ README.md #11apaz5
├─ tsconfig.json #1h72lkd
└─ yarn.lock"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ exports[`create-modular-react-app WHEN it sets up a project with prefer Offline
│ ├─ launch.json #1kk1omt
│ └─ settings.json #xes41c
├─ .yarnrc #1orkcoz
├─ README.md #1nksyzj
├─ README.md #5vircs
├─ modular
│ ├─ setupEnvironment.ts #m0s4vb
│ └─ setupTests.ts #bnjknz
├─ package.json
├─ packages
│ ├─ README.md #14bthrh
│ ├─ README.md #11apaz5
│ └─ app
│ ├─ package.json
│ ├─ public
Expand Down Expand Up @@ -418,13 +418,13 @@ exports[`create-modular-react-app WHEN setting a project with defaults should cr
│ ├─ launch.json #1kk1omt
│ └─ settings.json #xes41c
├─ .yarnrc #1orkcoz
├─ README.md #1nksyzj
├─ README.md #5vircs
├─ modular
│ ├─ setupEnvironment.ts #m0s4vb
│ └─ setupTests.ts #bnjknz
├─ package.json
├─ packages
│ ├─ README.md #14bthrh
│ ├─ README.md #11apaz5
│ └─ app
│ ├─ package.json
│ ├─ public
Expand Down
76 changes: 75 additions & 1 deletion packages/create-modular-react-app/template/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,75 @@
This is the `README.md` for the whole monorepo.
This is a monorepository initialised with [Modular](https://modular.js.org/)

## Commands available

- [Add](https://modular.js.org/commands/add/) - Add a new Modular package to the
monorepo
- [Analyze](https://modular.js.org/commands/analyze/) - Analyzes the
dependencies of a package from its source code, emitting JSON to `stdout`.
- [Build](https://modular.js.org/commands/build/) - Search workspaces based on
their name field in the `package.json` and build them according to their
respective `modular.type`, in order of dependency.
- [Check](https://modular.js.org/commands/check/) - Check the modular root repo
has [Yarn workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/),
modular packages are set up properly and check the package tree for issues
with dependencies.
- [Lint](https://modular.js.org/commands/lint/) - Check the diff between the
current branch and the remote origin default branch and lint the source files
that have changes. In CI, lint the entire codebase.
- [Start](https://modular.js.org/commands/start/) - Run the selected Modular
`app`, `esm-view` or `view` locally.
- [Test](https://modular.js.org/commands/test/) - Run [Jest](https://jestjs.io/)
tests against a selection of Modular packages.
- [Typecheck](https://modular.js.org/commands/typecheck/) - Report the semantic,
syntactic, and declaration type errors found in your code.
- [Workspace](https://modular.js.org/commands/workspace/) - Prints information
about the monorepository to the console. Like
[`yarn workspaces info`](https://classic.yarnpkg.com/lang/en/docs/cli/workspaces/#toc-yarn-workspaces-info),
but extended with modular metadata about package type and public/private
status.

## Package types

| Type | [start](https://modular.js.org/commands/start/) | [build](https://modular.js.org/commands/build/) | [test](https://modular.js.org/commands/test/) | [lint](https://modular.js.org/commands/lint/) | Custom index / assets | Bundled | Entry-point |
| ------------------------------------------------------------ | ----------------------------------------------- | ----------------------------------------------- | --------------------------------------------- | --------------------------------------------- | -------------------------- | --------------------- | ------------------------------ |
| [`app`](https://modular.js.org/package-types/app/) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | `src/index.tsx` |
| [`esm-view`](https://modular.js.org/package-types/esm-view/) | ✅ | ✅ | ✅ | ✅ | ❌ | ✅† | `src/index.tsx` |
| [`package`](https://modular.js.org/package-types/package/) | ❌ | ✅ | ✅ | ✅ | **N/A** | ❌ | `main` field of `package.json` |
| [`view`](https://modular.js.org/package-types/view/) | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | `main` field of `package.json` |
| [`source`](https://modular.js.org/package-types/source/) | ❌ | ❌ | ✅ | ✅ | **N/A** | **N/A** - never built | **N/A** - never built |
| [`template`](https://modular.js.org/package-types/template/) | ❌ | ❌ | ✅ | ✅ | Depends on the target type | **N/A** - never built | **N/A** - never built |

† For ESM Views, external dependencies are rewritten to point to a CDN

## Configuration

### Example with defaults

##### `.modular.js`

```js
module.exports = {
useModularEsbuild: false,
externalCdnTemplate: 'https://esm.sh/[name]@[resolution]',
externalBlockList: [],
externalAllowList: ['**'],
publicUrl: '',
generateSourceMap: true,
};
```

### Options

- `useModularEsbuild`: Use [esbuild](https://esbuild.github.io/) instead of
default Webpack. Only affects Apps and ESM Views. Default: _false_.
- `externalCdnTemplate`: Template to resolve the URL used to fetch packages from
a CDN. Only applies to ESM Views. Default:
`https://esm.sh/[name]@[resolution]`
- `externalBlockList`: External oackages that should be bundled and not fetched
from a CDN. Applies only to ESM Views. Default: _no package_.
- `externalAllowList`: External packages that should be fetched from a CDN.
Applies only to ESM Views. Default: _all_.
- `publicUrl`: Sub-path from which the SPA is served. Applies only to Apps and
ESM Views when served standalone. Default: _/_.
- `generateSourceMap`: Should build process generate source maps? Default:
_true_.
11 changes: 10 additions & 1 deletion packages/create-modular-react-app/template/packages/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
This will be the readme inside /packages
# Workspaces

This is the default
[workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/) root created
by Create Modular React App. Packages added by the
[`modular add`](https://modular.js.org/commands/add/) command will be located
here by default, unless a different directory (included in the root
package.json's
[`workspaces` field](https://classic.yarnpkg.com/lang/en/docs/workspaces/#toc-how-to-use-it))
is specified using the `--path` option.
2 changes: 2 additions & 0 deletions packages/modular-scripts/src/__tests__/addPackage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ describe('When adding a module from a template without a files filter', () => {
).toMatchInlineSnapshot(`
"no-filter-module
├─ CHANGELOG.md
├─ README.md #13oulez
├─ package.json
├─ public
│ └─ robots.txt #1sjb8b3
Expand Down Expand Up @@ -198,6 +199,7 @@ describe('When adding a module from a template with a files filter', () => {
}),
).toMatchInlineSnapshot(`
"filter-module
├─ README.md #13oulez
├─ package.json
├─ src
│ ├─ __tests__
Expand Down
1 change: 1 addition & 0 deletions packages/modular-scripts/src/__tests__/app.esbuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('when working with an app', () => {
expect(tree(path.join(packagesPath, 'sample-esbuild-app')))
.toMatchInlineSnapshot(`
"sample-esbuild-app
├─ README.md #g3sy9z
├─ package.json
├─ public
│ ├─ favicon.ico #6pu3rg
Expand Down
1 change: 1 addition & 0 deletions packages/modular-scripts/src/__tests__/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ describe('when working with a non-scoped app', () => {
it('can add an app', () => {
expect(tree(path.join(packagesPath, 'sample-app'))).toMatchInlineSnapshot(`
"sample-app
├─ README.md #1wz039g
├─ package.json
├─ public
│ ├─ favicon.ico #6pu3rg
Expand Down
1 change: 1 addition & 0 deletions packages/modular-scripts/src/__tests__/esmView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('modular-scripts', () => {
expect(tree(path.join(packagesPath, 'sample-esm-view')))
.toMatchInlineSnapshot(`
"sample-esm-view
├─ README.md #lr4tm5
├─ package.json
└─ src
├─ EsmView.css #x6onxt
Expand Down
3 changes: 3 additions & 0 deletions packages/modular-scripts/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe('modular-scripts', () => {
expect(tree(path.join(packagesPath, 'sample-view')))
.toMatchInlineSnapshot(`
"sample-view
├─ README.md #dei1vf
├─ package.json
└─ src
├─ __tests__
Expand All @@ -107,6 +108,7 @@ describe('modular-scripts', () => {
expect(tree(path.join(packagesPath, 'sample-package')))
.toMatchInlineSnapshot(`
"sample-package
├─ README.md #y1pubb
├─ package.json
└─ src
├─ __tests__
Expand All @@ -120,6 +122,7 @@ describe('modular-scripts', () => {
expect(tree(path.join(packagesPath, 'nested/sample-package')))
.toMatchInlineSnapshot(`
"sample-package
├─ README.md #18abj74
├─ package.json
└─ src
├─ __tests__
Expand Down
9 changes: 5 additions & 4 deletions packages/modular-scripts/src/addPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ async function addPackage({

try {
logger.log(`Looking for template ${templateName} in project...`);
console.log(`require.resolve(${installedPackageJsonPath}, {
paths: [${modularRoot}],
});`);
templatePackageJsonPath = require.resolve(installedPackageJsonPath, {
paths: [modularRoot],
});
Expand Down Expand Up @@ -214,7 +211,11 @@ async function addPackage({

const modularTemplateType = modularTemplatePackageJson?.modular
?.templateType as string;
if (!['app', 'esm-view', 'view', 'package'].includes(modularTemplateType)) {
if (
!['app', 'esm-view', 'view', 'source', 'package'].includes(
modularTemplateType,
)
) {
throw new Error(
`${templateName} has modular type: ${modularTemplateType}, which does not exist, please use update this template`,
);
Expand Down
39 changes: 39 additions & 0 deletions packages/modular-template-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# `PackageName__`

This is a [Modular App](https://modular.js.org/package-types/app)

## Build

To [build](https://modular.js.org/commands/build) your app for deployment, run:

```bash
modular build PackageName__
```

The resulting output is an optimized site that can be served statically. All
code (files in `src` plus external dependencies required in the code) is bundled
in a single blob of code that can be split in different files.

## Start

To run your app locally on a development server, run
[start](https://modular.js.org/commands/start):

```bash
modular start PackageName__
```

This causes a developer server to run on port 3000, serving the app with an
additional runtime layer that provides developer experience functionalities like
hot reloading and on-screen error overlay.

## Entry-point

Apps need an entry-point file located at `src/index.tsx`, which typically uses
React to render components to the DOM, generated at `public/index.html`.

## Template

Apps are generated by `modular add` using the
[`modular-template-app`](https://github.com/jpmorganchase/modular/tree/main/packages/modular-template-app)
[template](https://modular.js.org/package-types/template).
Loading