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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: modelSettings is stringified properly #2915 #3015

Merged
merged 1 commit into from May 31, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/cli/generators/discover/index.js
Expand Up @@ -219,9 +219,12 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
modelDefinition.isModelBaseBuiltin = true;
modelDefinition.modelBaseClass = 'Entity';
modelDefinition.className = utils.pascalCase(modelDefinition.name);
// These last two are so that the templat doesn't error out of they aren't there
// These last two are so that the template doesn't error out of they aren't there
modelDefinition.allowAdditionalProperties = true;
modelDefinition.modelSettings = modelDefinition.settings || {};
// modelDefinition.modelSettings = modelDefinition.settings || {};
modelDefinition.modelSettings = utils.stringifyModelSettings(
modelDefinition.settings || {},
);
debug(`Generating: ${modelDefinition.name}`);

const fullPath = path.resolve(
Expand Down
10 changes: 2 additions & 8 deletions packages/cli/generators/model/index.js
Expand Up @@ -14,7 +14,6 @@ const inspect = require('util').inspect;
const utils = require('../../lib/utils');
const chalk = require('chalk');
const path = require('path');
const stringifyObject = require('stringify-object');

const PROMPT_BASE_MODEL_CLASS = 'Please select the model base class';
const ERROR_NO_MODELS_FOUND = 'Model was not found in';
Expand Down Expand Up @@ -515,13 +514,8 @@ module.exports = class ModelGenerator extends ArtifactGenerator {
});

if (this.artifactInfo.modelSettings) {
this.artifactInfo.modelSettings = stringifyObject(
{settings: this.artifactInfo.modelSettings},
{
indent: ' ', // two spaces
singleQuotes: true,
inlineCharacterLimit: 80,
},
this.artifactInfo.modelSettings = utils.stringifyModelSettings(
this.artifactInfo.modelSettings,
);
}

Expand Down
12 changes: 12 additions & 0 deletions packages/cli/lib/utils.js
Expand Up @@ -23,6 +23,7 @@ const urlSlug = require('url-slug');
const validate = require('validate-npm-package-name');
const Conflicter = require('yeoman-generator/lib/util/conflicter');
const connectors = require('../generators/datasource/connectors.json');
const stringifyObject = require('stringify-object');

const readdirAsync = promisify(fs.readdir);

Expand Down Expand Up @@ -518,6 +519,17 @@ exports.dataSourceToJSONFileName = function(dataSourceClass) {
);
};

exports.stringifyModelSettings = function(modelSettings) {
return stringifyObject(
{settings: modelSettings},
{
indent: ' ', // two spaces
singleQuotes: true,
inlineCharacterLimit: 80,
},
);
};

// literal strings with artifacts directory locations
exports.repositoriesDir = 'repositories';
exports.datasourcesDir = 'datasources';
Expand Down