const _ = require('lodash'); const oneLineTrim = require('common-tags/lib/oneLineTrim'); const previousSpec = require('./v2'); const ghostVersions = require('../utils').versions; const docsBaseUrl = `https://ghost.org/docs/themes/`; // TODO: we don't use versioned docs anymore and the previous rules should only contain // correct links. The usage of replacing the previousBaseUrl can probably be removed const prevDocsBaseUrl = `https://themes.ghost.org/v${ghostVersions.v2.docs}/docs/`; const prevDocsBaseUrlRegEx = new RegExp(prevDocsBaseUrl, 'g'); const previousKnownHelpers = previousSpec.knownHelpers; const previousTemplates = previousSpec.templates; const previousRules = previousSpec.rules; // assign new or overwrite existing knownHelpers, templates, or rules here: let knownHelpers = ['cancel_link', 'price']; let templates = []; let rules = { // New rules 'GS010-PJ-GHOST-API': { level: 'warning', rule: 'package.json property "engines.ghost-api" is recommended. Otherwise, it falls back to "v3"', details: oneLineTrim`Please add "ghost-api" to your package.json. E.g. {"engines": {"ghost-api": "v3"}}.
If no "ghost-api" property is provided, Ghost will use its default setting of "v3" Ghost API.
Check the package.json documentation for further information.` }, 'GS010-PJ-GHOST-API-V01': { level: 'error', rule: 'package.json property "engines.ghost-api" is incompatible with current version of Ghost API and will fall back to "v3"', details: oneLineTrim`Please change "ghost-api" in your package.json to higher version. E.g. {"engines": {"ghost-api": "v3"}}.
If "ghost-api" property is left at "v0.1", Ghost will use its default setting of "v3".
Check the package.json documentation for further information.` }, 'GS001-DEPR-ESC': { level: 'error', rule: 'Replace {{error.code}} with {{error.statusCode}}', details: oneLineTrim`The usage of {{error.code}} is deprecated and should be replaced with {{error.statusCode}}.
When in error context, e. g. in the error.hbs template, replace {{code}} with {{statusCode}}.
Find more information about the error.hbs template here.`, regex: /{{\s*?(?:error\.)?(code)\s*?}}/g, helper: '{{error.code}}' }, 'GS060-JS-GUA': { level: 'error', rule: 'The v0.1 API and ghost.url.api() JavaScript helper have been removed.', details: oneLineTrim`The v0.1 API & Public API Beta have been removed, along with the public/ghost-sdk.min.js file & the ghost.url.api() helper.
All code relying on the v0.1 API must be upgraded to use the new API.`, regex: /ghost\.url\.api/g }, 'GS070-VALID-TRANSLATIONS': { level: 'error', rule: 'Theme translations must be parsable', fatal: false, details: oneLineTrim`Theme translations (located in locales/*.json) need to be readable by the node JSON parser, or they will not be applied.` } }; knownHelpers = _.union(previousKnownHelpers, knownHelpers); templates = _.union(previousTemplates, templates); // Merge the previous rules into the new rules, but overwrite any specified property, // as well as adding any new rule to the spec. // Furthermore, replace the usage of the old doc URLs that we're linking to, with the // new version. rules = _.each(_.merge({}, previousRules, rules), function replaceDocsUrl(value) { value.details = value.details.replace(prevDocsBaseUrlRegEx, docsBaseUrl); }); module.exports = { knownHelpers: knownHelpers, templates: templates, rules: rules, defaultPackageJSON: previousSpec.defaultPackageJSON };