Skip to content

Commit

Permalink
add dateFormat + minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniopresto committed Mar 1, 2024
1 parent da780ec commit 6b5f6ce
Show file tree
Hide file tree
Showing 27 changed files with 571 additions and 87 deletions.
13 changes: 0 additions & 13 deletions .run/Template Jest.run.xml

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powership",
"version": "3.2.20",
"version": "3.2.24",
"private": true,
"scripts": {
"pack": "run-s pack:*",
Expand Down Expand Up @@ -45,7 +45,7 @@
"runmate": "latest",
"typedoc-plugin-markdown": "3.14.0",
"typescript": "4.8.2",
"bun-safe": "1.0.5",
"bun-safe": "1.0.7",
"semver": "7.5.2",
"typedoc": "0.23.24",
"zx": "7.2.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/accounts",
"version": "3.2.22",
"version": "3.2.24",
"description": "Powership accounts",
"type": "module",
"main": "./out/index.cjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/babel-plugins",
"version": "3.2.22",
"version": "3.2.24",
"main": "./out/index.js",
"sideEffects": false,
"typings": "./out/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/boilerplate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/boilerplate",
"version": "3.2.22",
"version": "3.2.24",
"author": "antoniopresto <[email protected]>",
"sideEffects": false,
"type": "module",
Expand Down Expand Up @@ -34,6 +34,7 @@
"out/*",
"tsconfig/*",
"eslintrc.cjs",
"babel-config.cjs",
"README.md"
]
}
2 changes: 1 addition & 1 deletion packages/deepstate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/deepstate",
"version": "3.2.22",
"version": "3.2.24",
"main": "out/index.cjs",
"module": "out/module/index.mjs",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/entity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/entity",
"version": "3.2.22",
"version": "3.2.24",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/module/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/helpers",
"version": "3.2.22",
"version": "3.2.24",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/module/index.mjs",
Expand Down
5 changes: 3 additions & 2 deletions packages/logstorm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logstorm",
"version": "3.2.22",
"version": "3.2.24",
"typings": "out",
"author": "antoniopresto <[email protected]>",
"type": "module",
Expand Down Expand Up @@ -39,7 +39,8 @@
"description": "run command in each package",
"keywords": [],
"dependencies": {
"plugin-hooks": "2.0.0"
"plugin-hooks": "2.0.0",
"@powership/utils": "workspace:*"
},
"devDependencies": {
"@powership/boilerplate": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/mongo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/mongo",
"version": "3.2.22",
"version": "3.2.24",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/module/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plugin-engine",
"version": "3.2.22",
"version": "3.2.24",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/module/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/powership/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powership",
"version": "3.2.22",
"version": "3.2.24",
"author": "antoniopresto <[email protected]>",
"type": "module",
"main": "./out/index.cjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/runmate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "runmate",
"version": "3.2.22",
"version": "3.2.24",
"typings": "out",
"author": "antoniopresto <[email protected]>",
"license": "MIT",
Expand Down
18 changes: 12 additions & 6 deletions packages/runmate/src/__tests__/findWorkspacePackages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ describe('findWorkspacePackages', () => {
cwd: nodePath.resolve(__dirname),
});

expect(sut).toEqual([]);
});

