@proteinjs/build 1.3.1 → 1.4.1
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/.eslintrc.js +20 -0
- package/.prettierignore +4 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +32 -180
- package/dist/src/Github.d.ts.map +1 -1
- package/dist/src/Github.js +8 -4
- package/dist/src/Github.js.map +1 -1
- package/dist/src/bin/runBuildWorkspace.js.map +1 -1
- package/dist/src/bin/runCleanWorkspace.js.map +1 -1
- package/dist/src/bin/runLintWorkspace.d.ts +3 -0
- package/dist/src/bin/runLintWorkspace.d.ts.map +1 -0
- package/dist/src/bin/runLintWorkspace.js +6 -0
- package/dist/src/bin/runLintWorkspace.js.map +1 -0
- package/dist/src/bin/runSymlinkWorkspace.js.map +1 -1
- package/dist/src/bin/runTestWorkspace.js.map +1 -1
- package/dist/src/bin/runVersionWorkspace.js.map +1 -1
- package/dist/src/bin/runWatchWorkspace.js.map +1 -1
- package/dist/src/bin/runWorkspaceCommand.js.map +1 -1
- package/dist/src/bin/runWorkspacePackageCommand.js.map +1 -1
- package/dist/src/buildWorkspace.d.ts +1 -0
- package/dist/src/buildWorkspace.d.ts.map +1 -1
- package/dist/src/buildWorkspace.js +27 -9
- package/dist/src/buildWorkspace.js.map +1 -1
- package/dist/src/cleanWorkspace.d.ts.map +1 -1
- package/dist/src/cleanWorkspace.js.map +1 -1
- package/dist/src/lintWorkspace.d.ts +11 -0
- package/dist/src/lintWorkspace.d.ts.map +1 -0
- package/dist/src/lintWorkspace.js +171 -0
- package/dist/src/lintWorkspace.js.map +1 -0
- package/dist/src/symlinkWorkspace.d.ts.map +1 -1
- package/dist/src/symlinkWorkspace.js +2 -1
- package/dist/src/symlinkWorkspace.js.map +1 -1
- package/dist/src/testWorkspace.d.ts.map +1 -1
- package/dist/src/testWorkspace.js +2 -1
- package/dist/src/testWorkspace.js.map +1 -1
- package/dist/src/versionWorkspace.d.ts.map +1 -1
- package/dist/src/versionWorkspace.js +59 -31
- package/dist/src/versionWorkspace.js.map +1 -1
- package/dist/src/watchWorkspace.d.ts.map +1 -1
- package/dist/src/watchWorkspace.js +15 -8
- package/dist/src/watchWorkspace.js.map +1 -1
- package/dist/src/workspaceCommand.d.ts.map +1 -1
- package/dist/src/workspaceCommand.js +4 -3
- package/dist/src/workspaceCommand.js.map +1 -1
- package/dist/src/workspacePackageCommand.d.ts.map +1 -1
- package/dist/src/workspacePackageCommand.js +2 -1
- package/dist/src/workspacePackageCommand.js.map +1 -1
- package/jest.config.js +8 -17
- package/package.json +9 -3
- package/src/Github.ts +30 -27
- package/src/bin/runBuildWorkspace.ts +2 -2
- package/src/bin/runCleanWorkspace.ts +2 -2
- package/src/bin/runLintWorkspace.ts +5 -0
- package/src/bin/runSymlinkWorkspace.ts +2 -2
- package/src/bin/runTestWorkspace.ts +2 -2
- package/src/bin/runVersionWorkspace.ts +2 -2
- package/src/bin/runWatchWorkspace.ts +2 -2
- package/src/bin/runWorkspaceCommand.ts +2 -2
- package/src/bin/runWorkspacePackageCommand.ts +2 -2
- package/src/buildWorkspace.ts +38 -21
- package/src/cleanWorkspace.ts +17 -9
- package/src/lintWorkspace.ts +105 -0
- package/src/logColors.ts +1 -1
- package/src/symlinkWorkspace.ts +23 -16
- package/src/testWorkspace.ts +19 -10
- package/src/versionWorkspace.ts +173 -79
- package/src/watchWorkspace.ts +41 -24
- package/src/workspaceCommand.ts +26 -20
- package/src/workspacePackageCommand.ts +16 -11
- package/tsconfig.json +18 -22
- package/webpack.config.js +12 -12
package/src/cleanWorkspace.ts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
import * as path from 'path'
|
|
2
|
-
import { PackageUtil, cmd, WorkspaceMetadata } from '@proteinjs/util-node'
|
|
3
|
-
import { Logger } from '@proteinjs/util'
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { PackageUtil, cmd, WorkspaceMetadata } from '@proteinjs/util-node';
|
|
3
|
+
import { Logger } from '@proteinjs/util';
|
|
4
4
|
|
|
5
5
|
export const cleanWorkspace = async (workspaceMetadata?: WorkspaceMetadata) => {
|
|
6
6
|
const logger = new Logger('workspace:clean');
|
|
7
7
|
const workspacePath = process.cwd();
|
|
8
|
-
const { packageMap, sortedPackageNames } = workspaceMetadata
|
|
8
|
+
const { packageMap, sortedPackageNames } = workspaceMetadata
|
|
9
|
+
? workspaceMetadata
|
|
10
|
+
: await PackageUtil.getWorkspaceMetadata(workspacePath);
|
|
9
11
|
const skippedPackages = ['root'];
|
|
10
|
-
const filteredPackageNames = sortedPackageNames.filter(
|
|
12
|
+
const filteredPackageNames = sortedPackageNames.filter(
|
|
13
|
+
(packageName) => !!packageMap[packageName].packageJson.scripts?.clean && !skippedPackages.includes(packageName)
|
|
14
|
+
);
|
|
11
15
|
|
|
12
|
-
logger.info(
|
|
13
|
-
|
|
16
|
+
logger.info(
|
|
17
|
+
`> Cleaning ${filteredPackageNames.length} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`
|
|
18
|
+
);
|
|
19
|
+
for (const packageName of filteredPackageNames) {
|
|
14
20
|
const localPackage = packageMap[packageName];
|
|
15
21
|
const packageDir = path.dirname(localPackage.filePath);
|
|
16
22
|
await cmd('npm', ['run', 'clean'], { cwd: packageDir });
|
|
17
23
|
}
|
|
18
|
-
logger.info(
|
|
19
|
-
}
|
|
24
|
+
logger.info(
|
|
25
|
+
`> Finished cleaning ${filteredPackageNames.length} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { LocalPackageMap, LogColorWrapper, PackageUtil, cmd, parseArgsMap } from '@proteinjs/util-node';
|
|
4
|
+
import { Logger } from '@proteinjs/util';
|
|
5
|
+
import { primaryLogColor, secondaryLogColor } from './logColors';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Lint workspace, in dependency order.
|
|
9
|
+
*
|
|
10
|
+
* Optional args:
|
|
11
|
+
*
|
|
12
|
+
* --skip=@some/package,@another/package
|
|
13
|
+
*/
|
|
14
|
+
export async function lintWorkspace() {
|
|
15
|
+
const cw = new LogColorWrapper();
|
|
16
|
+
const logger = new Logger(cw.color('workspace:', primaryLogColor) + cw.color('lint', secondaryLogColor));
|
|
17
|
+
const args = getArgs();
|
|
18
|
+
const workspacePath = process.cwd();
|
|
19
|
+
const { packageMap, sortedPackageNames } = await PackageUtil.getWorkspaceMetadata(workspacePath);
|
|
20
|
+
const skippedPackages = ['root'];
|
|
21
|
+
const filteredPackageNames = sortedPackageNames.filter((packageName) => {
|
|
22
|
+
return (
|
|
23
|
+
hasLintConfig(packageMap, packageName) &&
|
|
24
|
+
!(args.skip && args.skip.includes(packageName)) &&
|
|
25
|
+
!skippedPackages.includes(packageName)
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
logger.info(
|
|
30
|
+
`> Linting ${cw.color(`${filteredPackageNames.length}`, secondaryLogColor)} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`
|
|
31
|
+
);
|
|
32
|
+
logger.debug(`packageMap:\n${JSON.stringify(packageMap, null, 2)}`, true);
|
|
33
|
+
logger.debug(`filteredPackageNames:\n${JSON.stringify(filteredPackageNames, null, 2)}`, true);
|
|
34
|
+
for (const packageName of filteredPackageNames) {
|
|
35
|
+
const localPackage = packageMap[packageName];
|
|
36
|
+
const packageDir = path.dirname(localPackage.filePath);
|
|
37
|
+
|
|
38
|
+
await cmd('npx', ['prettier', '.', '--write'], { cwd: packageDir }, { logPrefix: `[${cw.color(packageName)}] ` });
|
|
39
|
+
await cmd('npx', ['eslint', '.', '--fix'], { cwd: packageDir }, { logPrefix: `[${cw.color(packageName)}] ` });
|
|
40
|
+
logger.info(`Linted ${cw.color(packageName)} (${packageDir})`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
logger.info(
|
|
44
|
+
`> Linted ${cw.color(`${filteredPackageNames.length}`, secondaryLogColor)} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type Args = {
|
|
49
|
+
skip?: string[];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function getArgs() {
|
|
53
|
+
const args: Args = {};
|
|
54
|
+
const argsMap = parseArgsMap(process.argv.slice(2));
|
|
55
|
+
for (const argName in argsMap) {
|
|
56
|
+
const argValue = argsMap[argName];
|
|
57
|
+
if (argName == 'skip' && typeof argValue === 'string') {
|
|
58
|
+
args.skip = argValue.split(',');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return args;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const hasLintConfig = (packageMap: LocalPackageMap, packageName: string): boolean => {
|
|
66
|
+
const packageInfo = packageMap[packageName];
|
|
67
|
+
const directoryPath = path.dirname(packageInfo.filePath);
|
|
68
|
+
|
|
69
|
+
const getFilesInDirectory = (directoryPath: string): string[] => {
|
|
70
|
+
try {
|
|
71
|
+
return fs.readdirSync(directoryPath).map((file) => path.basename(file));
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.error(`Error reading directory ${directoryPath}:`, err);
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const files = getFilesInDirectory(directoryPath);
|
|
79
|
+
|
|
80
|
+
const prettierConfigs = [
|
|
81
|
+
'.prettierrc',
|
|
82
|
+
'.prettierrc.json',
|
|
83
|
+
'.prettierrc.yml',
|
|
84
|
+
'.prettierrc.yaml',
|
|
85
|
+
'.prettierrc.js',
|
|
86
|
+
'.prettierrc.cjs',
|
|
87
|
+
'prettier.config.js',
|
|
88
|
+
'prettier.config.cjs',
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
const eslintConfigs = [
|
|
92
|
+
'.eslintrc',
|
|
93
|
+
'.eslintrc.json',
|
|
94
|
+
'.eslintrc.yml',
|
|
95
|
+
'.eslintrc.yaml',
|
|
96
|
+
'.eslintrc.js',
|
|
97
|
+
'.eslintrc.cjs',
|
|
98
|
+
'eslint.config.js',
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
const hasPrettier = files.some((file) => prettierConfigs.includes(file));
|
|
102
|
+
const hasEslint = files.some((file) => eslintConfigs.includes(file));
|
|
103
|
+
|
|
104
|
+
return hasPrettier && hasEslint;
|
|
105
|
+
};
|
package/src/logColors.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const primaryLogColor = { r: 81, g: 0, b: 135 };
|
|
2
|
-
export const secondaryLogColor = { r: 253, g: 197, b: 0 };
|
|
2
|
+
export const secondaryLogColor = { r: 253, g: 197, b: 0 };
|
package/src/symlinkWorkspace.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { LogColorWrapper, PackageUtil, parseArgsMap } from '@proteinjs/util-node'
|
|
2
|
-
import { Logger } from '@proteinjs/util'
|
|
3
|
-
import { primaryLogColor, secondaryLogColor } from './logColors'
|
|
1
|
+
import { LogColorWrapper, PackageUtil, parseArgsMap } from '@proteinjs/util-node';
|
|
2
|
+
import { Logger } from '@proteinjs/util';
|
|
3
|
+
import { primaryLogColor, secondaryLogColor } from './logColors';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Symlink dependencies to local packages for each package in the workspace.
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* ie: `npx symlink-workspace --skip=@some/package,@another/package`
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
10
|
* Optional args:
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
12
|
* --skip=@some/package,@another/package
|
|
13
13
|
*/
|
|
14
14
|
export const symlinkWorkspace = async () => {
|
|
@@ -18,32 +18,39 @@ export const symlinkWorkspace = async () => {
|
|
|
18
18
|
const workspacePath = process.cwd();
|
|
19
19
|
const { packageMap, sortedPackageNames } = await PackageUtil.getWorkspaceMetadata(workspacePath);
|
|
20
20
|
const skippedPackages = ['root'];
|
|
21
|
-
const filteredPackageNames = sortedPackageNames.filter(
|
|
21
|
+
const filteredPackageNames = sortedPackageNames.filter(
|
|
22
|
+
(packageName) => !(args.skip && args.skip.includes(packageName)) && !skippedPackages.includes(packageName)
|
|
23
|
+
);
|
|
22
24
|
if (filteredPackageNames.length == 0) {
|
|
23
25
|
logger.info(`> There are no packages to symlink in workspace (${workspacePath})`);
|
|
24
26
|
return;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
logger.info(
|
|
28
|
-
|
|
29
|
+
logger.info(
|
|
30
|
+
`> Symlinking ${cw.color(`${filteredPackageNames.length}`, secondaryLogColor)} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`
|
|
31
|
+
);
|
|
32
|
+
for (const packageName of filteredPackageNames) {
|
|
29
33
|
const localPackage = packageMap[packageName];
|
|
30
34
|
await PackageUtil.symlinkDependencies(localPackage, packageMap, logger);
|
|
31
35
|
}
|
|
32
|
-
logger.info(
|
|
33
|
-
}
|
|
36
|
+
logger.info(
|
|
37
|
+
`> Symlinked ${cw.color(`${filteredPackageNames.length}`, secondaryLogColor)} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`
|
|
38
|
+
);
|
|
39
|
+
};
|
|
34
40
|
|
|
35
41
|
type Args = {
|
|
36
|
-
skip?: string[]
|
|
37
|
-
}
|
|
42
|
+
skip?: string[];
|
|
43
|
+
};
|
|
38
44
|
|
|
39
45
|
function getArgs() {
|
|
40
46
|
const args: Args = {};
|
|
41
47
|
const argsMap = parseArgsMap(process.argv.slice(2));
|
|
42
|
-
for (
|
|
48
|
+
for (const argName in argsMap) {
|
|
43
49
|
const argValue = argsMap[argName];
|
|
44
|
-
if (argName == 'skip' && typeof argValue === 'string')
|
|
50
|
+
if (argName == 'skip' && typeof argValue === 'string') {
|
|
45
51
|
args.skip = argValue.split(',');
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
return args;
|
|
49
|
-
}
|
|
56
|
+
}
|
package/src/testWorkspace.ts
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
import * as path from 'path'
|
|
2
|
-
import { PackageUtil, cmd, WorkspaceMetadata } from '@proteinjs/util-node'
|
|
3
|
-
import { Logger } from '@proteinjs/util'
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { PackageUtil, cmd, WorkspaceMetadata } from '@proteinjs/util-node';
|
|
3
|
+
import { Logger } from '@proteinjs/util';
|
|
4
4
|
|
|
5
5
|
export const testWorkspace = async (workspaceMetadata?: WorkspaceMetadata) => {
|
|
6
6
|
const logger = new Logger('workspace:test');
|
|
7
7
|
const workspacePath = process.cwd();
|
|
8
|
-
const { packageMap, sortedPackageNames } = workspaceMetadata
|
|
8
|
+
const { packageMap, sortedPackageNames } = workspaceMetadata
|
|
9
|
+
? workspaceMetadata
|
|
10
|
+
: await PackageUtil.getWorkspaceMetadata(workspacePath);
|
|
9
11
|
const skippedPackages = ['root'];
|
|
10
|
-
const filteredPackageNames = sortedPackageNames.filter(
|
|
12
|
+
const filteredPackageNames = sortedPackageNames.filter(
|
|
13
|
+
(packageName) => !!packageMap[packageName].packageJson.scripts?.test && !skippedPackages.includes(packageName)
|
|
14
|
+
);
|
|
11
15
|
|
|
12
|
-
logger.info(
|
|
13
|
-
|
|
16
|
+
logger.info(
|
|
17
|
+
`> Testing ${filteredPackageNames.length} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`
|
|
18
|
+
);
|
|
19
|
+
for (const packageName of filteredPackageNames) {
|
|
14
20
|
const localPackage = packageMap[packageName];
|
|
15
21
|
const packageDir = path.dirname(localPackage.filePath);
|
|
16
|
-
if (!await PackageUtil.hasTests(packageDir))
|
|
22
|
+
if (!(await PackageUtil.hasTests(packageDir))) {
|
|
17
23
|
continue;
|
|
24
|
+
}
|
|
18
25
|
|
|
19
26
|
await cmd('npm', ['run', 'test'], { cwd: packageDir });
|
|
20
27
|
}
|
|
21
|
-
logger.info(
|
|
22
|
-
}
|
|
28
|
+
logger.info(
|
|
29
|
+
`> Finished testing ${filteredPackageNames.length} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`
|
|
30
|
+
);
|
|
31
|
+
};
|