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

Add Preliminary Support For Javascript-based Configs #1000

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/bin/resolve-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
122 changes: 122 additions & 0 deletions packages/core/patternlab-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
const resolvePkg = require('resolve-pkg');

module.exports = {
engines: {
twig: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

twig engine should not be in core?

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: [],
},
],
};
95 changes: 0 additions & 95 deletions packages/core/patternlab-config.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/loaduikits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/lib/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just do this instead and then either .json or .js (or even patternlab-config/index.js) would work? Backwards compatible so previous installs do not error if they have .json and might even help with some of the other problems you've mentioned.

- require(path.resolve(__dirname, '../../patternlab-config.js'))
+ require(path.resolve(__dirname, '../../patternlab-config'))


//register our log events
this.registerLogger(config.logLevel);
Expand Down
7 changes: 4 additions & 3 deletions packages/edition-twig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading