Skip to content

Commit

Permalink
chore: merge origin and fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ampersarnie committed Dec 12, 2022
2 parents ab195c8 + 4d052c0 commit 583ff70
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 53 deletions.
46 changes: 45 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@ orbs:
node: circleci/[email protected]

jobs:
install_tests:
docker:
- image: cimg/node:17.2.0
steps:
- checkout
- restore_cache:
name: Restoring Modules Cache
keys:
- v1-modules-cache-{{ checksum "package-lock.json" }}
- node/install-packages:
pkg-manager: npm
- run:
command: |
cd ./example-site/
node ./../src/cli.js install
name: Run test - install projects
- run:
command: |
cd ./example-site/
node ./../src/cli.js install -- --package-lock-only
name: Run test - install projects with npm args
- run:
command: |
cd ./example-site/
node ./../src/cli.js ci
name: Run test - ci install projects
- save_cache:
name: Saving Modules Cache
key: v1-modules-cache-{{ checksum "package-lock.json" }}
paths:
- ./node_modules
- /home/circleci/.cache
- persist_to_workspace:
root: ~/project
paths:
- .
notify_slack:
docker:
- image: cimg/node:17.2.0
Expand Down Expand Up @@ -64,6 +100,11 @@ jobs:
cd ./example-site/
node ./../src/cli.js ci
name: Run test - ci install projects
- run:
command: |
cd ./example-site/
node ./../src/cli.js ci
name: Run test - ci install projects
- run:
command: |
cd ./example-site/
Expand All @@ -84,7 +125,10 @@ jobs:
paths:
- .
workflows:
test_build_tools:
test_install:
jobs:
- install_tests
test_build:
jobs:
- install_tests
- self_test
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"name": "test-client-plugin"
}
}
4 changes: 4 additions & 0 deletions example-site/plugins/test-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example-site/plugins/test-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"name": "test-plugin"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('test frontend');
4 changes: 4 additions & 0 deletions example-site/themes/test-theme/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example-site/themes/test-theme/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"name": "test-theme"
}
}
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bigbite/build-tools",
"version": "1.0.0",
"version": "1.1.0",
"description": "Provides configuration for the Big Bite Build Tools.",
"author": "Paul Taylor <[email protected]> (https://github.com/ampersarnie)",
"keywords": [
Expand Down
1 change: 1 addition & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

const yargs = require('yargs');
const globalVars = require('./globals');

yargs.scriptName('build-tools');
yargs.usage('Usage: build-tools <command>');
Expand Down
21 changes: 9 additions & 12 deletions src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ exports.handler = async ({
const mode = production ? 'production' : 'development';
// Use env variables if working on Webpack >=5.
const projectsList = projects.split(',').filter((item) => item.length > 0);
const targetDirs = ['client-mu-plugins', 'plugins', 'themes'];
const hasTargetDirs = dirsExist(targetDirs);
const isAllProjects = (site || hasTargetDirs) && !projects;

Expand Down Expand Up @@ -95,10 +94,8 @@ exports.handler = async ({
}

terminal('Processing the following projects:\n');
packages.forEach((item) => {
const regexDirs = targetDirs.join('|');
const packagePath = item.packagePath.match(`((${regexDirs})\/)?([^\/]+)\/package.json$`);
terminal.defaultColor(` * %s `, item.packageName).dim(`[%s]\n`, packagePath[0]);
packages.forEach((package) => {
terminal.defaultColor(` * %s `, package.name).dim(`[%s]\n`, package.relativePath);
});
terminal('\n');

Expand All @@ -111,8 +108,8 @@ exports.handler = async ({
* to build them, use what is here.
*/
const PROJECT_CONFIG = {
name: packageObject.packageName,
version: packageObject.package.version,
name: packageObject.name,
version: packageObject.json.version,
paths: {
project: path.resolve(packageObject.path),
config: path.resolve(`${__dirname}/configs`),
Expand All @@ -131,18 +128,18 @@ exports.handler = async ({
};

let customWebpackConfig = {
extends: true
extends: true,
};
let config = webpackConfig(PROJECT_CONFIG, mode);

try {
customWebpackConfig = {
...customWebpackConfig,
...require(PROJECT_CONFIG.paths.project + '/webpack.config.js')
}
} catch(e) {}
...require(PROJECT_CONFIG.paths.project + '/webpack.config.js'),
};
} catch (e) {}

if(!customWebpackConfig?.extends) {
if (!customWebpackConfig?.extends) {
config = customWebpackConfig;
} else if (customWebpackConfig) {
config = {
Expand Down
9 changes: 9 additions & 0 deletions src/commands/ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const installer = require('./installer/installer');

exports.command = 'ci';
exports.desc = 'Run an npm ci install process.';
exports.builder = (yargs) => {};

exports.handler = async ({}) => {
installer(exports.command);
};
9 changes: 9 additions & 0 deletions src/commands/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const installer = require('./installer/installer');

exports.command = 'install';
exports.desc = 'Run an npm install process.';
exports.builder = (yargs) => {};

exports.handler = async ({}) => {
installer(exports.command);
};
48 changes: 48 additions & 0 deletions src/commands/installer/installer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { terminal } = require('terminal-kit');
const { execSync } = require('child_process');
const yargs = require('yargs');
const args = yargs.argv._;

const { findAllProjectPaths } = require('./../../utils/projectpaths');
const { getPackage } = require('./../../utils/get-package');
const dirsExist = require('./../../utils/dirs-exist');

module.exports = (commandType) => {
if (!['ci', 'install'].includes(commandType)) {
throw new Error('Not a valid comment type.');
}

const hasTargetDirs = dirsExist(targetDirs);

if (!hasTargetDirs) {
throw new Error('Recursive install only works from the site root directory.');
}

let paths = findAllProjectPaths(targetDirs);

let packages = [];

try {
packages = paths.map((item) => getPackage(item, false)).filter((item) => item);
} catch (e) {
terminal.red(e);
process.exit(1);
}

terminal('Installing packages for the following projects:\n');
packages.forEach((package) => {
terminal.defaultColor(` * %s `, package.name).dim(`[%s]\n`, package.relativePath);
});
terminal('\n');

const gluedArgs = args.join(' ');

packages.forEach((package) => {
terminal
.defaultColor(`Installing packages for `)
.bold(`%s`, package.name)
.dim(` [%s]\n`, package.relativePath);
execSync(`npm ${gluedArgs}`, { cwd: package.path, stdio: 'inherit' });
terminal.defaultColor('\n\n----------------------\n\n');
});
};
2 changes: 2 additions & 0 deletions src/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global.targetDirs = ['client-mu-plugins', 'plugins', 'themes'];
global.packageList = {};
Loading

0 comments on commit 583ff70

Please sign in to comment.