Skip to content

Commit

Permalink
Merge branch 'dev' into refactor/further-code-optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mfranzke committed Nov 30, 2021
2 parents 12f0b4e + fe92f4b commit 8bbd83d
Show file tree
Hide file tree
Showing 68 changed files with 375 additions and 395 deletions.
3 changes: 2 additions & 1 deletion packages/cli/bin/inquiries/starterkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const starterkitSetup = [
message: 'What initial patterns do you want included in your project?',
choices: [
{
name: 'Handlebars base patterns (some basic patterns to get started with)',
name:
'Handlebars base patterns (some basic patterns to get started with)',
value: '@pattern-lab/starterkit-handlebars-vanilla',
},
{
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/bin/scaffold.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const path = require('path');
const execa = require('execa');
const fs = require('fs-extra');
const fs = require('fs');
const wrapAsync = require('./utils').wrapAsync;
const mkdirsAsync = require('./utils').mkdirsAsync;

Expand All @@ -18,7 +18,6 @@ const scaffold = (projectDir, sourceDir, publicDir, exportDir) =>
wrapAsync(function* () {
const projectPath = path.join(process.cwd(), projectDir);
if (!fs.existsSync(path.join(projectPath, 'package.json'))) {
fs.ensureDirSync(projectPath);
execa.sync('npm', ['init', '-y'], {
cwd: projectPath,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
],
"scripts": {
"lint": "eslint ./{bin,test}",
"test:separate": "tap ./test/*.test.js --reporter spec --timeout=120"
"test:separate": "tap './test/*.test.js' --reporter spec --timeout=120"
},
"repository": "https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli",
"bugs": "https://github.com/pattern-lab/patternlab-node/issues",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/addPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const logger = require('./log');

module.exports = function (pattern, patternlab) {
module.exports = function(pattern, patternlab) {
//add the link to the global object
if (!patternlab.data.link) {
patternlab.data.link = {};
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/lib/annotation_exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const _ = require('lodash');
const mp = require('./markdown_parser');
const logger = require('./log');

const annotations_exporter = function (pl) {
const annotations_exporter = function(pl) {
const paths = pl.config.paths;
let oldAnnotations;

Expand Down Expand Up @@ -68,7 +68,7 @@ const annotations_exporter = function (pl) {
//let annotations = annotations;
const markdown_parser = parser;

return function (filePath) {
return function(filePath) {
const annotationsMD = fs.readFileSync(path.resolve(filePath), 'utf8');

//take the annotation snippets and split them on our custom delimiter
Expand Down Expand Up @@ -110,15 +110,15 @@ const annotations_exporter = function (pl) {
}

return {
gather: function () {
gather: function() {
return gatherAnnotations();
},
gatherJS: function () {
gatherJS: function() {
return parseAnnotationsJS();
},
gatherMD: function () {
gatherMD: function() {
return parseAnnotationsMD();
},
}
};
};

Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/lib/buildFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ let render = require('./render'); //eslint-disable-line prefer-const
* @param patternPartial - the partial key to build this for, either viewall-patternPartial or a viewall-patternGroup-all
* @returns A promise which resolves with the HTML
*/
module.exports = function (patternlab, patternPartial, uikit) {
module.exports = function(patternlab, patternPartial, uikit) {
//first render the general footer
return render(Pattern.createEmpty({ extendedTemplate: uikit.footer }), {
patternData: JSON.stringify({
patternPartial: patternPartial,
patternPartial: patternPartial
}),
cacheBuster: patternlab.cacheBuster,
cacheBuster: patternlab.cacheBuster
})
.then((footerPartial) => {
.then(footerPartial => {
let allFooterData;
try {
allFooterData = jsonCopy(
Expand All @@ -36,7 +36,7 @@ module.exports = function (patternlab, patternPartial, uikit) {

return render(patternlab.userFoot, allFooterData);
})
.catch((reason) => {
.catch(reason => {
console.log(reason);
logger.error('Error building buildFooterHTML');
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/buildListItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ const items = [
'seventeen',
'eighteen',
'nineteen',
'twenty',
'twenty'
];

module.exports = function (container) {
module.exports = function(container) {
//combine all list items into one structure
const list = [];
for (const item in container.listitems) {
Expand Down
28 changes: 14 additions & 14 deletions packages/core/src/lib/buildPatterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ module.exports = async (deletePatternDir, patternlab, additionalData) => {
return render(
Pattern.createEmpty({
// todo should this be uikit.header?
extendedTemplate: patternlab.header,
extendedTemplate: patternlab.header
}),
{
cacheBuster: patternlab.cacheBuster,
cacheBuster: patternlab.cacheBuster
}
)
.then((results) => {
.then(results => {
patternlab.data.patternLabHead = results;

// If deletePatternDir == true or graph needs to be updated
Expand All @@ -133,7 +133,7 @@ module.exports = async (deletePatternDir, patternlab, additionalData) => {
if (patternlab.incrementalBuildsEnabled) {
// When the graph was loaded from file, some patterns might have been moved/deleted between runs
// so the graph data become out of sync
patternlab.graph.sync().forEach((n) => {
patternlab.graph.sync().forEach(n => {
logger.info('[Deleted/Moved] ' + n);
});

Expand All @@ -150,18 +150,18 @@ module.exports = async (deletePatternDir, patternlab, additionalData) => {
}
//render all patterns last, so lineageR works
const allPatternsPromise = patternsToBuild.map(
async (pattern) => await compose(pattern, patternlab)
async pattern => await compose(pattern, patternlab)
);
//copy non-pattern files like JavaScript
const allJS = patternsToBuild.map((pattern) => {
const allJS = patternsToBuild.map(pattern => {
const { name, patternPartial, subdir } = pattern;
const {
source: { patterns: sourceDir },
public: { patterns: publicDir },
public: { patterns: publicDir }
} = patternlab.config.paths;
const src = path.join(sourceDir, subdir);
const dest = path.join(publicDir, name);
return map(patternlab.uikits, (uikit) => {
return map(patternlab.uikits, uikit => {
return copy(
src,
path.resolve(process.cwd(), uikit.outputDir, dest),
Expand All @@ -170,7 +170,7 @@ module.exports = async (deletePatternDir, patternlab, additionalData) => {
filter: ['*.js'],
rename: () => {
return `${patternPartial}.js`;
},
}
}
).on(copy.events.COPY_FILE_COMPLETE, () => {
logger.debug(
Expand Down Expand Up @@ -199,27 +199,27 @@ module.exports = async (deletePatternDir, patternlab, additionalData) => {
//export patterns if necessary
pattern_exporter.export_patterns(patternlab);
})
.catch((reason) => {
.catch(reason => {
console.log(reason);
logger.error('Error rendering patterns');
});
})
.catch((reason) => {
.catch(reason => {
console.log(reason);
logger.error('Error rendering pattern lab header');
});
})
.catch((reason) => {
.catch(reason => {
console.log(reason);
logger.error('Error processing meta patterns');
});
})
.catch((reason) => {
.catch(reason => {
console.log(reason);
logger.error('Error processing patterns recursively');
});
})
.catch((reason) => {
.catch(reason => {
console.log(reason);
logger.error('Error in buildPatterns()');
});
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/lib/changes_hunter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let fs = require('fs-extra'); //eslint-disable-line prefer-const
* For detecting changed patterns.
* @constructor
*/
const ChangesHunter = function () {};
const ChangesHunter = function() {};

ChangesHunter.prototype = {
/**
Expand All @@ -25,7 +25,7 @@ ChangesHunter.prototype = {
*
* @see {@link CompileState}
*/
checkBuildState: function (pattern, patternlab) {
checkBuildState: function(pattern, patternlab) {
//write the compiled template to the public patterns directory
const renderedTemplatePath =
patternlab.config.paths.public.patterns +
Expand All @@ -40,12 +40,12 @@ ChangesHunter.prototype = {
pattern.compileState = CompileState.NEEDS_REBUILD;
}

_.each(patternlab.uikits, (uikit) => {
_.each(patternlab.uikits, uikit => {
try {
// renderedTemplatePath required to display a single element
// Markup only is required for "View All" pages. It will get loaded later on.
// If any of these is missing, mark pattern for recompile
[renderedTemplatePath, markupOnlyPath].forEach((renderedFile) => {
[renderedTemplatePath, markupOnlyPath].forEach(renderedFile => {
// Prevent error message if file does not exist
fs.accessSync(
path.join(process.cwd(), uikit.outputDir, renderedFile),
Expand Down Expand Up @@ -94,7 +94,7 @@ ChangesHunter.prototype = {
* @param {Pattern} currentPattern
* @param {string} file
*/
checkLastModified: function (currentPattern, file) {
checkLastModified: function(currentPattern, file) {
if (file && fs.pathExistsSync(file)) {
try {
const stat = fs.statSync(file);
Expand All @@ -110,12 +110,12 @@ ChangesHunter.prototype = {
}
},

needsRebuild: function (lastModified, p) {
needsRebuild: function(lastModified, p) {
if (p.compileState !== CompileState.CLEAN || !p.lastModified) {
return true;
}
return p.lastModified >= lastModified;
},
}
};

module.exports = ChangesHunter;
4 changes: 2 additions & 2 deletions packages/core/src/lib/cleanBuildDirectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ module.exports = (incrementalBuildsEnabled, patternlab) => {
return Promise.resolve();
} else {
return Promise.all(
_.map(patternlab.uikits, (uikit) => {
_.map(patternlab.uikits, uikit => {
return fs.emptyDir(
path.join(process.cwd(), uikit.outputDir, paths.public.patterns)
);
})
).catch((reason) => {
).catch(reason => {
logger.error(reason);
});
}
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/lib/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const pluginManager = new pm();
const Pattern = require('./object_factory').Pattern;
const CompileState = require('./object_factory').CompileState;

module.exports = async function (pattern, patternlab) {
module.exports = async function(pattern, patternlab) {
// Pattern does not need to be built and recompiled more than once
if (!pattern.isPattern || pattern.compileState === CompileState.CLEAN) {
return Promise.resolve(false);
Expand All @@ -41,7 +41,7 @@ module.exports = async function (pattern, patternlab) {
);

return Promise.all(
_.map(patternlab.uikits, (uikit) => {
_.map(patternlab.uikits, uikit => {
// exclude pattern from uikit rendering
if (uikitExcludePattern(pattern, uikit)) {
return Promise.resolve();
Expand Down Expand Up @@ -125,18 +125,18 @@ module.exports = async function (pattern, patternlab) {
patternBreadcrumb:
pattern.patternGroup === pattern.patternSubgroup
? {
patternGroup: pattern.patternGroup,
patternGroup: pattern.patternGroup
}
: {
patternGroup: pattern.patternGroup,
patternSubgroup: pattern.patternSubgroup,
patternSubgroup: pattern.patternSubgroup
},
patternExtension: pattern.fileExtension.substr(1), //remove the dot because styleguide asset default adds it for us
patternName: pattern.patternName,
patternPartial: pattern.patternPartial,
patternState: pattern.patternState,
patternEngineName: pattern.engine.engineName,
extraOutput: extraOutput,
extraOutput: extraOutput
});

//set the pattern-specific footer by compiling the general-footer with data, and then adding it to the meta footer
Expand All @@ -145,16 +145,16 @@ module.exports = async function (pattern, patternlab) {
{
isPattern: pattern.isPattern,
patternData: pattern.patternData,
cacheBuster: patternlab.cacheBuster,
cacheBuster: patternlab.cacheBuster
}
);

return Promise.all([
headPromise,
patternPartialPromise,
footerPartialPromise,
footerPartialPromise
])
.then((intermediateResults) => {
.then(intermediateResults => {
// retrieve results of promises
const headHTML = intermediateResults[0]; //headPromise
pattern.patternPartialCode = intermediateResults[1]; //patternPartialPromise
Expand All @@ -178,7 +178,7 @@ module.exports = async function (pattern, patternlab) {
allFooterData.patternLabFoot = footerPartial;

return render(patternlab.userFoot, allFooterData).then(
async (footerHTML) => {
async footerHTML => {
///////////////
// WRITE FILES
///////////////
Expand Down Expand Up @@ -211,7 +211,7 @@ module.exports = async function (pattern, patternlab) {
}
);
})
.catch((reason) => {
.catch(reason => {
console.log(reason);
});
})
Expand Down
Loading

0 comments on commit 8bbd83d

Please sign in to comment.