Skip to content

Commit

Permalink
Merge pull request #425 from 10up/develop
Browse files Browse the repository at this point in the history
Release 6.3
  • Loading branch information
fabiankaegy authored Sep 24, 2024
2 parents 44caa00 + b642d40 commit f56726a
Show file tree
Hide file tree
Showing 32 changed files with 375 additions and 131 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-pumpkins-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"10up-toolkit": patch
---

Simple enhancements to toolkit project command to align with devops needs.
5 changes: 5 additions & 0 deletions .changeset/lemon-owls-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"10up-toolkit": minor
---

Allow block-specific CSS entry points to get automatically generated for any CSS files in the `assets/css/blocks` directory.
18 changes: 18 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"mode": "pre",
"tag": "next",
"initialVersions": {
"@10up/babel-preset-default": "2.1.1",
"@10up/eslint-config": "4.1.0",
"@10up/stylelint-config": "3.0.0",
"10up-toolkit": "6.2.2",
"tenup-theme": "1.1.5-next.7",
"@10up/component-accordion": "2.1.5",
"@10up/library-ts-test": "2.1.5"
},
"changesets": [
"eight-pumpkins-provide",
"lemon-owls-invent",
"young-guests-deliver"
]
}
5 changes: 5 additions & 0 deletions .changeset/young-guests-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"10up-toolkit": patch
---

Fix: transform file extension for .ts and .tsx assets inside block.json files
11 changes: 11 additions & 0 deletions packages/toolkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 6.3.0-next.0

### Minor Changes

- 3a5b540: Allow block-specific CSS entry points to get automatically generated for any CSS files in the `assets/css/blocks` directory.

### Patch Changes

- 8b74e5a: Simple enhancements to toolkit project command to align with devops needs.
- 7ce09d9: Fix: transform file extension for .ts and .tsx assets inside block.json files

