Skip to content

Commit

Permalink
make sure ember-cli-update config is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed May 24, 2024
1 parent b7d860f commit c14a72f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
26 changes: 19 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Blueprint = require('ember-cli/lib/models/blueprint');
const fs = require('fs-extra');
const { join } = require('path');
const emberCliUpdate = require('./lib/ember-cli-update');

const appBlueprint = Blueprint.lookup('app');

Expand All @@ -19,13 +20,7 @@ module.exports = {
});
},

async afterInstall(options) {
// there doesn't seem to be a way to tell ember-cli to not prompt to override files that were added in the beforeInstall
// so I'm just copying a few over at this stage
await fs.copy(join(__dirname, 'files-override'), options.target, {
overwrite: true,
});

async updateDeps(options) {
// this.addPackagesToProject doesn't respect the packageManager that the blueprint specified 🙈 so we're skipping a level here
let installTask = this.taskFor('npm-install');
await installTask.run({
Expand All @@ -49,6 +44,14 @@ module.exports = {
packages: ['ember-fetch'],
packageManager: options.packageManager,
});
},

async afterInstall(options) {
// there doesn't seem to be a way to tell ember-cli to not prompt to override files that were added in the beforeInstall
// so I'm just copying a few over at this stage
await fs.copy(join(__dirname, 'files-override'), options.target, {
overwrite: true,
});

let packageJson = join(options.target, 'package.json');
let json = await fs.readJSON(packageJson);
Expand All @@ -61,5 +64,14 @@ module.exports = {
};

await fs.writeFile(packageJson, JSON.stringify(json, null, 2));

await emberCliUpdate({
projectDir: options.target,
projectName: options.projectName,
version: require('./package.json').version,
options,
});

await this.updateDeps(options);
},
};
34 changes: 34 additions & 0 deletions lib/ember-cli-update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fs = require('fs-extra');
const { join } = require('path');

module.exports = async function ({
projectDir,
projectName,
version,
options = [],
} = {}) {
fs.writeJSON(
join(projectDir, 'config', 'ember-cli-update.json'),
{
schemaVersion: '1.0.0',
projectName,
packages: [
{
name: '@embroider/app-blueprint',
version,
blueprints: [
{
name: '@embroider/app-blueprint',
isBaseBlueprint: true,
// TODO pass more of the original options through
options: [`--package-manager ${options.packageManager}`],
},
],
},
],
},
{
spaces: 2,
},
);
};

0 comments on commit c14a72f

Please sign in to comment.