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

issue/2721 Fixed component schema naming #2722

Merged
merged 2 commits into from Apr 24, 2020
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
10 changes: 6 additions & 4 deletions grunt/helpers/Schemas.js
Expand Up @@ -63,15 +63,17 @@ class Schemas {
* @param {string} filePath
*/
const createSchema = (plugin, filePath) => {
const inferredSchemaName = (plugin.name === 'core') ?
path.parse(filePath).name.split('.')[0] : // if core, get schema name from file name
plugin.name; // assume schema name is plugin name

const json = fs.readJSONSync(filePath);
const isExtensionSchema = Boolean(json.properties.pluginLocations);
const InferredSchemaClass = (isExtensionSchema ? ExtensionSchema : ModelSchema);
const inferredSchemaName = (plugin.name === 'core') ?
path.parse(filePath).name.split('.')[0] : // if core, get schema name from file name
isExtensionSchema ?
plugin.name : // assume schema name is plugin name
plugin.targetAttribute; // assume schema name is plugin._[type] value
return new InferredSchemaClass({
name: inferredSchemaName,
plugin,
framework: this.framework,
filePath,
globalsType: plugin.type,
Expand Down
7 changes: 5 additions & 2 deletions grunt/helpers/schema/GlobalsSchema.js
Expand Up @@ -2,6 +2,7 @@ const Schema = require('./Schema');

/**
* @typedef {import('./Framework')} Framework
* @typedef {import('../plugins/Plugin')} Plugin
*/

/**
Expand All @@ -15,6 +16,7 @@ class GlobalsSchema extends Schema {
* @param {Object} options
* @param {Framework} options.framework
* @param {string} options.name
* @param {Plugin} options.plugin
* @param {Object} options.json
* @param {string} options.filePath
* @param {string} options.globalsType
Expand All @@ -23,14 +25,15 @@ class GlobalsSchema extends Schema {
constructor({
framework = null,
name = '',
plugin = null,
json = {},
filePath = '',
globalsType = '',
targetAttribute = ''
} = {}) {
super({ framework, name, json, filePath, globalsType });
super({ framework, name, plugin, json, filePath, globalsType });
// Add an underscore to the front of the targetAttribute if necessary
this.targetAttribute = (targetAttribute[0] !== '_' ? '_' : '') + targetAttribute;
this.targetAttribute = (targetAttribute && targetAttribute[0] !== '_' ? '_' : '') + targetAttribute;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions grunt/helpers/schema/Schema.js
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs-extra');
/**
* @typedef {import('./Framework')} Framework
* @typedef {import('./JSONFileItem')} JSONFileItem
* @typedef {import('../plugins/Plugin')} Plugin
*/

class Schema {
Expand All @@ -12,19 +13,23 @@ class Schema {
* @param {Object} options
* @param {Framework} options.framework
* @param {string} options.name
* @param {Plugin} options.plugin
* @param {Object} options.json
* @param {string} options.filePath
* @param {string} options.globalsType
*/
constructor({
framework = null,
name = '',
plugin = null,
json = null,
filePath = '',
globalsType = ''
} = {}) {
/** @type {Framework} */
this.framework = framework;
/** @type {Plugin} */
this.plugin = plugin;
/** @type {string} */
this.name = name;
/** @type {Object} */
Expand Down