@proteinjs/build 1.0.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +21 -0
  3. package/build-workspace.js +7 -0
  4. package/build-workspace.js.LICENSE.txt +62 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +2 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/src/buildWorkspace.d.ts +3 -0
  10. package/dist/src/buildWorkspace.d.ts.map +1 -0
  11. package/dist/src/buildWorkspace.js +119 -0
  12. package/dist/src/buildWorkspace.js.map +1 -0
  13. package/dist/src/runBuildWorkspace.d.ts +3 -0
  14. package/dist/src/runBuildWorkspace.d.ts.map +1 -0
  15. package/dist/src/runBuildWorkspace.js +6 -0
  16. package/dist/src/runBuildWorkspace.js.map +1 -0
  17. package/dist/src/runTestWorkspace.d.ts +3 -0
  18. package/dist/src/runTestWorkspace.d.ts.map +1 -0
  19. package/dist/src/runTestWorkspace.js +6 -0
  20. package/dist/src/runTestWorkspace.js.map +1 -0
  21. package/dist/src/runWatchWorkspace.d.ts +3 -0
  22. package/dist/src/runWatchWorkspace.d.ts.map +1 -0
  23. package/dist/src/runWatchWorkspace.js +6 -0
  24. package/dist/src/runWatchWorkspace.js.map +1 -0
  25. package/dist/src/testWorkspace.d.ts +3 -0
  26. package/dist/src/testWorkspace.d.ts.map +1 -0
  27. package/dist/src/testWorkspace.js +109 -0
  28. package/dist/src/testWorkspace.js.map +1 -0
  29. package/dist/src/watchWorkspace.d.ts +3 -0
  30. package/dist/src/watchWorkspace.d.ts.map +1 -0
  31. package/dist/src/watchWorkspace.js +130 -0
  32. package/dist/src/watchWorkspace.js.map +1 -0
  33. package/index.ts +0 -0
  34. package/jest.config.js +18 -0
  35. package/package.json +47 -0
  36. package/src/buildWorkspace.ts +29 -0
  37. package/src/runBuildWorkspace.ts +5 -0
  38. package/src/runTestWorkspace.ts +5 -0
  39. package/src/runWatchWorkspace.ts +5 -0
  40. package/src/testWorkspace.ts +21 -0
  41. package/src/watchWorkspace.ts +55 -0
  42. package/tsconfig.json +23 -0
  43. package/webpack.config.js +26 -0
