Skip to content

Commit a36f4c4

Browse files
committed
import existing addon-blueprint implementation
# Conflicts: # RELEASE.md # package.json
2 parents c458ef9 + b22155a commit a36f4c4

30 files changed

Lines changed: 11769 additions & 5 deletions

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Simon Ihmig
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, 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,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# @embroider/addon-blueprint
2+
3+
Blueprint for scaffolding ember v2 addons
4+
5+
For migrating a v1 addon to a v2 addon, you may follow _[Porting Addons to V2](https://github.com/embroider-build/embroider/blob/main/PORTING-ADDONS-TO-V2.md)_ and
6+
this blog post [Migrating an Ember addon to the next-gen v2 format
7+
](https://www.kaliber5.de/de/blog/v2-addon_en).
8+
9+
## WIP
10+
11+
This is still work in progress.
12+
13+
The blueprint contains a number of assumptions, e.g. using a monorepo using (`yarn` or `npm`) workspaces, with separate workspaces for the addon and the test-app. But there is plenty of room for bikeshedding here, so if you have suggestions about better ways to set this up, then please file an issue to discuss!
14+
15+
## Usage
16+
17+
```bash
18+
npx ember-cli@latest addon my-addon -b @embroider/addon-blueprint --pnpm
19+
```
20+
21+
### Options
22+
23+
For all these options, you'll see a warning printed from `ember-cli` about unsupported options.
24+
`ember-cli` doesn't have a way to detect if flags are used by a blueprint.
25+
26+
#### `--pnpm`
27+
28+
Sets up the new addon with [`pnpm`](https://pnpm.io/) as a default package manager.
29+
30+
Example:
31+
32+
```bash
33+
npx ember-cli@latest addon my-addon -b @embroider/addon-blueprint --pnpm
34+
cd my-addon
35+
```
36+
37+
#### `--npm`
38+
39+
Sets up the new addon with `npm` as a default.
40+
41+
Example:
42+
43+
```bash
44+
npx ember-cli@latest addon my-addon -b @embroider/addon-blueprint --npm
45+
cd my-addon
46+
```
47+
48+
#### `--yarn`
49+
50+
Sets up the new addon with `yarn` as a default.
51+
52+
Example:
53+
54+
```bash
55+
npx ember-cli@latest addon my-addon -b @embroider/addon-blueprint --yarn
56+
cd my-addon
57+
```
58+
59+
#### `--addon-location`
60+
61+
The location / folder name of the addon can be customized via `--addon-location`.
62+
63+
Examples:
64+
65+
```bash
66+
ember addon my-addon -b @embroider/addon-blueprint --addon-location=packages/the-addon
67+
# generates
68+
# my-addon/packages/the-addon
69+
```
70+
71+
#### `--test-app-location`
72+
73+
The location / folder name of the addon can be customized via `--test-app-location`.
74+
75+
Examples:
76+
77+
```bash
78+
npx ember-cli@latest addon my-addon -b @embroider/addon-blueprint --test-app-location=test-app
79+
# generates
80+
# my-addon/test-app
81+
```
82+
83+
By default, `{test app name}` will be used.
84+
85+
#### `--test-app-name`
86+
87+
The name of the test-app can be customized via `--test-app-name`.
88+
89+
Examples:
90+
91+
```bash
92+
npx ember-cli@latest addon my-addon -b @embroider/addon-blueprint --test-app-name=test-app-for-my-addon
93+
# generates
94+
# my-addon/test-app-for-my-addon
95+
```
96+
97+
By default, `test-app` will be used.
98+
99+
#### `--addon-only`
100+
101+
Will only create the addon, similar to the v1 addon behavior of `ember addon my-addon`.
102+
This is useful for incremental migrations of v1 addons to v2 addons where the process from the
103+
[Porting Addons to V2](https://github.com/embroider-build/embroider/blob/main/PORTING-ADDONS-TO-V2.md)
104+
guide.
105+
106+
```bash
107+
npx ember-cli@latest addon my-addon -b @embroider/addon-blueprint --addon-only
108+
# generates non-monorepo:
109+
# my-addon/
110+
# .git
111+
# package.json
112+
```
113+
114+
For incremental migration in monorepos, you'll want to also supply the `--skip-git` flag.
115+
116+
#### `--typescript`
117+
118+
Sets up the new addon with [`typescript`](https://www.typescriptlang.org/) support.
119+
120+
Example:
121+
122+
```bash
123+
npx ember-cli@latest addon my-addon -b @embroider/addon-blueprint --typescript
124+
```
125+
126+
### Updating the addon
127+
128+
The blueprint supports `ember-cli-update` to update your addon with any changes that occurred in the blueprint since you created the addon. So to update your addons boilerplate, simply run `ember-cli-update` (or `npx ember-cli-update` if you haven't installed it globally).
129+
130+
For additional instructions, please consult its [documentation](https://github.com/ember-cli/ember-cli-update).
131+
132+
### In existing monorepos
133+
134+
To generate a new v2 addon inside an existing monorepo, `cd` to that repo's directory and run the command as usual. The blueprint will auto-detect an existing `package.json` and adapt to it. Specifically it will not create or override any files at the root folder, like the `package.json` itself.
135+
136+
Most likely though you would not want to use the default locations for the addon and the test app. Instead you should establish a convention how multiple addons and test-apps are located. With the aforementioned path options you can then make the blueprint emit the packages in the correct place.
137+
138+
Some more things to pay attention to:
139+
140+
- Pass the package manager option ( `--npm`, `--yarn`, `--pnpm`) that you already use!
141+
- Make sure that the chosen addon and test-app locations are all covered by the configured workspace layout of your package manager!
142+
- Each package should have a distinct name, so make provide unique names for your test apps instead of the default `test-app` by using the `--test-app-name` option.
143+
- There is no `start` script at the root `package.json` anymore to start both the addon's build and the test app in watch mode. So you would have to run that `start` script with your package manager in both locations in parallel (separate terminal windows/tabs).
144+
- Pass the `skip-git` option to not auto-commit the generated files. Most likely there will be things to adapt to you specific requirements before committing.
145+
- The blueprint will omit all files usually generated at the root folder, including `.prettierrc.js`, and instead use whatever you have already defined in your existing monorepo. So you should run the `lint:fix` script for both the addon and the test-app, and eventually address any non-fixable linting issues or other configuration conventions related to your specific setup.
146+
147+
Some examples...
148+
149+
#### Group by name
150+
151+
We group by the name of the addon, the addon's package and its test app are co-located sub-folders:
152+
153+
```
154+
project-monorepo
155+
└── addons
156+
├── my-addon
157+
│ ├── package
158+
│ └── test-app
159+
└── ...
160+
```
161+
162+
[//]: # 'to edit this: https://tree.nathanfriend.io/?s=(%27options!(%27fancy!true~fullPath3~trailingSlash3~rootDot3)~4(%274%27project-monorepo02addons05my-addon0*5package0*5test-app05...%27)~version!%271%27)*%20%200%5Cn5-%203!false4source!5*2%0154320*'
163+
164+
To generate this run:
165+
166+
```bash
167+
cd project-monorepo
168+
npx ember-cli@latest addon my-addon -b @embroider/addon-blueprint \
169+
--skip-git \
170+
--skip-npm \
171+
--addon-location="addons/my-addon/package" \
172+
--test-app-name="test-app-for-my-addon" \
173+
--test-app-location="addons/my-addon/test-app"
174+
```
175+
176+
#### Group by type
177+
178+
Addons and test-apps are separated:
179+
180+
```
181+
project-monorepo
182+
├── addons
183+
│ ├── my-addon
184+
│ └── ...
185+
└── tests
186+
├── my-addon
187+
└── ...
188+
```
189+
190+
[//]: # 'to edit this: https://tree.nathanfriend.io/?s=(%27options!(%27fancy!true~fullPath2~trailingSlash2~rootDot2)~5(%275%27project-monorepo04738904test39%27)~version!%271%27)*0640862!false3s*my-74-%205source!6%20%207addon8%5Cn9*...%01987654320*'
191+
192+
To generate this run:
193+
194+
```bash
195+
cd project-monorepo
196+
npx ember-cli@latest addon my-addon -b @embroider/addon-blueprint \
197+
--skip-git \
198+
--skip-npm \
199+
--addon-location="addons/my-addon" \
200+
--test-app-name="test-app-for-my-addon" \
201+
--test-app-location="tests/my-addon"
202+
```
203+
204+
## License
205+
206+
This project is licensed under the [MIT License](LICENSE.md).

additional-test-app-package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"devDependencies": {
3+
"@embroider/test-setup": "^3.0.1",
4+
"ember-try": "^3.0.0",
5+
"ember-source-channel-url": "^3.0.0"
6+
}
7+
}

files/.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
indent_style = space
13+
indent_size = 2
14+
15+
[*.hbs]
16+
insert_final_newline = false
17+
18+
[*.{diff,md}]
19+
trim_trailing_whitespace = false

files/.github/workflows/ci.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request: {}
9+
10+
concurrency:
11+
group: ci-${{ github.head_ref || github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
test:
16+
name: "Tests"
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
20+
steps:
21+
- uses: actions/checkout@v4<% if (pnpm) { %>
22+
- uses: pnpm/action-setup@v4<% } %>
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version: 18
26+
cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %>
27+
- name: Install Dependencies
28+
run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %>
29+
- name: Lint
30+
run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> lint
31+
- name: Run Tests
32+
run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> test
33+
34+
floating:
35+
name: "Floating Dependencies"
36+
runs-on: ubuntu-latest
37+
timeout-minutes: 10
38+
39+
steps:
40+
- uses: actions/checkout@v4<% if (pnpm) { %>
41+
- uses: pnpm/action-setup@v4<% } %>
42+
- uses: actions/setup-node@v4
43+
with:
44+
node-version: 18
45+
cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %>
46+
- name: Install Dependencies
47+
run: <%= pnpm ? 'pnpm install --no-lockfile' : yarn ? 'yarn install --no-lockfile' : 'npm install --no-package-lock' %>
48+
- name: Run Tests
49+
run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> test
50+
51+
try-scenarios:
52+
name: ${{ matrix.try-scenario }}
53+
runs-on: ubuntu-latest
54+
needs: "test"
55+
timeout-minutes: 10
56+
57+
strategy:
58+
fail-fast: false
59+
matrix:
60+
try-scenario:
61+
- ember-lts-4.12
62+
- ember-lts-5.4
63+
- ember-release
64+
- ember-beta
65+
- ember-canary
66+
- embroider-safe
67+
- embroider-optimized
68+
69+
steps:
70+
- uses: actions/checkout@v4<% if (pnpm) { %>
71+
- uses: pnpm/action-setup@v4<% } %>
72+
- uses: actions/setup-node@v4
73+
with:
74+
node-version: 18
75+
cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %>
76+
- name: Install Dependencies
77+
run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %>
78+
- name: Run Tests
79+
run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }} --skip-cleanup
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Because this library needs to be built,
2+
# we can't easily point package.json files at the git repo for easy cross-repo testing.
3+
#
4+
# This workflow brings back that capability by placing the compiled assets on a "dist" branch
5+
# (configurable via the "branch" option below)
6+
name: Push dist
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
- master
13+
14+
jobs:
15+
push-dist:
16+
name: Push dist
17+
permissions:
18+
contents: write
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 10
21+
22+
steps:
23+
- uses: actions/checkout@v4<% if (pnpm) { %>
24+
- uses: pnpm/action-setup@v4<% } %>
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: 18
28+
cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %>
29+
- name: Install Dependencies
30+
run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %>
31+
- uses: kategengler/[email protected]
32+
with:
33+
branch: dist
34+
token: ${{ secrets.GITHUB_TOKEN }}

files/.npmrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Docs: https://pnpm.io/npmrc
2+
# https://github.com/emberjs/rfcs/pull/907
3+
4+
# we don't want addons to be bad citizens of the ecosystem
5+
auto-install-peers=false
6+
7+
# we want true isolation,
8+
# if a dependency is not declared, we want an error
9+
resolve-peers-from-workspace-root=false

files/.prettierignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# unconventional js
2+
/blueprints/*/files/
3+
4+
# compiled output
5+
/dist/
6+
/declarations/
7+
8+
# misc
9+
/coverage/
10+
pnpm-lock.yaml

0 commit comments

Comments
 (0)