Explorar o código

Merge pull request #3536 from Automattic/add/build-tool-for-bcb

Blank Canvas Blocks: Add a build tool
Ben Dwyer %!s(int64=4) %!d(string=hai) anos
pai
achega
7af870b234

+ 21 - 0
blank-canvas-blocks/build.js

@@ -0,0 +1,21 @@
+const fs = require('fs');
+const chokidar = require('chokidar');
+const merge = require('deepmerge');
+const childThemeName = process.argv[ 2 ];
+const childThemeJsonFileName = '../' + childThemeName + '/child-experimental-theme.json';
+
+chokidar.watch( childThemeJsonFileName ).on( 'all', ( event, path ) => {
+	try {
+		const parentThemeJsonFile = fs.readFileSync( 'experimental-theme.json', 'utf8' );
+		const childThemeJsonFile  = fs.readFileSync( childThemeJsonFileName, 'utf8' );
+		parentThemeJson          = JSON.parse( parentThemeJsonFile );
+		childThemeJson           = JSON.parse( childThemeJsonFile );
+		mergedThemeJson          = merge( parentThemeJson, childThemeJson );
+		fs.writeFile( '../' + childThemeName + '/experimental-theme.json', JSON.stringify( mergedThemeJson ), 'utf8', () => {
+			console.log( "\x1b[32m" + childThemeName + "/experimental-theme.json created successfully." );
+		} )
+
+	} catch ( error ) {
+		console.error( "\x1b[41m" + error );
+	}
+} );

+ 6 - 0
blank-canvas-blocks/package-lock.json

@@ -610,6 +610,12 @@
       "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
       "dev": true
     },
+    "deepmerge": {
+      "version": "4.2.2",
+      "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz",
+      "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==",
+      "dev": true
+    },
     "define-property": {
       "version": "2.0.2",
       "resolved": "https://registry.npmjs.org/define-property/-/define-property-2.0.2.tgz",

+ 3 - 1
blank-canvas-blocks/package.json

@@ -10,6 +10,7 @@
     "@wordpress/base-styles": "^3.3.0",
     "@wordpress/browserslist-config": "^2.2.2",
     "chokidar-cli": "^2.1.0",
+    "deepmerge": "^4.2.2",
     "node-sass": "^4.13.1",
     "node-sass-package-importer": "^5.3.2",
     "rtlcss": "^2.4.0"
@@ -32,6 +33,7 @@
   ],
   "scripts": {
     "start": "chokidar \"**/*.scss\" -c \"npm run build\" --initial",
-    "build": "node-sass --importer node_modules/node-sass-package-importer/dist/cli.js sass/ponyfill.scss assets/ponyfill.css --output-style expanded --indent-type tab --indent-width 1 --source-map true"
+    "build": "node-sass --importer node_modules/node-sass-package-importer/dist/cli.js sass/ponyfill.scss assets/ponyfill.css --output-style expanded --indent-type tab --indent-width 1 --source-map true",
+    "build-child": "node build.js"
   }
 }