test('catch top package', () => {
const sut = findWorkspacePackages({
cwd: nodePath.resolve(__dirname, '../../'),
});

expect(sut).toEqual([
{
found: [],
pattern: 'apps/*',
},
{
found: [],
pattern: 'packages/*',
path: expect.stringMatching(/\/packages\/runmate\/package.json$/),
json: expect.objectContaining({ name: 'runmate' }),
relative: './',
pattern: './',
},
]);
});
Expand Down
20 changes: 19 additions & 1 deletion packages/runmate/src/commands/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export function main(program: Command) {
'Run command in each package in ./packages folder or in `--cwd` option folder'
)
.option('-d, --cwd <pattern>', 'Source directory or glob pattern')
.option(
'--include-root <boolean>',
'Include root project in execution',
'true'
)
.option(
'-c, --chunk-size <number>',
'Chunk size of parallel executions',
Expand All @@ -33,6 +38,7 @@ export function main(program: Command) {
.action(async function run(
commands: string[],
options?: {
includeRoot?: unknown;
cwd?: string;
chunkSize: string;
failFast: boolean;
Expand All @@ -42,7 +48,7 @@ export function main(program: Command) {
packageNameCommand: boolean;
}
): Promise<any> {
const {
let {
//
cwd: src,
chunkSize = 1,
Expand All @@ -51,6 +57,7 @@ export function main(program: Command) {
packages,
packageNameCommand,
from,
includeRoot,
} = options || {};

const ignoreList = ignore?.split(/, ?/);
Expand All @@ -60,6 +67,17 @@ export function main(program: Command) {
const runner = await packageRunner({
cwd: src,
failFast,
includeRoot: (() => {
if (typeof includeRoot === 'boolean') return includeRoot;

if (typeof includeRoot !== 'string') {
throw new Error(
`includeRoot received invalid value: ${includeRoot} `
);
}

return includeRoot === 'true';
})(),
});

if (packageNameCommand !== false) {
Expand Down
3 changes: 2 additions & 1 deletion packages/runmate/src/commands/set-json-value.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { chalk, jsonParse, nodePath, setByPath } from '@powership/utils';
import { jsonParse, setByPath } from '@powership/utils';
import { chalk, nodePath } from '@powership/utils/out/node-utils';
import { Command } from 'commander';

import { writePackageJSON } from '../handleJSON';
Expand Down
48 changes: 31 additions & 17 deletions packages/runmate/src/findWorkspacePackages.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,68 @@
import nodePath from 'path';
import * as path from 'path';
import process from 'process';

import fs from 'fs-extra';
import * as glob from 'glob';

import { PackageJson } from './ICommons';
import { readPackageJSON } from './handleJSON';

export type FindWorkspacePackagesInit = {
cwd?: string;
globCache?: any;
includeRoot?: boolean;
};

export type WorkspacePackagesFoundResult = ReturnType<
typeof findWorkspacePackages
>;

export function findWorkspacePackages(init?: FindWorkspacePackagesInit) {
const { cwd: rootDir = process.cwd(), globCache } = init || {};
const {
cwd: rootDir = process.cwd(),
globCache,
includeRoot = true,
} = init || {};

const pnpmWorkspaces = listPnpmWorkspaces(rootDir);
const packageJsonWorkspaces = listPackageJSONWorkspaces(rootDir);

const foundPatterns = pnpmWorkspaces?.length
let foundPatterns = pnpmWorkspaces?.length
? pnpmWorkspaces
: packageJsonWorkspaces?.length
? packageJsonWorkspaces
: null;

if (!foundPatterns) {
throw new Error('No workspaces config found.');
console.warn('⚠️ No workspaces config found.');
foundPatterns = [];
}

return foundPatterns.flatMap((pattern) => {
const found = glob.sync(nodePath.join(pattern, 'package.json'), {
cwd: rootDir,
absolute: true,
cache: globCache,
ignore: ['**/node_modules/**'],
});
if (includeRoot) {
foundPatterns.unshift('./');
}

return {
found,
pattern,
};
return foundPatterns.flatMap((pattern) => {
return glob
.sync(nodePath.join(pattern, 'package.json'), {
cwd: rootDir,
absolute: true,
cache: globCache,
ignore: ['**/node_modules/**'],
})
.flatMap((path) => {
return {
pattern,
path: path,
json: readPackageJSON(path),
relative: nodePath.relative(rootDir, nodePath.dirname(path)) || `./`,
};
});
});
}

function listPnpmWorkspaces(rootDir: string) {
const pnpmWorkspacePath = path.join(rootDir, 'pnpm-workspace.yaml');
const pnpmWorkspacePath = nodePath.join(rootDir, 'pnpm-workspace.yaml');

if (fs.existsSync(pnpmWorkspacePath)) {
const workspaceFileContent = fs.readFileSync(pnpmWorkspacePath, 'utf-8');
Expand All @@ -72,7 +86,7 @@ function listPnpmWorkspaces(rootDir: string) {
}

function listPackageJSONWorkspaces(rootDir: string) {
const packageJsonPath = path.join(rootDir, 'package.json');
const packageJsonPath = nodePath.join(rootDir, 'package.json');

if (fs.existsSync(packageJsonPath)) {
const packageJson = fs.readJSONSync(packageJsonPath) as PackageJson;
Expand Down
24 changes: 20 additions & 4 deletions packages/runmate/src/packageRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import nodePath from 'path';
import { inspect } from 'util';

import { chunk } from 'lodash';
import { logstorm } from 'logstorm';

import { DepTree, PackageItem } from './depTree';
import { findWorkspacePackages } from './findWorkspacePackages';
Expand Down Expand Up @@ -69,6 +70,7 @@ export interface PackageRunnerOptions {
cwd?: string;
cache?: boolean | Record<string, any>;
failFast?: boolean;
includeRoot?: boolean;
}

export interface PackageRunOptions {
Expand Down Expand Up @@ -103,6 +105,7 @@ export async function packageRunner(
cwd = process.cwd(),
cache: cacheOption = true,
failFast: failFastRoot = true,
includeRoot,
} = options;

const cache = (() => {
Expand All @@ -112,11 +115,24 @@ export async function packageRunner(
return undefined;
})();

const files = findWorkspacePackages({ globCache: cache, cwd }).flatMap(
(el) => el.found
);
const files = findWorkspacePackages({ globCache: cache, cwd, includeRoot });

(() => {
// force log
const level = logstorm.level;
const prefix = logstorm.prefix;
logstorm.level = 'info';
logstorm.prefix = false;
logstorm.info(
`Running command in:\n${(() => {
return files.map((el) => ` ‣ ${el.relative}`).join('\n');
})()}`
);
logstorm.level = level;
logstorm.prefix = prefix;
})();

const utils = files.map((file) => getPackageRunnerUtils(file));
const utils = files.map((file) => getPackageRunnerUtils(file.path));
const packages = reduceObject(utils, (item) => ({ [item.name]: item }));

const depTree = new DepTree(utils.map((el) => el.json)).find();
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powership/schema",
"version": "3.2.22",
"version": "3.2.24",
"type": "module",
"main": "./out/index.cjs",
"module": "./out/module/index.mjs",
Expand Down
4 changes: 3 additions & 1 deletion packages/schema/src/tsfy/tsfyWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import {
simpleObjectHash,
Store,
} from '@powership/utils';
import { ensureFileSync } from 'fs-extra';
import fsExtra from 'fs-extra';

import { GraphType } from '../GraphType/GraphType';
import { ObjectType } from '../ObjectType';

import { createTSFYContext, tsfy, TSFYConfig } from './tsfy';

const { ensureFileSync } = fsExtra;

export const defaultTypesDest = path.resolve(
Process.cwd(),
'generated/powership.d.ts'
Expand Down
Loading

0 comments on commit 6b5f6ce

Please sign in to comment.