## 6.2.2

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.wp-block-heading {

@mixin margin-trim;

@media (--bp-small) {
padding: 40px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
html {
background: #f5f5f5;
padding: 20px;

@mixin margin-trim;

@media (--bp-small) {
padding: 40px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Media Queries
*/
@custom-media --bp-tiny ( min-width: 25em ); /* 400px */
@custom-media --bp-small ( min-width: 30em ); /* 480px */
@custom-media --bp-medium ( min-width: 48em ); /* 768px */
@custom-media --bp-large ( min-width: 64em ); /* 1024px */
@custom-media --bp-xlarge ( min-width: 80em ); /* 1280px */
@custom-media --bp-xxlarge ( min-width: 90em ); /* 1440px */

/* WP Core Breakpoints (used for the admin bar for example) */
@custom-media --wp-small ( min-width: 600px );
@custom-media --wp-medium-max (max-width: 782px);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@define-mixin margin-trim {
margin-trim: block;

/* Fallback for browsers that don't support margin-trim */
@supports not (margin-trim: block) {

& > *:first-child {
margin-top: 0;
}

& > *:last-child {
margin-bottom: 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "test-build-project-global-css",
"10up-toolkit": {
"loadBlockSpecificStyles": true,
"paths": {
"srcDir": "./__fixtures__/assets/",
"blocksStyles": "./__fixtures__/assets/css/blocks/",
"cssLoaderPaths": ["./__fixtures__/assets/css", "./includes/blocks"],
"globalStylesDir": "./__fixtures__/assets/css/globals/",
"globalMixinsDir": "./__fixtures__/assets/css/mixins/"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-disable import/no-extraneous-dependencies */
import spawn from 'cross-spawn';
import fs from 'fs';
import path from 'path';

describe('build a project', () => {
it('builds and compiles css with global css', async () => {
spawn.sync('node', ['../../scripts/build'], {
cwd: __dirname,
});

const frontendCss = path.join(
__dirname,
'dist',
'blocks',
'autoenqueue',
'core',
'heading.css',
);

expect(fs.existsSync(frontendCss)).toBeTruthy();
expect(
fs.existsSync(
path.join(__dirname, 'dist', 'blocks', 'autoenqueue', 'core', 'heading.asset.php'),
),
).toBeTruthy();

const compiledCSS = fs.readFileSync(frontendCss).toString();

// expect the compiled CSS to contain "min-width: 30em"
expect(compiledCSS).toMatch('min-width: 30em');
});
});
71 changes: 36 additions & 35 deletions packages/toolkit/config/__tests__/__fixtures__/accordion.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,52 @@


:root {
--primary-font: 'Mr George', Arial, Helvetica, sans-serif;
--primary-font: "Mr George", arial, helvetica, sans-serif;
}

@font-face {
font-family: 'Mr George';
src: url('./assets/fonts/MrGeorgeHeavy.ttf') format('truetype');
font-weight: 900
font-family: "Mr George";
font-weight: 900;
src: url("./assets/fonts/MrGeorgeHeavy.ttf") format("truetype");
}

@font-face {
font-family: 'Mr George';
src: url('./assets/fonts/MrGeorge.ttf') format('truetype');
font-weight: 400
font-family: "Mr George";
font-weight: 400;
src: url("./assets/fonts/MrGeorge.ttf") format("truetype");
}

.accordion-header {
border-bottom: 1px solid #303030;
cursor: pointer;
font-size: 1em;
padding: 10px 0 10px 20px;
position: relative;
text-align: left;
width: 100%;

&:before {
content: "+";
left: 5px;
position: absolute;
top: 8px;
}

&.is-active:before {
content: "-";
}
border-bottom: 1px solid #303030;
cursor: pointer;
font-size: 1em;
padding: 10px 0 10px 20px;
position: relative;
text-align: left;
width: 100%;

&::before {
content: "+";
left: 5px;
position: absolute;
top: 8px;
}

&.is-active::before {
content: "-";
}
}

.accordion-content {
@nest .js & {
display: none;
visibility: hidden;

&.is-active {
border-bottom: 1px solid #303030;
display: block;
visibility: visible;
}
}

.js & {
display: none;
visibility: hidden;

&.is-active {
border-bottom: 1px solid #303030;
display: block;
visibility: visible;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,45 +183,45 @@ exports[`postcss properly transforms css 1`] = `

exports[`postcss transforms accordion.css properly 1`] = `
":root {
--primary-font: 'Mr George', Arial, Helvetica, sans-serif;
--primary-font: "Mr George", arial, helvetica, sans-serif;
}
@font-face {
font-family: 'Mr George';
src: url('./assets/fonts/MrGeorgeHeavy.ttf') format('truetype');
font-weight: 900
font-family: "Mr George";
font-weight: 900;
src: url("./assets/fonts/MrGeorgeHeavy.ttf") format("truetype");
}
@font-face {
font-family: 'Mr George';
src: url('./assets/fonts/MrGeorge.ttf') format('truetype');
font-weight: 400
font-family: "Mr George";
font-weight: 400;
src: url("./assets/fonts/MrGeorge.ttf") format("truetype");
}
.accordion-header {
border-bottom: 1px solid #303030;
cursor: pointer;
font-size: 1em;
padding: 10px 0 10px 20px;
position: relative;
text-align: left;
width: 100%;
}
.accordion-header:before {
content: "+";
left: 5px;
position: absolute;
top: 8px;
}
.accordion-header.is-active:before {
content: "-";
}
.js .accordion-content {
display: none;
visibility: hidden;
border-bottom: 1px solid #303030;
cursor: pointer;
font-size: 1em;
padding: 10px 0 10px 20px;
position: relative;
text-align: left;
width: 100%;
}
.accordion-header::before {
content: "+";
left: 5px;
position: absolute;
top: 8px;
}
.accordion-header.is-active::before {
content: "-";
}
.js .accordion-content {
display: none;
visibility: hidden;
}
.js .accordion-content.is-active {
border-bottom: 1px solid #303030;
display: block;
visibility: visible;
}
border-bottom: 1px solid #303030;
display: block;
visibility: visible;
}
"
`;

Expand Down
9 changes: 5 additions & 4 deletions packages/toolkit/config/paths.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module.exports = {
srcDir: './assets/',
cssLoaderPaths: ['./assets/css', './includes/blocks'],
copyAssetsDir: './assets/',
blocksDir: './includes/blocks/',
globalStylesDir: './assets/css/globals/',
blocksStyles: './assets/css/blocks/',
copyAssetsDir: './assets/',
cssLoaderPaths: ['./assets/css', './includes/blocks'],
globalMixinsDir: './assets/css/mixins/',
globalStylesDir: './assets/css/globals/',
srcDir: './assets/',
};
29 changes: 27 additions & 2 deletions packages/toolkit/config/webpack/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ const removeDistFolder = (file) => {
module.exports = ({
buildType = 'script',
isPackage,
projectConfig: { devServer, paths, useBlockAssets, filenames },
projectConfig: { devServer, paths, useBlockAssets, filenames, loadBlockSpecificStyles },
packageConfig: { packageType, source, main, umd, libraryName },
buildFiles,
moduleBuildFiles,
}) => {
let additionalEntrypoints = {};

if (useBlockAssets) {
// override default block filenames
filenames.block = 'blocks/[name].js';
Expand Down Expand Up @@ -105,13 +106,37 @@ module.exports = ({
}, {});
}

const blockStyleEntryPoints = {};

// Logic for loading CSS files per block.
if (loadBlockSpecificStyles) {
// get all stylesheets located in the assets/css/blocks directory and subdirectories
const blockStylesheetDirectory = resolve(process.cwd(), paths.blocksStyles).replace(
/\\/g,
'/',
);

// get all stylesheets in the blocks directory
const stylesheets = glob(`${blockStylesheetDirectory}/**/*.css`, {
absolute: true,
});

stylesheets.forEach((filePath) => {
const blockName = filePath
.replace(`${blockStylesheetDirectory}/`, '')
.replace(extname(filePath), '');

blockStyleEntryPoints[`autoenqueue/${blockName}`] = resolve(filePath);
});
}

if (buildType === 'module') {
Object.assign(moduleBuildFiles, additionalEntrypoints);
return moduleBuildFiles;
}

// merge the new entrypoints with the existing ones
Object.assign(buildFiles, additionalEntrypoints);
Object.assign(buildFiles, additionalEntrypoints, blockStyleEntryPoints);

if (isPackage) {
const config = {};
Expand Down
Loading

0 comments on commit f56726a

Please sign in to comment.