@@ -0,0 +1,29 @@
1
+ import * as path from 'path'
2
+ import { PackageUtil, WorkspaceMetadata, cmd } from '@proteinjs/util-node'
3
+ import { Logger } from '@proteinjs/util'
4
+
5
+ export async function buildWorkspace(workspaceMetadata?: WorkspaceMetadata) {
6
+ const logger = new Logger('buildWorkspace');
7
+ const workspacePath = process.cwd();
8
+ logger.info(`> Building workspace (${workspacePath})`);
9
+ const { packageMap, sortedPackageNames } = workspaceMetadata ? workspaceMetadata : await PackageUtil.getWorkspaceMetadata(workspacePath);
10
+ const filteredPackageNames = sortedPackageNames.filter(packageName => !!packageMap[packageName].packageJson.scripts?.build);
11
+ logger.debug(`packageMap:\n${JSON.stringify(packageMap, null, 2)}`, true);
12
+ logger.debug(`filteredPackageNames:\n${JSON.stringify(filteredPackageNames, null, 2)}`, true);
13
+
14
+ logger.info(`> Installing and building ${filteredPackageNames.length} package${filteredPackageNames.length != 1 ? 's' : ''} packages`);
15
+ for (let packageName of filteredPackageNames) {
16
+ const localPackage = packageMap[packageName];
17
+ const packageDir = path.dirname(localPackage.filePath);
18
+ await cmd('npm', ['install'], { cwd: packageDir });
19
+ await PackageUtil.symlinkDependencies(localPackage, packageMap, logger);
20
+ logger.info(`Installed ${packageName} (${packageDir})`);
21
+
22
+ if (packageName != 'typescript-parser') {
23
+ await cmd('npm', ['run', 'build'], { cwd: packageDir });
24
+ logger.info(`Built ${packageName} (${packageDir})`);
25
+ }
26
+ }
27
+
28
+ logger.info(`> Built workspace (${workspacePath})`);
29
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { buildWorkspace } from './buildWorkspace'
4
+
5
+ buildWorkspace();
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { testWorkspace } from './testWorkspace'
4
+
5
+ testWorkspace();
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { watchWorkspace } from './watchWorkspace'
4
+
5
+ watchWorkspace();
@@ -0,0 +1,21 @@
1
+ import * as path from 'path'
2
+ import { PackageUtil, cmd, WorkspaceMetadata } from '@proteinjs/util-node'
3
+ import { Logger } from '@proteinjs/util'
4
+
5
+ export const testWorkspace = async (workspaceMetadata?: WorkspaceMetadata) => {
6
+ const logger = new Logger('testWorkspace');
7
+ const workspacePath = process.cwd();
8
+ const { packageMap, sortedPackageNames } = workspaceMetadata ? workspaceMetadata : await PackageUtil.getWorkspaceMetadata(workspacePath);
9
+ const filteredPackageNames = sortedPackageNames.filter(packageName => !!packageMap[packageName].packageJson.scripts?.test && packageName != 'typescript-parser');
10
+
11
+ logger.info(`> Testing ${filteredPackageNames.length} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`);
12
+ for (let packageName of filteredPackageNames) {
13
+ const localPackage = packageMap[packageName];
14
+ const packageDir = path.dirname(localPackage.filePath);
15
+ if (!await PackageUtil.hasTests(packageDir))
16
+ continue;
17
+
18
+ await cmd('npm', ['run', 'test'], { cwd: packageDir });
19
+ }
20
+ logger.info(`> Finished testing ${filteredPackageNames.length} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`);
21
+ }
@@ -0,0 +1,55 @@
1
+ import * as path from 'path'
2
+ import { PackageUtil, WorkspaceMetadata, cmd } from '@proteinjs/util-node'
3
+ import { Logger } from '@proteinjs/util'
4
+
5
+ export const watchWorkspace = async (workspaceMetadata?: WorkspaceMetadata) => {
6
+ const logger = new Logger('watchWorkspace');
7
+ const workspacePath = process.cwd();
8
+ const { packageMap, sortedPackageNames } = workspaceMetadata ? workspaceMetadata : await PackageUtil.getWorkspaceMetadata(workspacePath);
9
+ const filteredPackageNames = sortedPackageNames.filter(packageName => !!packageMap[packageName].packageJson.scripts?.watch);
10
+
11
+ logger.info(`> Watching ${filteredPackageNames.length} package${filteredPackageNames.length != 1 ? 's' : ''} in workspace (${workspacePath})`);
12
+ const loggingStartDelay = 0;
13
+ for (let packageName of filteredPackageNames) {
14
+ const localPackage = packageMap[packageName];
15
+ const packageDir = path.dirname(localPackage.filePath);
16
+ const loggingEnabledState = { loggingEnabled: false };
17
+ setTimeout(() => loggingEnabledState.loggingEnabled = true, loggingStartDelay);
18
+ const logPrefix = `[${packageName}] `;
19
+ let inMultiLineLog = false;
20
+ const stdoutFilter = (log: string) => {
21
+ if (log.includes('File change detected. Starting incremental compilation'))
22
+ return;
23
+
24
+ let filteredOutput = log.replace(/\x1Bc|\x1B\[2J\x1B\[0;0H/g, ''); // char sequence for clearing terminal
25
+ if (filteredOutput.includes('Watching for file changes.'))
26
+ filteredOutput = filteredOutput.replace(/^\n/, '');
27
+
28
+ if (filteredOutput.trim() == '')
29
+ return;
30
+
31
+ // Replace newline with newline+prefix under the following conditions:
32
+ // 1. It is not at the start of the string (?<!^)
33
+ // 2. It is not at the end of the string (?!$)
34
+ // 3. It is not followed by another newline (?!\r?\n)
35
+ filteredOutput = filteredOutput.replace(/(?<!^)(\r?\n)(?!\r?\n|$)/g, `$1${logPrefix}`);
36
+
37
+ if (!inMultiLineLog)
38
+ filteredOutput = `${logPrefix}${filteredOutput}`;
39
+
40
+ if (filteredOutput.endsWith('\n') || filteredOutput.endsWith('\r\n'))
41
+ inMultiLineLog = false;
42
+ else
43
+ inMultiLineLog = true;
44
+
45
+ return filteredOutput;
46
+ };
47
+ cmd('npm', ['run', 'watch'], { cwd: packageDir }, {
48
+ omitLogs: {
49
+ stdout: {
50
+ filter: stdoutFilter,
51
+ }
52
+ },
53
+ });
54
+ }
55
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./",
4
+ "target": "es5",
5
+ "module": "commonjs",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "sourceMap": true,
9
+ "outDir": "./dist/",
10
+ "strict": true,
11
+ "noImplicitAny": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true,
16
+ "typeRoots": [
17
+ "./node_modules/@types"
18
+ ],
19
+ "types": [
20
+ "node", "jest"
21
+ ]
22
+ }
23
+ }
@@ -0,0 +1,26 @@
1
+ module.exports = {
2
+ target: 'node', // Ensures that webpack emulates Node.js environment
3
+ entry: './dist/src/runBuildWorkspace.js', // Entry point of your application
4
+ output: {
5
+ path: __dirname, // Output directory
6
+ filename: 'build-workspace.js' // Output file
7
+ },
8
+ module: {
9
+ rules: [
10
+ {
11
+ test: /\.js$/, // Include .js files
12
+ exclude: /node_modules/, // Exclude node_modules from babel-loader
13
+ use: {
14
+ loader: 'babel-loader', // Use babel-loader for transpiling
15
+ options: {
16
+ presets: ['@babel/preset-env']
17
+ }
18
+ }
19
+ },
20
+ // Add more rules for other file types if needed
21
+ ]
22
+ },
23
+ resolve: {
24
+ extensions: ['.js'], // File extensions to process
25
+ },
26
+ };