Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented generate commands (Part 1) #6

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/selfish-onions-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"blueprints-addon": minor
---

Implemented generate commands (Part 1)
16 changes: 16 additions & 0 deletions packages/blueprints-addon/bin/blueprints-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ yargs(hideBin(process.argv))
describe: 'Where to run the codemod',
type: 'string',
})
.option('test-app-location', {
demandOption: true,
describe: 'Location of the test-app',
type: 'string',
})
.demandOption(['entity-type', 'name']);
},
command: 'destroy [entity-type] [name]',
Expand All @@ -45,6 +50,7 @@ yargs(hideBin(process.argv))
type: argv['entity-type'],
},
projectRoot: argv['root'] ?? process.cwd(),
testAppLocation: argv['test-app-location'],
});
},
})
Expand All @@ -67,6 +73,11 @@ yargs(hideBin(process.argv))
describe: 'Where to run the codemod',
type: 'string',
})
.option('test-app-location', {
demandOption: true,
describe: 'Location of the test-app',
type: 'string',
})
.command({
builder: (yargs) => {
return yargs
Expand All @@ -92,6 +103,7 @@ yargs(hideBin(process.argv))
type: 'component',
},
projectRoot: argv['root'] ?? process.cwd(),
testAppLocation: argv['test-app-location'],
});
},
})
Expand Down Expand Up @@ -120,6 +132,7 @@ yargs(hideBin(process.argv))
type: 'helper',
},
projectRoot: argv['root'] ?? process.cwd(),
testAppLocation: argv['test-app-location'],
});
},
})
Expand Down Expand Up @@ -148,6 +161,7 @@ yargs(hideBin(process.argv))
type: 'modifier',
},
projectRoot: argv['root'] ?? process.cwd(),
testAppLocation: argv['test-app-location'],
});
},
})
Expand Down Expand Up @@ -176,6 +190,7 @@ yargs(hideBin(process.argv))
type: 'service',
},
projectRoot: argv['root'] ?? process.cwd(),
testAppLocation: argv['test-app-location'],
});
},
})
Expand Down Expand Up @@ -204,6 +219,7 @@ yargs(hideBin(process.argv))
type: 'util',
},
projectRoot: argv['root'] ?? process.cwd(),
testAppLocation: argv['test-app-location'],
});
},
})
Expand Down
13 changes: 10 additions & 3 deletions packages/blueprints-addon/codemod-test-fixture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
#---------

# Get named arguments for the binary
while getopts ":N:" flag
while getopts ":C:N:" flag
do
case $flag in
C) COMMAND=$OPTARG;;
N) NAMED_ARGUMENTS=$OPTARG;;
esac
done

# Get fixture name
FIXTURE=${@:$OPTIND:1}
FIXTURE=${@:$OPTIND:2}

if [ ! $FIXTURE ]
then
Expand All @@ -39,6 +40,12 @@ fi
rm -r "tests/fixtures/$FIXTURE/output"
cp -r "tests/fixtures/$FIXTURE/input" "tests/fixtures/$FIXTURE/output"

./dist/bin/blueprints-addon.js $NAMED_ARGUMENTS --root="tests/fixtures/$FIXTURE/output"
if [[ $COMMAND == "destroy" || $COMMAND == "generate" ]]
then
./dist/bin/blueprints-addon.js $NAMED_ARGUMENTS --root "tests/fixtures/$FIXTURE/output/packages/ui/button" --test-app-location "../../../test-app"
elif [[ $COMMAND == "new" ]]
then
./dist/bin/blueprints-addon.js $NAMED_ARGUMENTS --root "tests/fixtures/$FIXTURE/output"
fi

echo "SUCCESS: Updated the output of $FIXTURE.\n"
61 changes: 51 additions & 10 deletions packages/blueprints-addon/codemod-test-fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,86 @@
pnpm build

./codemod-test-fixture.sh \
-C "destroy" \
-N "destroy component my/example-1" \
run-destroy-component/typescript
run-destroy-component/glimmer

./codemod-test-fixture.sh \
-C "destroy" \
-N "destroy component my/example-1" \
run-destroy-component/template-tag

./codemod-test-fixture.sh \
-C "destroy" \
-N "destroy helper my/example-1" \
run-destroy-helper/class

