diff --git a/packages/cli/bin/resolve-config.js b/packages/cli/bin/resolve-config.js index f34c5e083..e68a1afaa 100644 --- a/packages/cli/bin/resolve-config.js +++ b/packages/cli/bin/resolve-config.js @@ -31,7 +31,7 @@ function resolveConfig(configPath) { */ try { const absoluteConfigPath = path.resolve(configPath); // 1 - return yield readJsonAsync(absoluteConfigPath); // 2 + return yield require(absoluteConfigPath); } catch (err) { error( 'resolveConfig: Got an error during parsing your Pattern Lab config. Please make sure your config file exists.' diff --git a/packages/core/package.json b/packages/core/package.json index 38ea422ac..5819bbd02 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -21,6 +21,7 @@ "update-notifier": "2.2.0" }, "devDependencies": { + "resolve-pkg": "^1.0.0", "eslint": "4.18.2", "eslint-config-prettier": "2.9.0", "eslint-plugin-prettier": "2.6.0", diff --git a/packages/core/patternlab-config.js b/packages/core/patternlab-config.js new file mode 100644 index 000000000..a82d5c5b2 --- /dev/null +++ b/packages/core/patternlab-config.js @@ -0,0 +1,122 @@ +const resolvePkg = require('resolve-pkg'); + +module.exports = { + engines: { + twig: { + namespaces: [ + { + id: 'uikit', + recursive: true, + paths: [resolvePkg(`@pattern-lab/uikit-workshop/views-twig`)], + }, + { + id: 'atoms', + recursive: true, + paths: ['source/_patterns/00-atoms'], + }, + { + id: 'molecules', + recursive: true, + paths: ['source/_patterns/01-molecules'], + }, + ], + alterTwigEnv: [ + { + file: 'alter-twig.php', + functions: ['addCustomExtension'], + }, + ], + }, + }, + cacheBust: true, + cleanPublic: true, + defaultPattern: 'all', + defaultShowPatternInfo: false, + ishControlsHide: { + s: false, + m: false, + l: false, + full: false, + random: false, + disco: false, + hay: true, + mqs: false, + find: false, + 'views-all': false, + 'views-annotations': false, + 'views-code': false, + 'views-new': false, + 'tools-all': false, + 'tools-docs': false, + }, + ishViewportRange: { + s: [240, 500], + m: [500, 800], + l: [800, 2600], + }, + logLevel: 'info', + outputFileSuffixes: { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only', + }, + paths: { + source: { + root: './source/', + patterns: './source/_patterns/', + data: './source/_data/', + meta: './source/_meta/', + annotations: './source/_annotations/', + styleguide: 'dist/', + patternlabFiles: { + 'general-header': + '../uikit-workshop/views/partials/general-header.mustache', + 'general-footer': + '../uikit-workshop/views/partials/general-footer.mustache', + patternSection: + '../uikit-workshop/views/partials/patternSection.mustache', + patternSectionSubtype: + '../uikit-workshop/views/partials/patternSectionSubtype.mustache', + viewall: '../uikit-workshop/views/viewall.mustache', + }, + js: './source/js', + images: './source/images', + fonts: './source/fonts', + css: './source/css', + }, + public: { + root: 'public/', + patterns: 'public/patterns/', + data: 'public/styleguide/data/', + annotations: 'public/annotations/', + styleguide: 'public/styleguide/', + js: 'public/js', + images: 'public/images', + fonts: 'public/fonts', + css: 'public/css', + }, + }, + patternExtension: 'twig', + patternStateCascade: ['inprogress', 'inreview', 'complete'], + patternExportDirectory: './pattern_exports/', + patternExportPatternPartials: [], + serverOptions: { + wait: 1000, + }, + starterkitSubDir: 'dist', + styleGuideExcludes: [], + theme: { + color: 'light', + density: 'compact', + layout: 'horizontal', + }, + uikits: [ + { + name: 'uikit-workshop', + outputDir: '', + enabled: true, + excludedPatternStates: [], + excludedTags: [], + }, + ], +}; diff --git a/packages/core/patternlab-config.json b/packages/core/patternlab-config.json deleted file mode 100644 index 80669ea5f..000000000 --- a/packages/core/patternlab-config.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "cacheBust": true, - "cleanPublic" : true, - "defaultPattern": "all", - "defaultShowPatternInfo": false, - "ishControlsHide": { - "s": false, - "m": false, - "l": false, - "full": false, - "random": false, - "disco": false, - "hay": true, - "mqs": false, - "find": false, - "views-all": false, - "views-annotations": false, - "views-code": false, - "views-new": false, - "tools-all": false, - "tools-docs": false - }, - "ishViewportRange": { - "s": [240, 500], - "m": [500, 800], - "l": [800, 2600] - }, - "logLevel": "info", - "outputFileSuffixes": { - "rendered": ".rendered", - "rawTemplate": "", - "markupOnly": ".markup-only" - }, - "paths" : { - "source": { - "root": "./source/", - "patterns": "./source/_patterns/", - "data": "./source/_data/", - "meta": "./source/_meta/", - "annotations": "./source/_annotations/", - "styleguide": "dist/", - "patternlabFiles": { - "general-header": - "views/partials/general-header.mustache", - "general-footer": - "views/partials/general-footer.mustache", - "patternSection": - "views/partials/patternSection.mustache", - "patternSectionSubtype": - "views/partials/patternSectionSubtype.mustache", - "viewall": - "views/viewall.mustache" - }, - "js": "./source/js", - "images": "./source/images", - "fonts": "./source/fonts", - "css": "./source/css" - }, - "public": { - "root": "public/", - "patterns": "public/patterns/", - "data": "public/styleguide/data/", - "annotations": "public/annotations/", - "styleguide": "public/styleguide/", - "js": "public/js", - "images": "public/images", - "fonts": "public/fonts", - "css": "public/css" - } - }, - "patternExtension": "mustache", - "patternStateCascade": ["inprogress", "inreview", "complete"], - "patternExportDirectory": "./pattern_exports/", - "patternExportPatternPartials": [], - "serverOptions": { - "wait": 1000 - }, - "starterkitSubDir": "dist", - "styleGuideExcludes": [ - ], - "theme": { - "color": "dark", - "density": "compact", - "layout": "horizontal" - }, - "uikits": [ - { - "name": "uikit-workshop", - "outputDir": "", - "enabled": true, - "excludedPatternStates": [], - "excludedTags": [] - } - ] -} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 653a9f731..615ff5c29 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -19,7 +19,7 @@ const events = require('./lib/events'); const pe = require('./lib/pattern_exporter'); const pm = require('./lib/plugin_manager'); -const defaultConfig = require('../patternlab-config.json'); +const defaultConfig = require('../patternlab-config.js'); let buildPatterns = require('./lib/buildPatterns'); // eslint-disable-line let logger = require('./lib/log'); // eslint-disable-line diff --git a/packages/core/src/lib/loaduikits.js b/packages/core/src/lib/loaduikits.js index 1f97564a2..7ac215118 100644 --- a/packages/core/src/lib/loaduikits.js +++ b/packages/core/src/lib/loaduikits.js @@ -37,7 +37,7 @@ const readModuleFile = (kit, subPath) => { /** * Loads uikits, connecting configuration and installed modules * [1] Looks in node_modules for uikits. - * [2] Only continue if uikit is enabled in patternlab-config.json + * [2] Only continue if uikit is enabled in patternlab-config.js * [3] Reads files from uikit that apply to every template * @param {object} patternlab */ @@ -55,7 +55,7 @@ module.exports = patternlab => { logger.warning( `Could not find uikit with name uikit-${ kit.name - } defined within patternlab-config.json, or it is not enabled.` + } defined within a patternlab-config.js file, or it is not enabled.` ); return; } diff --git a/packages/core/src/lib/patternlab.js b/packages/core/src/lib/patternlab.js index 2b8cc3d43..50dbda15f 100644 --- a/packages/core/src/lib/patternlab.js +++ b/packages/core/src/lib/patternlab.js @@ -36,8 +36,7 @@ module.exports = class PatternLab { constructor(config) { // Either use the config we were passed, or load one up from the config file ourselves this.config = - config || - fs.readJSONSync(path.resolve(__dirname, '../../patternlab-config.json')); + config || require(path.resolve(__dirname, '../../patternlab-config.js')); //register our log events this.registerLogger(config.logLevel); diff --git a/packages/edition-twig/package.json b/packages/edition-twig/package.json index 43c23c1f0..010c6a96c 100644 --- a/packages/edition-twig/package.json +++ b/packages/edition-twig/package.json @@ -13,14 +13,15 @@ ], "main": "patternlab-config.json", "scripts": { - "build": "patternlab build --config ./patternlab-config.json", + "build": "patternlab build --config ./patternlab-config.js", "help": "patternlab --help", - "install": "patternlab install --config ./patternlab-config.json", - "serve": "patternlab serve --config ./patternlab-config.json", + "install": "patternlab install --config ./patternlab-config.js", + "serve": "patternlab serve --config ./patternlab-config.js", "start": "npm run serve", "version": "patternlab --version" }, "dependencies": { + "resolve-pkg": "^1.0.0", "@pattern-lab/cli": "^0.0.2-alpha.0", "@pattern-lab/core": "^3.0.1-alpha.0", "@pattern-lab/engine-twig-php": "^3.0.0", diff --git a/packages/edition-twig/patternlab-config.default.js b/packages/edition-twig/patternlab-config.default.js new file mode 100644 index 000000000..a82d5c5b2 --- /dev/null +++ b/packages/edition-twig/patternlab-config.default.js @@ -0,0 +1,122 @@ +const resolvePkg = require('resolve-pkg'); + +module.exports = { + engines: { + twig: { + namespaces: [ + { + id: 'uikit', + recursive: true, + paths: [resolvePkg(`@pattern-lab/uikit-workshop/views-twig`)], + }, + { + id: 'atoms', + recursive: true, + paths: ['source/_patterns/00-atoms'], + }, + { + id: 'molecules', + recursive: true, + paths: ['source/_patterns/01-molecules'], + }, + ], + alterTwigEnv: [ + { + file: 'alter-twig.php', + functions: ['addCustomExtension'], + }, + ], + }, + }, + cacheBust: true, + cleanPublic: true, + defaultPattern: 'all', + defaultShowPatternInfo: false, + ishControlsHide: { + s: false, + m: false, + l: false, + full: false, + random: false, + disco: false, + hay: true, + mqs: false, + find: false, + 'views-all': false, + 'views-annotations': false, + 'views-code': false, + 'views-new': false, + 'tools-all': false, + 'tools-docs': false, + }, + ishViewportRange: { + s: [240, 500], + m: [500, 800], + l: [800, 2600], + }, + logLevel: 'info', + outputFileSuffixes: { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only', + }, + paths: { + source: { + root: './source/', + patterns: './source/_patterns/', + data: './source/_data/', + meta: './source/_meta/', + annotations: './source/_annotations/', + styleguide: 'dist/', + patternlabFiles: { + 'general-header': + '../uikit-workshop/views/partials/general-header.mustache', + 'general-footer': + '../uikit-workshop/views/partials/general-footer.mustache', + patternSection: + '../uikit-workshop/views/partials/patternSection.mustache', + patternSectionSubtype: + '../uikit-workshop/views/partials/patternSectionSubtype.mustache', + viewall: '../uikit-workshop/views/viewall.mustache', + }, + js: './source/js', + images: './source/images', + fonts: './source/fonts', + css: './source/css', + }, + public: { + root: 'public/', + patterns: 'public/patterns/', + data: 'public/styleguide/data/', + annotations: 'public/annotations/', + styleguide: 'public/styleguide/', + js: 'public/js', + images: 'public/images', + fonts: 'public/fonts', + css: 'public/css', + }, + }, + patternExtension: 'twig', + patternStateCascade: ['inprogress', 'inreview', 'complete'], + patternExportDirectory: './pattern_exports/', + patternExportPatternPartials: [], + serverOptions: { + wait: 1000, + }, + starterkitSubDir: 'dist', + styleGuideExcludes: [], + theme: { + color: 'light', + density: 'compact', + layout: 'horizontal', + }, + uikits: [ + { + name: 'uikit-workshop', + outputDir: '', + enabled: true, + excludedPatternStates: [], + excludedTags: [], + }, + ], +}; diff --git a/packages/edition-twig/patternlab-config.js b/packages/edition-twig/patternlab-config.js new file mode 100644 index 000000000..a82d5c5b2 --- /dev/null +++ b/packages/edition-twig/patternlab-config.js @@ -0,0 +1,122 @@ +const resolvePkg = require('resolve-pkg'); + +module.exports = { + engines: { + twig: { + namespaces: [ + { + id: 'uikit', + recursive: true, + paths: [resolvePkg(`@pattern-lab/uikit-workshop/views-twig`)], + }, + { + id: 'atoms', + recursive: true, + paths: ['source/_patterns/00-atoms'], + }, + { + id: 'molecules', + recursive: true, + paths: ['source/_patterns/01-molecules'], + }, + ], + alterTwigEnv: [ + { + file: 'alter-twig.php', + functions: ['addCustomExtension'], + }, + ], + }, + }, + cacheBust: true, + cleanPublic: true, + defaultPattern: 'all', + defaultShowPatternInfo: false, + ishControlsHide: { + s: false, + m: false, + l: false, + full: false, + random: false, + disco: false, + hay: true, + mqs: false, + find: false, + 'views-all': false, + 'views-annotations': false, + 'views-code': false, + 'views-new': false, + 'tools-all': false, + 'tools-docs': false, + }, + ishViewportRange: { + s: [240, 500], + m: [500, 800], + l: [800, 2600], + }, + logLevel: 'info', + outputFileSuffixes: { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only', + }, + paths: { + source: { + root: './source/', + patterns: './source/_patterns/', + data: './source/_data/', + meta: './source/_meta/', + annotations: './source/_annotations/', + styleguide: 'dist/', + patternlabFiles: { + 'general-header': + '../uikit-workshop/views/partials/general-header.mustache', + 'general-footer': + '../uikit-workshop/views/partials/general-footer.mustache', + patternSection: + '../uikit-workshop/views/partials/patternSection.mustache', + patternSectionSubtype: + '../uikit-workshop/views/partials/patternSectionSubtype.mustache', + viewall: '../uikit-workshop/views/viewall.mustache', + }, + js: './source/js', + images: './source/images', + fonts: './source/fonts', + css: './source/css', + }, + public: { + root: 'public/', + patterns: 'public/patterns/', + data: 'public/styleguide/data/', + annotations: 'public/annotations/', + styleguide: 'public/styleguide/', + js: 'public/js', + images: 'public/images', + fonts: 'public/fonts', + css: 'public/css', + }, + }, + patternExtension: 'twig', + patternStateCascade: ['inprogress', 'inreview', 'complete'], + patternExportDirectory: './pattern_exports/', + patternExportPatternPartials: [], + serverOptions: { + wait: 1000, + }, + starterkitSubDir: 'dist', + styleGuideExcludes: [], + theme: { + color: 'light', + density: 'compact', + layout: 'horizontal', + }, + uikits: [ + { + name: 'uikit-workshop', + outputDir: '', + enabled: true, + excludedPatternStates: [], + excludedTags: [], + }, + ], +}; diff --git a/packages/edition-twig/patternlab-config.json b/packages/edition-twig/patternlab-config.json deleted file mode 100644 index 8612b1633..000000000 --- a/packages/edition-twig/patternlab-config.json +++ /dev/null @@ -1,137 +0,0 @@ -{ - "engines": { - "twig": { - "namespaces": [ - { - "id": "uikit", - "recursive": true, - "paths": [ - "../uikit-workshop/views-twig" - ] - }, - { - "id": "atoms", - "recursive": true, - "paths": [ - "source/_patterns/00-atoms" - ] - }, - { - "id": "molecules", - "recursive": true, - "paths": [ - "source/_patterns/01-molecules" - ] - } - ], - "alterTwigEnv": [ - { - "file": "alter-twig.php", - "functions": [ - "addCustomExtension" - ] - } - ] - } - }, - "cacheBust": true, - "cleanPublic": true, - "defaultPattern": "all", - "defaultShowPatternInfo": false, - "ishControlsHide": { - "s": false, - "m": false, - "l": false, - "full": false, - "random": false, - "disco": false, - "hay": true, - "mqs": false, - "find": false, - "views-all": false, - "views-annotations": false, - "views-code": false, - "views-new": false, - "tools-all": false, - "tools-docs": false - }, - "ishViewportRange": { - "s": [ - 240, - 500 - ], - "m": [ - 500, - 800 - ], - "l": [ - 800, - 2600 - ] - }, - "logLevel": "info", - "outputFileSuffixes": { - "rendered": ".rendered", - "rawTemplate": "", - "markupOnly": ".markup-only" - }, - "paths": { - "source": { - "root": "./source/", - "patterns": "./source/_patterns/", - "data": "./source/_data/", - "meta": "./source/_meta/", - "annotations": "./source/_annotations/", - "styleguide": "dist/", - "patternlabFiles": { - "general-header": "../uikit-workshop/views/partials/general-header.mustache", - "general-footer": "../uikit-workshop/views/partials/general-footer.mustache", - "patternSection": "../uikit-workshop/views/partials/patternSection.mustache", - "patternSectionSubtype": "../uikit-workshop/views/partials/patternSectionSubtype.mustache", - "viewall": "../uikit-workshop/views/viewall.mustache" - }, - "js": "./source/js", - "images": "./source/images", - "fonts": "./source/fonts", - "css": "./source/css" - }, - "public": { - "root": "public/", - "patterns": "public/patterns/", - "data": "public/styleguide/data/", - "annotations": "public/annotations/", - "styleguide": "public/styleguide/", - "js": "public/js", - "images": "public/images", - "fonts": "public/fonts", - "css": "public/css" - } - }, - "patternExtension": "twig", - "patternStateCascade": [ - "inprogress", - "inreview", - "complete" - ], - "patternExportDirectory": "./pattern_exports/", - "patternExportPatternPartials": [], - "serverOptions": { - "wait": 1000 - }, - "starterkitSubDir": "dist", - "styleGuideExcludes": [], - "theme": { - "color": "light", - "density": "compact", - "layout": "horizontal" - }, - "uikits": [ - { - "name": "uikit-workshop", - "outputDir": "", - "enabled": true, - "excludedPatternStates": [], - "excludedTags": [] - } - ] -}