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 4 commits
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 .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"es6": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 2017,
"sourceType": "module"
},
"globals": {},
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/bin/resolve-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const path = require('path');
const error = require('./utils').error;
const readJsonAsync = require('./utils').readJsonAsync;
const wrapAsync = require('./utils').wrapAsync;
const {
findPatternLabConfig,
} = require('@pattern-lab/core/src/lib/utils/find-config-file');

/**
* @func resolveConfig
Expand All @@ -30,8 +33,12 @@ function resolveConfig(configPath) {
* 2. Read the config file
*/
try {
const absoluteConfigPath = path.resolve(configPath); // 1
return yield readJsonAsync(absoluteConfigPath); // 2
if (configPath) {
const absoluteConfigPath = path.resolve(configPath); // 1
return yield findPatternLabConfig(absoluteConfigPath);
} else {
return yield findPatternLabConfig();
}
} catch (err) {
error(
'resolveConfig: Got an error during parsing your Pattern Lab config. Please make sure your config file exists.'
Expand Down
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "3.0.1-alpha.0",
"main": "./src/index.js",
"dependencies": {
"cosmiconfig": "^5.2.0",
"@pattern-lab/engine-mustache": "^2.0.1-alpha.0",
"@pattern-lab/live-server": "^1.3.3-beta.1",
"chalk": "1.1.3",
Expand All @@ -21,6 +22,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
22 changes: 12 additions & 10 deletions packages/core/src/lib/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const dive = require('dive');
const _ = require('lodash');
const path = require('path');
const cleanHtml = require('js-beautify').html;

const inherits = require('util').inherits;
const pm = require('./plugin_manager');
const plugin_manager = new pm();
Expand All @@ -16,7 +15,7 @@ const loaduikits = require('./loaduikits');
const logger = require('./log');
const processIterative = require('./processIterative');
const processRecursive = require('./processRecursive');

const { findPatternLabConfig } = require('./utils/find-config-file');
const loadPattern = require('./loadPattern');
const sm = require('./starterkit_manager');

Expand All @@ -32,21 +31,22 @@ function PatternLabEventEmitter() {
}
inherits(PatternLabEventEmitter, EventEmitter);

module.exports = class PatternLab {
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'));
// Use the already-resolved config passed in OR auto load one up from the config
const getConfigAsync = async () => {
this.config = config || (await Promise.resolve(findPatternLabConfig()));
};
getConfigAsync();

//register our log events
this.registerLogger(config.logLevel);
this.registerLogger(this.config.logLevel);

logger.info(`Pattern Lab Node v${packageInfo.version}`);

// Load up engines please
this.engines = patternEngines;
this.engines.loadAllEngines(config);
this.engines.loadAllEngines(this.config);

//
// INITIALIZE EMPTY GLOBAL DATA STRUCTURES
Expand Down Expand Up @@ -362,4 +362,6 @@ module.exports = class PatternLab {
});
return promiseAllPatternFiles;
}
};
}

module.exports = PatternLab;
Loading