Skip to content

Commit 0168aac

Browse files
author
Ruslan Hrabovyi
committed
move addon package transforms back to method
1 parent 53c4f0d commit 0168aac

File tree

1 file changed

+17
-26
lines changed
  • ts/blueprints/ember-cli-typescript

1 file changed

+17
-26
lines changed

ts/blueprints/ember-cli-typescript/index.js

+17-26
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,7 @@ module.exports = {
121121

122122
beforeInstall() {
123123
if (this.project.isEmberCLIAddon()) {
124-
let pkg = readPackage(this.project);
125-
126-
this._installPrecompilationHooks(pkg);
127-
128-
if (pkg.devDependencies['ember-cli-typescript']) {
129-
pkg.dependencies['ember-cli-typescript'] = pkg.devDependencies['ember-cli-typescript'];
130-
delete pkg.devDependencies['ember-cli-typescript'];
131-
}
132-
133-
writePackage(this.project, pkg);
124+
this._transformAddonPackage();
134125
}
135126

136127
let packages = [
@@ -184,11 +175,23 @@ module.exports = {
184175
return this.project.isModuleUnification && this.project.isModuleUnification();
185176
},
186177

187-
_installPrecompilationHooks(pkg) {
188-
// Really `prepack` and `postpack` would be ideal, but yarn doesn't execute those when publishing
189-
this._addScript(pkg.scripts, 'prepublishOnly', 'ember ts:precompile');
190-
this._addScript(pkg.scripts, 'postpublish', 'ember ts:clean');
178+
_transformAddonPackage() {
179+
const pkgPath = `${this.project.root}/package.json`;
180+
181+
let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
182+
183+
// Really `prepack` and `postpack` would be ideal, but yarn doesn't execute those when publishing
184+
this._addScript(pkg.scripts, 'prepublishOnly', 'ember ts:precompile');
185+
this._addScript(pkg.scripts, 'postpublish', 'ember ts:clean');
186+
187+
// avoid being placed in devDependencies
188+
const name = 'ember-cli-typescript';
189+
if (pkg.devDependencies[name]) {
190+
pkg.dependencies[name] = pkg.devDependencies[name];
191+
delete pkg.devDependencies[name];
192+
}
191193

194+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
192195
},
193196

194197
_addScript(scripts, type, script) {
@@ -209,15 +212,3 @@ module.exports = {
209212
}
210213
},
211214
};
212-
213-
const packagePath = (project) => `${project.root}/package.json`;
214-
215-
function readPackage(project) {
216-
const path = packagePath(project)
217-
218-
return JSON.parse(fs.readFileSync(path, 'utf-8'));
219-
}
220-
221-
function writePackage(project, pkg) {
222-
fs.writeFileSync(packagePath(project), JSON.stringify(pkg, null, 2) + '\n');
223-
}

0 commit comments

Comments
 (0)