Skip to content

Commit

Permalink
Added blueprints for create-v2-addon-repo (Part 2) (#13)
Browse files Browse the repository at this point in the history
* refactor: Changed name to be a positional argument

* bugfix: Fixed blueprints

* chore: Updated fixtures

* chore: Added blueprints (test-app)

* chore: Updated fixtures

* chore: Added changeset

---------

Co-authored-by: ijlee2 <ijlee2@users.noreply.github.com>
  • Loading branch information
ijlee2 and ijlee2 authored Aug 15, 2024
1 parent 8c4327b commit b8dc54a
Show file tree
Hide file tree
Showing 155 changed files with 1,599 additions and 169 deletions.
6 changes: 6 additions & 0 deletions .changeset/tidy-walls-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"create-v2-addon-repo": minor
"blueprints-addon": minor
---

Added blueprints for create-v2-addon-repo (Part 2)
15 changes: 15 additions & 0 deletions packages/blueprints-addon/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# compiled output
/dist/
/dist-for-testing/
/tmp/

# dependencies
/node_modules/

# misc
/.DS_Store
/.env*
/.eslintcache
/npm-debug.log*
/pnpm-debug.log*
/pnpm-error.log*
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.container {}
.container {
/* Style here */
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ module('Integration | Helper | <%= options.entity.name %>', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
this.inputValue = '1234';

await render(<template>
{{<%= options.entity.camelizedName %> this.inputValue}}
{{<%= options.entity.camelizedName %> '1234'}}
</template>);

assert.dom().hasText('1234');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ module('Integration | Helper | <%= options.entity.name %>', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
this.inputValue = '1234';

await render(hbs`
{{<%= options.entity.name %> this.inputValue}}
{{<%= options.entity.name %> "1234"}}
`);

assert.dom().hasText('1234');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Helper from '@ember/component/helper';

type Named = {};
type Positional = [];
type Return = Positional;
type Positional = [string];
type Return = string;

interface <%= options.entity.classifiedName %>Signature {
Args: {
Expand All @@ -14,6 +14,6 @@ interface <%= options.entity.classifiedName %>Signature {

export default class <%= options.entity.classifiedName %>Helper extends Helper<<%= options.entity.classifiedName %>Signature> {
compute(positional: Positional /*, named: Named*/): Return {
return positional;
return positional[0];
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { helper } from '@ember/component/helper';

type Named = {};
type Positional = [];
type Return = Positional;
type Positional = [string];
type Return = string;

interface <%= options.entity.classifiedName %>Signature {
Args: {
Expand All @@ -14,6 +14,6 @@ interface <%= options.entity.classifiedName %>Signature {

export default helper<<%= options.entity.classifiedName %>Signature>(
(positional /*, named*/) => {
return positional;
return positional[0];
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Modifier from 'ember-modifier';

type Named = {};
type Positional = [];
type Element = Element;

interface <%= options.entity.classifiedName %>Signature {
Args: {
Expand All @@ -13,5 +12,7 @@ interface <%= options.entity.classifiedName %>Signature {
}

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

type Named = {};
type Positional = [];
type Element = Element;

interface <%= options.entity.classifiedName %>Signature {
Args: {
Expand All @@ -13,5 +12,7 @@ interface <%= options.entity.classifiedName %>Signature {
}

export default modifier<<%= options.entity.classifiedName %>Signature>(
function <%= options.entity.camelizedName %>(element /*, positional, named*/) {},
function <%= options.entity.camelizedName %>(element /*, positional, named*/) {
console.log(element);
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
# compiled output
/declarations/
/dist/

# <template> tag
/**/*.gjs
/**/*.gts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"babel-plugin-ember-template-compilation": "^2.2.5",
"blueprints-addon": "workspace:*",
"concurrently": "^8.2.2",
"ember-modifier": "^4.2.0",
"ember-source": "~5.10.2",
"ember-template-lint": "^6.0.0",
"eslint": "^8.57.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFileSync } from 'node:fs';
import { existsSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';

import {
Expand Down Expand Up @@ -26,13 +26,19 @@ function updateDevDependencies(
export function updateTestAppPackageJson(options: Options): void {
const { projectRoot, testApp } = options;

const testAppRoot = join(projectRoot, testApp.location);

if (!existsSync(join(testAppRoot, 'package.json'))) {
return;
}

const packageJson = readPackageJson({
projectRoot: join(projectRoot, testApp.location),
projectRoot: testAppRoot,
});

updateDevDependencies(packageJson, options);

const destination = join(projectRoot, testApp.location, 'package.json');
const destination = join(testAppRoot, 'package.json');
const file = JSON.stringify(packageJson, null, 2) + '\n';

writeFileSync(destination, file, 'utf8');
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.container {}
.container {
/* Style here */
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Helper from '@ember/component/helper';

type Named = {};
type Positional = [];
type Return = Positional;
type Positional = [string];
type Return = string;

interface MyHelper1Signature {
Args: {
Expand All @@ -14,6 +14,6 @@ interface MyHelper1Signature {

export default class MyHelper1Helper extends Helper<MyHelper1Signature> {
compute(positional: Positional /*, named: Named*/): Return {
return positional;
return positional[0];
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { helper } from '@ember/component/helper';

type Named = {};
type Positional = [];
type Return = Positional;
type Positional = [string];
type Return = string;

interface MyHelper2Signature {
Args: {
Expand All @@ -14,6 +14,6 @@ interface MyHelper2Signature {

export default helper<MyHelper2Signature>(
(positional /*, named*/) => {
return positional;
return positional[0];
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Modifier from 'ember-modifier';

type Named = {};
type Positional = [];
type Element = Element;

interface MyModifier1Signature {
Args: {
Expand All @@ -13,5 +12,7 @@ interface MyModifier1Signature {
}

export default class MyModifier1Modifier extends Modifier<MyModifier1Signature> {
modify(element: Element /*, positional: Positional, named: Named */) {}
modify(element: Element /*, positional: Positional, named: Named */) {
console.log(element);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { modifier } from 'ember-modifier';

type Named = {};
type Positional = [];
type Element = Element;

interface MyModifier2Signature {
Args: {
Expand All @@ -13,5 +12,7 @@ interface MyModifier2Signature {
}

export default modifier<MyModifier2Signature>(
function myModifier2(element /*, positional, named*/) {},
function myModifier2(element /*, positional, named*/) {
console.log(element);
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ module('Integration | Helper | my/helper-1', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
this.inputValue = '1234';

await render(<template>
{{myHelper1 this.inputValue}}
{{myHelper1 '1234'}}
</template>);

assert.dom().hasText('1234');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ module('Integration | Helper | my/helper-1', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
this.inputValue = '1234';

await render(hbs`
{{my/helper-1 this.inputValue}}
{{my/helper-1 "1234"}}
`);

assert.dom().hasText('1234');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ module('Integration | Helper | my/helper-2', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
this.inputValue = '1234';

await render(<template>
{{myHelper2 this.inputValue}}
{{myHelper2 '1234'}}
</template>);

assert.dom().hasText('1234');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ module('Integration | Helper | my/helper-2', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
this.inputValue = '1234';

await render(hbs`
{{my/helper-2 this.inputValue}}
{{my/helper-2 "1234"}}
`);

assert.dom().hasText('1234');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
# compiled output
/declarations/
/dist/

# <template> tag
/**/*.gjs
/**/*.gts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"babel-plugin-ember-template-compilation": "^2.2.5",
"blueprints-addon": "workspace:*",
"concurrently": "^8.2.2",
"ember-modifier": "^4.2.0",
"ember-source": "~5.10.2",
"ember-template-lint": "^6.0.0",
"eslint": "^8.57.0",
Expand Down
41 changes: 24 additions & 17 deletions packages/create-v2-addon-repo/bin/create-v2-addon-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,34 @@ import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

import { runCodemod } from '../src/index.js';
import type { CodemodOptions } from '../src/types/index.js';

// Provide a title to the process in `ps`
process.title = 'create-v2-addon-repo';

// Set codemod options
const argv = yargs(hideBin(process.argv))
.option('name', {
demandOption: true,
describe: 'Name of your project',
type: 'string',
})
.option('root', {
describe: 'Where to run the codemod',
type: 'string',
yargs(hideBin(process.argv))
.command({
builder: (yargs) => {
return yargs
.positional('name', {
describe: 'Name of your project',
type: 'string',
})
.option('root', {
describe: 'Where to run the codemod',
type: 'string',
})
.demandOption(['name']);
},
command: '* [name]',
describe: 'Creates a v2 addon repo',
handler: (argv) => {
runCodemod({
name: argv['name'],
projectRoot: argv['root'] ?? process.cwd(),
});
},
})
.demandCommand()
.strict()
.parseSync();

const codemodOptions: CodemodOptions = {
name: argv['name'],
projectRoot: argv['root'] ?? process.cwd(),
};

runCodemod(codemodOptions);
9 changes: 9 additions & 0 deletions packages/create-v2-addon-repo/src/blueprints/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c)

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.
17 changes: 7 additions & 10 deletions packages/create-v2-addon-repo/src/blueprints/__gitignore__
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist/
/tmp/
dist/
tmp/

# dependencies
/node_modules/
node_modules/

# misc
/.DS_Store
/.env*
/npm-debug.log*
/pnpm-debug.log*
/pnpm-error.log*
.DS_Store
.env*
pnpm-debug.log
pnpm-error.log
Loading

0 comments on commit b8dc54a

Please sign in to comment.