Skip to content

Commit

Permalink
chore: Updated fixtures (create-v2-addon-repo)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijlee2 committed Aug 19, 2024
1 parent 73efd0e commit 2798aac
Show file tree
Hide file tree
Showing 88 changed files with 457 additions and 319 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# blueprints-addon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2024 Isaac J. Lee

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.
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).
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# compiled output
/dist-for-testing/
/tmp/

# dependencies
/node_modules/

# misc
/.DS_Store
/.env*
/.eslintcache
/.eslintignore
/.eslintrc.cjs
/.git/
/.github/
/.gitignore
/.pnpm-debug.log
/.prettierignore
/.prettierrc.cjs
/build.sh
/tests/
/update-test-fixtures.sh
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "blueprints-addon",
"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
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`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ export function runGenerate(codemodOptions: CodemodOptions): void {
const options = createOptions(codemodOptions);

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

return;
}

updateAddon(options);
updateTestApp(options);

console.log(`✅ Created ${options.entity.name} and its test file.\n`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ export function runNew(codemodOptions: CodemodOptions): void {
const options = createOptions(codemodOptions);

if (canSkip(options)) {
console.log(
`🚫 Skipped creating ${options.addon.name}, because it already exists.\n`,
);

return;
}

createAddon(options);
updateDocsApp(options);
updateTestApp(options);

console.log(`✅ Created ${options.addon.name}.\n`);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { join } from 'node:path';

import { findFiles } from '@codemod-utils/files';

import type { Options } from '../../types/run-destroy.js';

export function canSkip(options: Options): boolean {
const { entity, projectRoot } = options;

const filePaths = findFiles(
join('src', `${entity.type}s`, `${entity.name}.*`),
{ projectRoot },
);

return filePaths.length === 0;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './can-skip.js';
export * from './create-options.js';
export * from './update-addon.js';
export * from './update-test-app.js';
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export function createOptions(codemodOptions: CodemodOptions): Options {
projectRoot,
testApp: {
location: testAppLocation,
name: 'test-app',
useTemplateTag: true,
},
};
}
Loading

0 comments on commit 2798aac

Please sign in to comment.