Skip to content

Commit

Permalink
Downstreamed changes from @codemod-utils/cli@2.0.1 (#30)
Browse files Browse the repository at this point in the history
* chore: Updated README

* chore: Updated dependencies

* chore: Updated import statements

* refactor: Renamed variables

* chore: Ran update-blueprints-addon

* chore: Added changeset

---------

Co-authored-by: ijlee2 <ijlee2@users.noreply.github.com>
  • Loading branch information
ijlee2 and ijlee2 authored Aug 28, 2024
1 parent 25ebe2c commit 32fee77
Show file tree
Hide file tree
Showing 68 changed files with 181 additions and 170 deletions.
6 changes: 6 additions & 0 deletions .changeset/fair-drinks-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"create-v2-addon-repo": minor
"analyze-ember-project-dependencies": patch
---

Downstreamed changes from @codemod-utils/cli@2.0.1
10 changes: 4 additions & 6 deletions packages/analyze-ember-project-dependencies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ _Analyze dependencies of an Ember project_

## Why use it?

Both Embroider and `pnpm` ask that packages declare their dependencies correctly. The codemod (really, a linter) performs a static code analysis, so that you can easily find missing and unused dependencies.
Both Embroider and `pnpm` ask that packages declare their dependencies correctly. The codemod (really, a linter) performs a static code analysis so that you can easily find missing and unused dependencies.

For more information, see [Fixing Package Dependencies](https://crunchingnumbers.live/2024/07/19/fixing-package-dependencies).


## Usage

Step 1. Run the codemod.
Step 1. Run the codemod (e.g. at the workspace root of a monorepo).

```sh
cd <path/to/your/project>
Expand Down Expand Up @@ -63,9 +63,9 @@ pnpm build

> [!IMPORTANT]
>
> The codemod uses a list of entities called `KNOWN_ENTITIES` to analyze implicit code. The list isn't meant to be exhaustive.
> The codemod uses a list called `KNOWN_ENTITIES` to analyze implicit code. The list accounts for packages that live outside of your project. It isn't meant to be (and doesn't have to be) exhaustive.
>
> Please modify `KNOWN_ENTITIES` to account for packages specific to your project.
> You can modify `KNOWN_ENTITIES` to get more accurate results.
>
> <details>
>
Expand All @@ -82,8 +82,6 @@ pnpm build
>
> // ...
> ]);
>
> export { KNOWN_ENTITIES };
> ```
>
> </details>
Expand Down
4 changes: 2 additions & 2 deletions packages/analyze-ember-project-dependencies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@codemod-utils/ast-javascript": "^1.2.8",
"@codemod-utils/ast-template": "^1.1.4",
"@codemod-utils/ember-cli-string": "^1.1.4",
"@codemod-utils/ember": "^2.0.0",
"@codemod-utils/files": "^2.0.4",
"@codemod-utils/json": "^1.1.9",
"content-tag": "^2.0.1",
Expand All @@ -46,7 +46,7 @@
"@shared-configs/prettier": "workspace:*",
"@shared-configs/typescript": "workspace:*",
"@sondr3/minitest": "^0.1.2",
"@types/node": "^18.19.39",
"@types/node": "^18.19.47",
"@types/yargs": "^17.0.32",
"concurrently": "^8.2.2",
"eslint": "^8.57.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { doubleColonize } from '@codemod-utils/ember-cli-string';
import { doubleColonize } from '@codemod-utils/ember';
import { findFiles } from '@codemod-utils/files';

import type { PackageType, ProjectDataEntities } from '../../types/index.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { doubleColonize } from '@codemod-utils/ember-cli-string';
import { doubleColonize } from '@codemod-utils/ember';

import type { PackageName, ProjectDataEntities } from '../../types/index.js';
import { KNOWN_ENTITIES as _KNOWN_ENTITIES } from './known-entities.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/blueprints-addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"@codemod-utils/ast-javascript": "^1.2.8",
"@codemod-utils/blueprints": "^1.1.5",
"@codemod-utils/ember-cli-string": "^1.1.4",
"@codemod-utils/ember": "^2.0.0",
"@codemod-utils/files": "^2.0.4",
"@codemod-utils/json": "^1.1.9",
"yargs": "^17.7.2"
Expand All @@ -46,7 +46,7 @@
"@shared-configs/prettier": "workspace:*",
"@shared-configs/typescript": "workspace:*",
"@sondr3/minitest": "^0.1.2",
"@types/node": "^18.19.44",
"@types/node": "^18.19.47",
"@types/yargs": "^17.0.33",
"concurrently": "^8.2.2",
"eslint": "^8.57.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { <%= options.entity.classifiedName %> } from '<%= options.addon.name %>';
import { <%= options.entity.pascalizedName %> } from '<%= options.addon.name %>';
import { render } from '@ember/test-helpers';
import { a11yAudit } from 'ember-a11y-testing/test-support';
import { module, test } from 'qunit';
Expand All @@ -9,7 +9,7 @@ module('Integration | Component | <%= options.entity.name %>', function (hooks)

test('it renders', async function (assert) {
await render(<template>
<<%= options.entity.classifiedName %> />
<<%= options.entity.pascalizedName %> />
</template>);

assert.dom().hasText('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import Component from '@glimmer/component';

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

interface <%= options.entity.classifiedName %>Signature {
interface <%= options.entity.pascalizedName %>Signature {
Args: {};
Blocks: {
default: [];
};
Element: null;
}

export default class <%= options.entity.classifiedName %>Component extends Component<<%= options.entity.classifiedName %>Signature> {
export default class <%= options.entity.pascalizedName %>Component extends Component<<%= options.entity.pascalizedName %>Signature> {
styles = styles;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Component from '@glimmer/component';

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

interface <%= options.entity.classifiedName %>Signature {
interface <%= options.entity.pascalizedName %>Signature {
Args: {};
Blocks: {
default: [];
Expand All @@ -11,7 +11,7 @@ interface <%= options.entity.classifiedName %>Signature {
}

// eslint-disable-next-line ember/no-empty-glimmer-component-classes
export default class <%= options.entity.classifiedName %>Component extends Component<<%= options.entity.classifiedName %>Signature> {
export default class <%= options.entity.pascalizedName %>Component extends Component<<%= options.entity.pascalizedName %>Signature> {
<template>
<div class={{styles.container}}>
{{yield}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import templateOnlyComponent from '@ember/component/template-only';

interface <%= options.entity.classifiedName %>Signature {
interface <%= options.entity.pascalizedName %>Signature {
Args: {};
Blocks: {
default: [];
};
Element: null;
}

const <%= options.entity.classifiedName %>Component =
templateOnlyComponent<<%= options.entity.classifiedName %>Signature>();
const <%= options.entity.pascalizedName %>Component =
templateOnlyComponent<<%= options.entity.pascalizedName %>Signature>();

export default <%= options.entity.classifiedName %>Component;
export default <%= options.entity.pascalizedName %>Component;
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import type { TOC } from '@ember/component/template-only';

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

interface <%= options.entity.classifiedName %>Signature {
interface <%= options.entity.pascalizedName %>Signature {
Args: {};
Blocks: {
default: [];
};
Element: null;
}

const <%= options.entity.classifiedName %>Component: TOC<<%= options.entity.classifiedName %>Signature> =
const <%= options.entity.pascalizedName %>Component: TOC<<%= options.entity.pascalizedName %>Signature> =
<template>
<div class={{styles.container}}>
{{yield}}
</div>
</template>;

export default <%= options.entity.classifiedName %>Component;
export default <%= options.entity.pascalizedName %>Component;
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ type Named = {};
type Positional = [string];
type Return = string;

interface <%= options.entity.classifiedName %>Signature {
interface <%= options.entity.pascalizedName %>Signature {
Args: {
Named: Named;
Positional: Positional;
};
Return: Return;
}

export default class <%= options.entity.classifiedName %>Helper extends Helper<<%= options.entity.classifiedName %>Signature> {
export default class <%= options.entity.pascalizedName %>Helper extends Helper<<%= options.entity.pascalizedName %>Signature> {
compute(positional: Positional /*, named: Named*/): Return {
return positional[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ type Named = {};
type Positional = [string];
type Return = string;

interface <%= options.entity.classifiedName %>Signature {
interface <%= options.entity.pascalizedName %>Signature {
Args: {
Named: Named;
Positional: Positional;
};
Return: Return;
}

export default helper<<%= options.entity.classifiedName %>Signature>(
export default helper<<%= options.entity.pascalizedName %>Signature>(
function <%= options.entity.camelizedName %>(positional /*, named*/) {
return positional[0];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import Modifier from 'ember-modifier';
type Named = {};
type Positional = [];

interface <%= options.entity.classifiedName %>Signature {
interface <%= options.entity.pascalizedName %>Signature {
Args: {
Named: Named;
Positional: Positional;
};
Element: Element;
}

export default class <%= options.entity.classifiedName %>Modifier extends Modifier<<%= options.entity.classifiedName %>Signature> {
export default class <%= options.entity.pascalizedName %>Modifier extends Modifier<<%= options.entity.pascalizedName %>Signature> {
modify(element: Element /*, positional: Positional, named: Named */) {
console.log(element);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { modifier } from 'ember-modifier';
type Named = {};
type Positional = [];

interface <%= options.entity.classifiedName %>Signature {
interface <%= options.entity.pascalizedName %>Signature {
Args: {
Named: Named;
Positional: Positional;
};
Element: Element;
}

export default modifier<<%= options.entity.classifiedName %>Signature>(
export default modifier<<%= options.entity.pascalizedName %>Signature>(
function <%= options.entity.camelizedName %>(element /*, positional, named*/) {
console.log(element);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Service from '@ember/service';

export default class <%= options.entity.classifiedName %>Service extends Service {}
export default class <%= options.entity.pascalizedName %>Service extends Service {}

declare module '@ember/service' {
interface Registry {
'<%= options.entity.name %>': <%= options.entity.classifiedName %>Service;
'<%= options.entity.name %>': <%= options.entity.pascalizedName %>Service;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default interface <%= options.addon.pascalCaseName %>Registry {}
export default interface <%= options.addon.pascalizedName %>Registry {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import 'ember-source/types';

import type EmbroiderCssModulesRegistry from 'embroider-css-modules/template-registry';

import type <%= options.addon.pascalCaseName %>Registry from '../src/template-registry.ts';
import type <%= options.addon.pascalizedName %>Registry from '../src/template-registry.ts';

declare module '@glint/environment-ember-loose/registry' {
export default interface Registry
extends <%= options.addon.pascalCaseName %>Registry,
extends <%= options.addon.pascalizedName %>Registry,
EmbroiderCssModulesRegistry {
// Add any registry entries from other addons here that your addon itself uses (in non-strict mode templates)
// See https://typed-ember.gitbook.io/glint/using-glint/ember/using-addons
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'node:path';

import { classify, doubleColonize } from '@codemod-utils/ember-cli-string';
import { camelize, doubleColonize, pascalize } from '@codemod-utils/ember';
import { readPackageJson } from '@codemod-utils/json';

import type { CodemodOptions, Options } from '../../types/run-generate.js';
Expand All @@ -14,9 +14,9 @@ function getPackageName(projectRoot: string): string {
export function createOptions(codemodOptions: CodemodOptions): Options {
const { entity, projectRoot, testAppLocation } = codemodOptions;

const classifiedName = classify(entity.name);
const camelizedName = `${classifiedName.charAt(0).toLowerCase()}${classifiedName.substring(1)}`;
const camelizedName = camelize(entity.name);
const doubleColonizedName = doubleColonize(entity.name);
const pascalizedName = pascalize(entity.name);

return {
addon: {
Expand All @@ -25,8 +25,8 @@ export function createOptions(codemodOptions: CodemodOptions): Options {
entity: {
...entity,
camelizedName,
classifiedName,
doubleColonizedName,
pascalizedName,
},
projectRoot,
testApp: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function addExportStatement(file: string, options: Options): string {
entity.blueprint === 'glimmer-strict' ||
entity.blueprint === 'template-only-strict'
) {
line = `export { default as ${entity.classifiedName} } from './${entity.type}s/${entity.name}.gts';\n`;
line = `export { default as ${entity.pascalizedName} } from './${entity.type}s/${entity.name}.gts';\n`;
} else {
line = `export { default as ${entity.classifiedName} } from './${entity.type}s/${entity.name}.ts';\n`;
line = `export { default as ${entity.pascalizedName} } from './${entity.type}s/${entity.name}.ts';\n`;
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ function getLocalName(options: Options): string {

switch (entity.type) {
case 'component': {
return `${entity.classifiedName}Component`;
return `${entity.pascalizedName}Component`;
}

case 'helper': {
return `${entity.classifiedName}Helper`;
return `${entity.pascalizedName}Helper`;
}

case 'modifier': {
return `${entity.classifiedName}Modifier`;
return `${entity.pascalizedName}Modifier`;
}

default: {
return entity.classifiedName;
return entity.pascalizedName;
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions packages/blueprints-addon/src/steps/run-new/create-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ function dasherize(packageName: string): string {
return packageName.replace('@', '').replace(/\W|_/g, '-');
}

function pascalCase(packageName: string): string {
function pascalize(packageName: string): string {
const dasherizedName = dasherize(packageName);

return dasherizedName
.split('-')
.map((token) => `${token.charAt(0).toUpperCase()}${token.substring(1)}`)
.map((token) => {
return token.charAt(0).toUpperCase() + token.substring(1).toLowerCase();
})
.join('');
}

export function createOptions(codemodOptions: CodemodOptions): Options {
const { location, name, projectRoot } = codemodOptions;

const dasherizedName = dasherize(name);
const pascalCaseName = pascalCase(name);
const pascalizedName = pascalize(name);

const addonLocation = join('packages', location ?? dasherize(name));
const addonLocationInverse = relative(addonLocation, '.');
Expand All @@ -30,7 +32,7 @@ export function createOptions(codemodOptions: CodemodOptions): Options {
location: addonLocation,
locationInverse: addonLocationInverse,
name,
pascalCaseName,
pascalizedName,
},
docsApp: {
location: 'docs-app',
Expand Down
Loading

0 comments on commit 32fee77

Please sign in to comment.