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

document tasks needed to get this addon working #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -28,7 +28,7 @@ module.exports = codemodBlueprint({
/**
* runs after the upstream blueprint is installed
*/
transform(options, helpers) {
async transform(options, helpers) {
let { transformTemplate, transformScript } = helpers;
let { project, args } = options;
let projectRoot = project.root;
Expand Down
71 changes: 59 additions & 12 deletions lib/base-blueprint.js
Expand Up @@ -4,17 +4,29 @@
const path = require('path');
const fs = require('fs').promises;
const execa = require('execa');
const Blueprint = require('ember-cli/lib/models/blueprint');
const recast = require('ember-template-recast');
const jscodeshift = require('jscodeshift');

const Blueprint = require('ember-cli/lib/models/blueprint');
const mergeBlueprintOptions = require('ember-cli/lib/utilities/merge-blueprint-options');

/**
* TODO: add an API to ember-cli to allow
* accessing what files are generated in afterInstall
*/
module.exports = {
description: 'Codemod Base Blueprint',

/**
* Be sure to `this._super.call(this)` if overriding
*/
async beforeInstall(options) {
await this._installUpstreamBlueprint(options);
},

/**
* Be sure to `this._super.call(this)` if overriding
*/
async afterInstall(options) {
if (!this.transform) {
throw new Error('codemod-blueprint must define a `transform` hook');
Expand Down Expand Up @@ -64,24 +76,59 @@ module.exports = {
});
},

async _installUpstreamBlueprint(options) {
beforeInstall(options) {
let [, ...args] = options.args;
let blueprint = this._upstreamBlueprintPath();

mergeBlueprintOptions.call(this, [blueprint, ...args]);
},

async beforeUninstall(options) {
await this._uninstallUpstreamBlueprint(options);
},

/**
* @private - do not use outside of ember-codemod-blueprint
*/
async _installUpstreamBlueprint(options) {
let taskOptions = this._upstreamTaskOptions(options);

// https://github.com/ember-cli/ember-cli/blob/master/lib/tasks/install-blueprint.js
let blueprint = 'component';
// await this.taskFor('install-blueprint').run(taskOptions);
await this.taskFor('generate-from-blueprint').run(taskOptions);
},

/**
* @private - do not use outside of ember-codemod-blueprint
*/
async _uninstallUpstreamBlueprint(options) {
let taskOptions = this._upstreamTaskOptions(options);

await this.taskFor('destroy-from-blueprint').run(taskOptions);
},

/**
* @private - do not use outside of ember-codemod-blueprint
*/
_upstreamTaskOptions(options) {
let [, ...args] = options.args;
let blueprint = this._upstreamBlueprintPath();

let taskOptions = {
...options,
// TODO: load blueprint options
...options.taskOptions,
blueprint,
rawName: options.entity.name,
args: [blueprint, ...args],
taskOptions: {
...options.taskOptions,
args: [blueprint, ...args],
},
rawArgs: [blueprint, ...args],
originBlueprintName: blueprint,
};

await this.taskFor('install-blueprint').run(taskOptions);
return taskOptions;
},

_upstreamBlueprintPath() {
// If this exists, it'll have the `index.js` at the end
let blueprintIndex = require.resolve(this.upstream, { paths: [process.cwd()] });
let blueprint = blueprintIndex.replace(/\/index\.js$/, '');

return blueprint;
},
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -67,7 +67,7 @@
"typescript": "^4.1.2"
},
"engines": {
"node": "10.* || >= 12"
"node": ">= 12"
},
"ember": {
"edition": "octane"
Expand Down