./codemod-test-fixture.sh \
-C "destroy" \
-N "destroy helper my/example-1" \
run-destroy-helper/typescript
run-destroy-helper/function

./codemod-test-fixture.sh \
-C "destroy" \
-N "destroy modifier my/example-1" \
run-destroy-modifier/typescript
run-destroy-modifier/class

./codemod-test-fixture.sh \
-C "destroy" \
-N "destroy modifier my/example-1" \
run-destroy-modifier/function

./codemod-test-fixture.sh \
-C "destroy" \
-N "destroy service my/example-1" \
run-destroy-service/typescript
run-destroy-service/class

./codemod-test-fixture.sh \
-C "destroy" \
-N "destroy util my/example-1" \
run-destroy-util/typescript
run-destroy-util/function

./codemod-test-fixture.sh \
-C "generate" \
-N "generate component my/example-1" \
run-generate-component/typescript
run-generate-component/glimmer

./codemod-test-fixture.sh \
-C "generate" \
-N "generate component my/example-1 --blueprint-type template-tag" \
run-generate-component/template-tag

./codemod-test-fixture.sh \
-C "generate" \
-N "generate helper my/example-1" \
run-generate-helper/typescript
run-generate-helper/class

./codemod-test-fixture.sh \
-C "generate" \
-N "generate helper my/example-1 --blueprint-type function" \
run-generate-helper/function

./codemod-test-fixture.sh \
-C "generate" \
-N "generate modifier my/example-1" \
run-generate-modifier/typescript
run-generate-modifier/class

./codemod-test-fixture.sh \
-C "generate" \
-N "generate modifier my/example-1 --blueprint-type function" \
run-generate-modifier/function

./codemod-test-fixture.sh \
-C "generate" \
-N "generate service my/example-1" \
run-generate-service/typescript
run-generate-service/class

./codemod-test-fixture.sh \
-C "generate" \
-N "generate util my/example-1" \
run-generate-util/typescript
run-generate-util/function

./codemod-test-fixture.sh \
-C "new" \
-N "new --location ui/button --name @my-org-ui/button" \
run-new/typescript
3 changes: 2 additions & 1 deletion packages/blueprints-addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
"dependencies": {
"@codemod-utils/ast-javascript": "^1.2.8",
"@codemod-utils/blueprints": "^1.1.5",
"@codemod-utils/json": "^1.1.9",
"@codemod-utils/ember-cli-string": "^1.1.4",
"@codemod-utils/files": "^2.0.4",
"@codemod-utils/json": "^1.1.9",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { <%= data.entity.classifiedName %> } from '<%! options.package.name %>';
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'test-app/tests/helpers';

module('Integration | Component | <%= data.entity.name %>', function (hooks) {
setupRenderingTest(hooks);

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

assert.dom().hasText('');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'test-app/tests/helpers';

module('Integration | Component | <%= data.entity.name %>', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
await render(hbs`
<<%= data.entity.doubleColonizedName %> />
`);

assert.dom().hasText('');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.container {
/* Style here */
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare const styles: {
readonly 'container': string;
};

export default styles;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class={{this.styles.container}}>
{{yield}}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Component from '@glimmer/component';

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

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

export default class <%= data.entity.classifiedName %>Component extends Component<<%= data.entity.classifiedName %>Signature> {
styles = styles;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.container {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare const styles: {
readonly 'container': string;
};

export default styles;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Component from '@glimmer/component';

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

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

export default class <%= data.entity.classifiedName %>Component extends Component<<%= data.entity.classifiedName %>Signature> {
<template>
<div class={{styles.container}}>
{{yield}}
</div>
</template>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { <%= data.entity.camelizedName %> } from '<%! options.package.name %>';
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'test-app/tests/helpers';

module('Integration | Helper | <%= data.entity.name %>', function (hooks) {
setupRenderingTest(hooks);

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

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

assert.dom().hasText('1234');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'test-app/tests/helpers';

module('Integration | Helper | <%= data.entity.name %>', function (hooks) {
setupRenderingTest(hooks);

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

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

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

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

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

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

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

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

export default helper<<%= data.entity.classifiedName %>Signature>(
(positional /*, named*/) => {
return positional;
},
);
Loading