MCPcopy Index your code
hub / github.com/ember-cli/ember-cli / toJSON

Method toJSON

tests/helpers/fixturify-project.js:353–395  ·  view source on GitHub ↗

* Convert the object into a data structure suitable for passing to `fixturify`. * * @param {String} key optional key. If specified, the object will be run through toJSON, then the given * property extracted and returned. * @returns {Object} the `toJSON` value of the object (wrapped) or t

(key)

Source from the content-addressed store, hash-verified

351 * (not wrapped.)
352 */
353 toJSON(key) {
354 if (key) {
355 return super.toJSON(key);
356 }
357
358 let jsonData = super.toJSON();
359
360 let scoped = parseScoped(this.name);
361
362 // Allowing for scoped names, get the object in the JSON structure that corresponds
363 // to this FixturifyProject.
364 let container = scoped ? jsonData[scoped.scope][scoped.name] : jsonData[this.name];
365
366 if (this._referenceDependencies || this._referenceDevDependencies) {
367 let pkg = JSON.parse(container['package.json']);
368
369 if (this._referenceDependencies) {
370 if (!pkg.dependencies) {
371 pkg.dependencies = {};
372 }
373
374 Object.assign(pkg.dependencies, this._referenceDependencies);
375 }
376
377 if (this._referenceDevDependencies) {
378 if (!pkg.devDependencies) {
379 pkg.devDependencies = {};
380 }
381
382 Object.assign(pkg.devDependencies, this._referenceDevDependencies);
383 }
384
385 container['package.json'] = JSON.stringify(pkg, undefined, 2);
386 }
387
388 // an optimization to remove any node_modules declaration that has nothing in it,
389 // to avoid creating extra directories for no reason.
390 if (container['node_modules'] && Object.keys(container['node_modules']).length === 0) {
391 delete container['node_modules'];
392 }
393
394 return jsonData;
395 }
396};

Callers 4

buildProjectModelMethod · 0.95
addInRepoAddonMethod · 0.95
_writeInstrumentationMethod · 0.80
assertTreeValidJSONFunction · 0.80

Calls 1

parseScopedFunction · 0.85

Tested by

no test coverage detected