Skip to content

Commit

Permalink
Updated blueprints (#17)
Browse files Browse the repository at this point in the history
* feature: Provided feedback to end-developer

* chore: Simplified scripts

* feature: Added READMEs

* refactor: Exposed default blueprint values

* feature: Updated lint configurations to support <template> tag

* feature: Allowed *.gts test files and took the test-app name into account

* chore: Updated fixtures (blueprints-addon)

* chore: Updated the update-blueprints-addon script

* chore: Updated fixtures (create-v2-addon-repo)

* chore: Added changeset

---------

Co-authored-by: ijlee2 <ijlee2@users.noreply.github.com>
  • Loading branch information
ijlee2 and ijlee2 authored Aug 19, 2024
1 parent de1681e commit 3f97277
Show file tree
Hide file tree
Showing 138 changed files with 813 additions and 505 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-elephants-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-v2-addon-repo": minor
---

Updated blueprints
8 changes: 4 additions & 4 deletions configs/eslint/ember/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ module.exports = {
},
},
{
files: ['**/*.gts'],
files: ['**/*.gjs'],
parser: 'ember-eslint-parser',
extends: ['plugin:ember/recommended-gts'],
extends: ['plugin:ember/recommended-gjs'],
},
{
files: ['**/*.gjs'],
files: ['**/*.gts'],
parser: 'ember-eslint-parser',
extends: ['plugin:ember/recommended-gjs'],
extends: ['plugin:ember/recommended-gts'],
},
{
files: ['**/*.{gjs,gts,js,ts}'],
Expand Down
8 changes: 4 additions & 4 deletions configs/eslint/ember/v1-addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ module.exports = {
},
},
{
files: ['**/*.gts'],
files: ['**/*.gjs'],
parser: 'ember-eslint-parser',
extends: ['plugin:ember/recommended-gts'],
extends: ['plugin:ember/recommended-gjs'],
},
{
files: ['**/*.gjs'],
files: ['**/*.gts'],
parser: 'ember-eslint-parser',
extends: ['plugin:ember/recommended-gjs'],
extends: ['plugin:ember/recommended-gts'],
},
{
files: ['**/*.{gjs,gts,js,ts}'],
Expand Down
8 changes: 4 additions & 4 deletions configs/eslint/ember/v2-addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ module.exports = {
},
},
{
files: ['**/*.gts'],
files: ['**/*.gjs'],
parser: 'ember-eslint-parser',
extends: ['plugin:ember/recommended-gts'],
extends: ['plugin:ember/recommended-gjs'],
},
{
files: ['**/*.gjs'],
files: ['**/*.gts'],
parser: 'ember-eslint-parser',
extends: ['plugin:ember/recommended-gjs'],
extends: ['plugin:ember/recommended-gts'],
},
{
files: ['**/*.{gjs,gts,js,ts}'],
Expand Down
30 changes: 0 additions & 30 deletions packages/blueprints-addon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1 @@
# blueprints-addon

## 0.3.0

### Minor Changes

- [#16](https://github.com/ijlee2/embroider-toolbox/pull/16) Added blueprints for create-v2-addon-repo (Part 5) ([@ijlee2](https://github.com/ijlee2))

## 0.2.0

### Minor Changes

- [#10](https://github.com/ijlee2/embroider-toolbox/pull/10) Simplified API for new command and tests ([@ijlee2](https://github.com/ijlee2))
- [#13](https://github.com/ijlee2/embroider-toolbox/pull/13) Added blueprints for create-v2-addon-repo (Part 2) ([@ijlee2](https://github.com/ijlee2))
- [#14](https://github.com/ijlee2/embroider-toolbox/pull/14) Added blueprints for create-v2-addon-repo (Part 3) ([@ijlee2](https://github.com/ijlee2))

### Patch Changes

- [#12](https://github.com/ijlee2/embroider-toolbox/pull/12) Specified the location of test-app for generate and destroy commands ([@ijlee2](https://github.com/ijlee2))

## 0.1.0

### Minor Changes

- [#2](https://github.com/ijlee2/embroider-toolbox/pull/2) Scaffolded blueprints-addon ([@ijlee2](https://github.com/ijlee2))
- [#3](https://github.com/ijlee2/embroider-toolbox/pull/3) Implemented new command ([@ijlee2](https://github.com/ijlee2))
- [#4](https://github.com/ijlee2/embroider-toolbox/pull/4) Scaffolded generate and destroy commands ([@ijlee2](https://github.com/ijlee2))
- [#5](https://github.com/ijlee2/embroider-toolbox/pull/5) Separated generate commands ([@ijlee2](https://github.com/ijlee2))
- [#6](https://github.com/ijlee2/embroider-toolbox/pull/6) Implemented generate commands (Part 1) ([@ijlee2](https://github.com/ijlee2))
- [#7](https://github.com/ijlee2/embroider-toolbox/pull/7) Implemented generate commands (Part 2) ([@ijlee2](https://github.com/ijlee2))
- [#8](https://github.com/ijlee2/embroider-toolbox/pull/8) Implemented destroy commands ([@ijlee2](https://github.com/ijlee2))
72 changes: 72 additions & 0 deletions packages/blueprints-addon/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,73 @@
# blueprints-addon

_CLI for v2 addons_

1. [Features](#features)
1. [Usage](#usage)
1. [Compatibility](#compatibility)


## Features

Standardize how you write v2 addons:

- Run `new` to create a v2 addon
- Run `generate` to create source and test files
- Run `destroy` to remove source and test files
- Blueprints available for components, helpers, modifiers, services, and utilities
- Tailor addon blueprints to your needs


## Usage

Install `blueprints-addon` as a development dependency in these locations:

<details>

<summary>Workspace root</summary>

```json5
/* package.json */
{
"scripts": {
"addon": "blueprints-addon"
},
"devDependencies": {
"blueprints-addon": "workspace:*"
}
}
```

</details>

<details>

<summary>V2 addon in <code>packages</code></summary>

```json5
/* Example: packages/ui/button/package.json */
{
"scripts": {
"addon": "blueprints-addon --test-app-location '../../../test-app'"
},
"devDependencies": {
"blueprints-addon": "workspace:*"
}
}
```

</details>

> [!NOTE]
>
> After you build `blueprints-addon`, please run `pnpm install` at the workspace root so that the blueprints are available.

## Compatibility

- Node.js v18 or above


## License

This project is licensed under the [MIT License](LICENSE.md).
20 changes: 15 additions & 5 deletions packages/blueprints-addon/bin/blueprints-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import { runDestroy, runGenerate, runNew } from '../src/index.js';
process.title = 'blueprints-addon';

// Set codemod options
const DEFAULT_BLUEPRINT_VALUE = {
component: 'glimmer',
helper: 'class',
modifier: 'class',
service: 'class',
util: 'function',
} as const;

yargs(hideBin(process.argv))
.command({
aliases: ['d'],
Expand Down Expand Up @@ -98,7 +106,8 @@ yargs(hideBin(process.argv))
handler: (argv) => {
runGenerate({
entity: {
blueprint: argv['blueprint'] ?? 'glimmer',
blueprint:
argv['blueprint'] ?? DEFAULT_BLUEPRINT_VALUE.component,
name: argv['name'],
type: 'component',
},
Expand Down Expand Up @@ -127,7 +136,7 @@ yargs(hideBin(process.argv))
handler: (argv) => {
runGenerate({
entity: {
blueprint: argv['blueprint'] ?? 'class',
blueprint: argv['blueprint'] ?? DEFAULT_BLUEPRINT_VALUE.helper,
name: argv['name'],
type: 'helper',
},
Expand Down Expand Up @@ -156,7 +165,8 @@ yargs(hideBin(process.argv))
handler: (argv) => {
runGenerate({
entity: {
blueprint: argv['blueprint'] ?? 'class',
blueprint:
argv['blueprint'] ?? DEFAULT_BLUEPRINT_VALUE.modifier,
name: argv['name'],
type: 'modifier',
},
Expand Down Expand Up @@ -185,7 +195,7 @@ yargs(hideBin(process.argv))
handler: (argv) => {
runGenerate({
entity: {
blueprint: argv['blueprint'] ?? 'class',
blueprint: argv['blueprint'] ?? DEFAULT_BLUEPRINT_VALUE.service,
name: argv['name'],
type: 'service',
},
Expand Down Expand Up @@ -214,7 +224,7 @@ yargs(hideBin(process.argv))
handler: (argv) => {
runGenerate({
entity: {
blueprint: argv['blueprint'] ?? 'function',
blueprint: argv['blueprint'] ?? DEFAULT_BLUEPRINT_VALUE.util,
name: argv['name'],
type: 'util',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/blueprints-addon/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "blueprints-addon",
"version": "0.3.0",
"version": "0.0.0",
"private": true,
"description": "Blueprints for v2 addons",
"description": "CLI for v2 addons",
"keywords": [
"codemod",
"ember-codemod",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { <%= options.entity.classifiedName %> } from '<%= options.addon.name %>';
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'test-app/tests/helpers';
import { setupRenderingTest } from '<%= options.testApp.name %>/tests/helpers';

module('Integration | Component | <%= options.entity.name %>', function (hooks) {
setupRenderingTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'test-app/tests/helpers';
import { setupRenderingTest } from '<%= options.testApp.name %>/tests/helpers';

module('Integration | Component | <%= options.entity.name %>', function (hooks) {
setupRenderingTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Component from '@glimmer/component';
import type { TOC } from '@ember/component/template-only';

import styles from './<%= data.localFileName %>.css';

Expand All @@ -10,11 +10,11 @@ interface <%= options.entity.classifiedName %>Signature {
Element: null;
}

// eslint-disable-next-line ember/no-empty-glimmer-component-classes
export default class <%= options.entity.classifiedName %>Component extends Component<<%= options.entity.classifiedName %>Signature> {
const <%= options.entity.classifiedName %>Component: TOC<<%= options.entity.classifiedName %>Signature> =
<template>
<div class={{styles.container}}>
{{yield}}
</div>
</template>
}
</template>;

export default <%= options.entity.classifiedName %>Component;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { <%= options.entity.camelizedName %> } from '<%= options.addon.name %>';
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'test-app/tests/helpers';
import { setupRenderingTest } from '<%= options.testApp.name %>/tests/helpers';

module('Integration | Helper | <%= options.entity.name %>', function (hooks) {
setupRenderingTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'test-app/tests/helpers';
import { setupRenderingTest } from '<%= options.testApp.name %>/tests/helpers';

module('Integration | Helper | <%= options.entity.name %>', function (hooks) {
setupRenderingTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { <%= options.entity.camelizedName %> } from '<%= options.addon.name %>';
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'test-app/tests/helpers';
import { setupRenderingTest } from '<%= options.testApp.name %>/tests/helpers';

module('Integration | Modifier | <%= options.entity.name %>', function (hooks) {
setupRenderingTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'test-app/tests/helpers';
import { setupRenderingTest } from '<%= options.testApp.name %>/tests/helpers';

module('Integration | Modifier | <%= options.entity.name %>', function (hooks) {
setupRenderingTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { setupTest } from 'test-app/tests/helpers';
import { setupTest } from '<%= options.testApp.name %>/tests/helpers';

module('Unit | Service | <%= options.entity.name %>', function (hooks) {
setupTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,4 @@ require('@shared-configs/eslint-config-ember/patch');

module.exports = {
extends: ['@shared-configs/eslint-config-ember/v2-addon'],
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
overrides: [
// TypeScript files
{
files: ['**/*.{gts,ts}'],
rules: {
'@typescript-eslint/no-unnecessary-condition': 'error',
},
},
// JavaScript files
{
files: ['**/*.{cjs,js,gjs,mjs}'],
extends: ['plugin:@typescript-eslint/disable-type-checked'],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@
# compiled output
/declarations/
/dist/

# <template> tag
/**/*.gjs
/**/*.gts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pnpm start

<summary>Generate and destroy</summary>

From the package root, you can create (or remove) the source code and its corresponding test file in `test-app`.
From the package root, you can create (or remove) the source code and its corresponding test file in `<%= options.testApp.name %>`.

```sh
pnpm addon <generate|destroy> <component|helper|modifier|service|util> <name> [options]
Expand All @@ -43,4 +43,4 @@ For more information, pass `--help`.

## Compatibility

* Node.js v18 or above
- Node.js v18 or above
11 changes: 11 additions & 0 deletions packages/blueprints-addon/src/run-destroy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
canSkip,
createOptions,
updateAddon,
updateTestApp,
Expand All @@ -8,6 +9,16 @@ import type { CodemodOptions } from './types/run-destroy.js';
export function runDestroy(codemodOptions: CodemodOptions): void {
const options = createOptions(codemodOptions);

if (canSkip(options)) {
console.log(
`🚫 Skipped removing ${options.entity.name}, because it was already removed.\n`,
);

return;
}

updateAddon(options);
updateTestApp(options);

console.log(`✅ Removed ${options.entity.name} and its test file.\n`);
}
Loading

0 comments on commit 3f97277

Please sign in to comment.