-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from softlimit/cwc/parent-theme
- Loading branch information
Showing
31 changed files
with
932 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
module.exports = { | ||
getAll: require('./get-all'), | ||
liquid: require('./liquid'), | ||
tailwind: require('./tailwind'), | ||
themeEnvy: require('./theme-envy'), | ||
webpack: require('./webpack'), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* @private | ||
* @file Checks for a parent theme in node_modules or relative path and sets ThemeEnvy.parentTheme to the path | ||
*/ | ||
|
||
const fs = require('fs-extra') | ||
const path = require('path'); | ||
|
||
(() => { | ||
const ThemeConfigPath = path.resolve(process.cwd(), 'theme.config.js') | ||
if (!fs.existsSync(ThemeConfigPath)) return | ||
ThemeEnvy.childPreferred = ThemeEnvy.childPreferred || [] | ||
|
||
// look for parent theme in node_modules | ||
const parentThemePath = ThemeEnvy.parentTheme?.path | ||
if (!parentThemePath) { | ||
removeParentThemeReference() | ||
return | ||
} | ||
const parentThemePkg = fs.existsSync(path.resolve(process.cwd(), 'node_modules', parentThemePath)) | ||
? path.resolve(process.cwd(), 'node_modules', parentThemePath) | ||
: false | ||
// look for parent theme in relative path | ||
const parentThemeRelative = fs.existsSync(path.resolve(process.cwd(), parentThemePath)) | ||
? path.resolve(process.cwd(), parentThemePath) | ||
: false | ||
// prefer node_modules over relative path | ||
const parentTheme = parentThemePkg || parentThemeRelative | ||
|
||
if (!parentTheme) { | ||
removeParentThemeReference() | ||
return | ||
} | ||
ThemeEnvy.parentTheme.path = parentTheme | ||
// define elements and features arrays | ||
ThemeEnvy.parentTheme.elements = listFeaturesOrElements({ type: 'elements' }) | ||
ThemeEnvy.parentTheme.features = listFeaturesOrElements({ type: 'features' }) | ||
})() | ||
|
||
function removeParentThemeReference() { | ||
delete ThemeEnvy.parentTheme | ||
} | ||
|
||
function listFeaturesOrElements({ type }) { | ||
// get parentTheme config | ||
const parentConfig = require(path.resolve(ThemeEnvy.parentTheme.path, 'parent.config.js')) | ||
// get parentTheme theme-envy directory path | ||
const parentThemeEnvyDir = path.resolve(ThemeEnvy.parentTheme.path, 'src/theme-envy') | ||
|
||
const elementsOrFeatures = fs.readdirSync(path.resolve(parentThemeEnvyDir, type)) | ||
.filter(file => { | ||
// remove items that are in the parent.config.js exclude array | ||
if (!parentConfig[type]?.exclude) return true | ||
return parentConfig[type].exclude.includes(path.parse(file).name) === false | ||
}) | ||
.filter(file => { | ||
// remove items that are in theme.config.js exclude array | ||
if (!ThemeEnvy.parentTheme[type]?.exclude) return true | ||
return ThemeEnvy.parentTheme[type]?.exclude.includes(path.parse(file).name) === false | ||
}) | ||
.map(file => path.resolve(parentThemeEnvyDir, type, file).replace('.js', '')) | ||
|
||
// add items that are in the include array of the child theme | ||
if (ThemeEnvy.parentTheme[type]?.include) { | ||
ThemeEnvy.parentTheme[type].include.forEach(item => { | ||
if (!elementsOrFeatures.includes(item)) { | ||
// check if the item exists in the parent theme | ||
if (!fs.existsSync(path.resolve(parentThemeEnvyDir, type, item))) { | ||
console.error(`The ${item} ${type} does not exist in the parent theme`) | ||
return | ||
} | ||
elementsOrFeatures.push(path.resolve(ThemeEnvy.parentTheme.path, 'theme-envy', type, item)) | ||
} | ||
}) | ||
} | ||
return elementsOrFeatures | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Get all files from the parent theme that are not in the child | ||
* @private | ||
* @param {function} func - function to get files with a glob, should return an array of file paths | ||
* @param {array} childFiles - array of file paths from the child theme that we check against | ||
* @returns {array} - array of file paths from the parent theme that are not in the child | ||
*/ | ||
const path = require('path') | ||
const { directories } = require('#EnsureDirectories') | ||
// sets resolved parent theme path | ||
require('./index.js') | ||
|
||
module.exports = (func, childFiles, type) => { | ||
const childRelative = childFiles.map(file => path.relative(ThemeEnvy.themePath, file)) | ||
// get all files from the parent theme, using only elements and features directories in parent theme | ||
let only = [...ThemeEnvy.parentTheme.elements, ...ThemeEnvy.parentTheme.features] | ||
|
||
if (type === 'elements') { | ||
only = ThemeEnvy.parentTheme.elements | ||
} | ||
if (type === 'features') { | ||
only = ThemeEnvy.parentTheme.features | ||
} | ||
if (type === 'schema') { | ||
only.push(path.resolve(ThemeEnvy.parentTheme.path, 'src/theme-envy/schema')) | ||
} | ||
if (type === 'liquid') { | ||
only.push(...directories.map(dir => path.resolve(ThemeEnvy.parentTheme.path, 'src', dir))) | ||
} | ||
if (type === 'sectionGroups') { | ||
only.push(path.resolve(ThemeEnvy.parentTheme.path, 'src/sections')) | ||
} | ||
if (type === 'config') { | ||
only.push(path.resolve(ThemeEnvy.parentTheme.path, 'src/config')) | ||
} | ||
if (type === 'locales') { | ||
only.push(path.resolve(ThemeEnvy.parentTheme.path, 'src/locales')) | ||
} | ||
if (type === 'templates') { | ||
only.push(path.resolve(ThemeEnvy.parentTheme.path, 'src/templates')) | ||
} | ||
if (type === 'criticalCSS') { | ||
only.push(path.resolve(ThemeEnvy.parentTheme.path, 'src/styles')) | ||
} | ||
|
||
return func(ThemeEnvy.parentTheme.path, only).filter(file => !childRelative.includes(path.relative(ThemeEnvy.parentTheme.path, file))) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.