@total_onion/onion-library 2.0.23 → 2.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/checkBuildAssets.js +18 -0
- package/createJsAssets.js +31 -0
- package/createPreviewScss.js +35 -0
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable global-require */
|
|
2
|
+
require('dotenv').config();
|
|
3
|
+
const fs = require( 'fs' );
|
|
4
|
+
const themePath = process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
|
|
5
|
+
|
|
6
|
+
const paths = {
|
|
7
|
+
createJsAssets:
|
|
8
|
+
`${themePath}/assets/js/modules/jsAssets.js`,
|
|
9
|
+
createPreviewScss:
|
|
10
|
+
`${themePath}/assets/scss/modules/dynamicBlocksPreview.scss`,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
Object.keys( paths ).forEach( ( key ) => {
|
|
14
|
+
if ( ! fs.existsSync( paths[ key ] ) ) {
|
|
15
|
+
console.log( `creating missing assets with ${ key }` );
|
|
16
|
+
require( 'child_process' ).fork( `./node_modules/@pernod-ricard-global-cms/jsbuildutils/${ key }.js` );
|
|
17
|
+
}
|
|
18
|
+
} );
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const fs = require( 'fs' );
|
|
3
|
+
const path = require( 'path' );
|
|
4
|
+
const { globSync } = require( 'glob' );
|
|
5
|
+
const themePath = process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
|
|
6
|
+
|
|
7
|
+
const dynamicEntryPoints = globSync(`${themePath}/assets/js/blocks/*.js`)
|
|
8
|
+
.map((path) => {
|
|
9
|
+
const assetKey = path
|
|
10
|
+
.replace('assets/js/blocks/', '')
|
|
11
|
+
.replace('.js', '');
|
|
12
|
+
return assetKey;
|
|
13
|
+
});
|
|
14
|
+
const assetArray = dynamicEntryPoints.map((entry) => {
|
|
15
|
+
return { assetKey: entry };
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const jsAssetsFilePath = path.join(themePath, 'assets/js/modules/jsAssets.js'); // Create the absolute path to the destination file
|
|
19
|
+
|
|
20
|
+
// Create directories if they don't exist
|
|
21
|
+
const dirPath = path.dirname(jsAssetsFilePath);
|
|
22
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
23
|
+
|
|
24
|
+
const data = `// This file is auto-generated. To include assets for the lazyloader, just add your .js file to Assets/js/blocks/ and it will be included here.
|
|
25
|
+
const dynamicAssets = ${JSON.stringify(assetArray)};
|
|
26
|
+
const api = {
|
|
27
|
+
dynamicAssets,
|
|
28
|
+
};
|
|
29
|
+
export default api;`;
|
|
30
|
+
|
|
31
|
+
fs.writeFileSync(jsAssetsFilePath, data);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const {globSync} = require('glob');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const themePath =
|
|
6
|
+
process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
|
|
7
|
+
|
|
8
|
+
// Create the directory path for the target file
|
|
9
|
+
const scssModulePath = path.join(themePath, 'assets/scss/modules');
|
|
10
|
+
const scssFilePath = path.join(scssModulePath, 'dynamicBlocksPreview.scss');
|
|
11
|
+
|
|
12
|
+
// Create directories if they don't exist
|
|
13
|
+
fs.mkdirSync(scssModulePath, {recursive: true});
|
|
14
|
+
|
|
15
|
+
// Write the initial content to the target file
|
|
16
|
+
fs.writeFileSync(
|
|
17
|
+
scssFilePath,
|
|
18
|
+
'// This file is auto-generated. To include assets for the lazyloader, just add your .scss file to Assets/scss/blocks/ and it will be included here.\n'
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const dynamicEntryPoints = globSync(
|
|
22
|
+
`${themePath}/assets/scss/blocks/*.scss`
|
|
23
|
+
).map((path) => {
|
|
24
|
+
const assetPath = path.replace(
|
|
25
|
+
'assets/scss/blocks/',
|
|
26
|
+
'Assets/scss/blocks/'
|
|
27
|
+
);
|
|
28
|
+
return assetPath;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const stream = fs.createWriteStream(scssFilePath, {flags: 'a'});
|
|
32
|
+
dynamicEntryPoints.forEach((entry) => {
|
|
33
|
+
stream.write(`@use '${entry}';\n`);
|
|
34
|
+
});
|
|
35
|
+
stream.end();
|