@docupace/pipeline 1.0.0-alpha.3 → 1.0.0-alpha.31

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.
@@ -1,5 +1,7 @@
1
1
  #!/bin/bash
2
2
  # bin/next-changeset-validate
3
3
 
4
+ DIR="$(cd "$(dirname "$0")" && pwd)/../@docupace/pipeline"
5
+
4
6
  # Pass all arguments to the actual script
5
- bash ./next/changeset.sh validate "$@"
7
+ bash $DIR/next/changeset.sh validate $2
package/next/changeset.sh CHANGED
@@ -8,6 +8,8 @@ DIR="$(cd "$(dirname "$0")" && pwd)"
8
8
  validate_changesets() {
9
9
  if [ ! -z "$PR_ID" ]; then
10
10
  echo "🔍 Validating changesets..."
11
+ echo "Current Dir $DIR"
12
+ echo "1=$1"
11
13
  pnpm node $DIR/validateChangeset.cjs $1 || {
12
14
  if [ $? -eq 1 ]; then
13
15
  echo "❌ No changeset found. Please add a changeset to this PR. Please see more information at https://docupacellc.atlassian.net/wiki/spaces/PM/pages/1350893571/Creating+changesets+for+Docupace+Next"
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
+
4
5
  const directoryPath = process.argv[2];
5
6
 
6
7
  try {
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.31",
4
4
  "description": "",
5
5
  "main": "index.js",
6
+ "type": "module",
6
7
  "bin": {
7
- "next-changeset-validate": "./bin/next-changeset-validate.sh"
8
+ "dp-changeset-cli": "src/changeset/cli.js"
8
9
  },
9
10
  "keywords": [
10
11
  "bash"
11
12
  ],
12
13
  "author": "",
13
14
  "license": "ISC",
14
- "scripts": {
15
- "next-changeset-validate": "bash next/changeset.sh validate"
15
+ "dependencies": {
16
+ "commander": "^12.1.0",
17
+ "zx": "^8.2.4"
18
+ },
19
+ "devDependencies": {
20
+ "esbuild": "^0.24.0"
16
21
  }
17
22
  }
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { $ } from 'zx';
4
+ import path from 'path';
5
+ import {validateChangesets} from "./validate.js";
6
+ import fs from 'fs';
7
+
8
+ const program = new Command();
9
+ const args = process.argv.slice(1);
10
+
11
+ const DIR = path.resolve(process.cwd());
12
+
13
+ // Helper function to set Git info
14
+ async function setGitInfo() {
15
+ await $`git config --global user.email "gitops@docupace.com"`;
16
+ await $`git config --global user.name "Gitops"`;
17
+ await $`git remote set-url origin https://x-token-auth:${process.env.THIS_REP_TOKEN}@bitbucket.org/${process.env.BITBUCKET_REPO_FULL_NAME}.git`;
18
+ }
19
+
20
+ const changeSetPackage = `{
21
+ "name": "changeset-package",
22
+ "version": "1.0.0",
23
+ "description": "",
24
+ "scripts": {
25
+ },
26
+ "type": "module",
27
+ "keywords": [],
28
+ "author": "",
29
+ "license": "ISC",
30
+ "dependencies": {},
31
+ "devDependencies": {
32
+ "@changesets/cli": "^2.27.10"
33
+ }
34
+ }
35
+ `
36
+
37
+ async function versionCommand() {
38
+ console.log('📦 Running Changeset versioning...');
39
+ await setGitInfo();
40
+ await $`mv package.json package.json.bak`
41
+ await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`
42
+ await fs.promises.writeFile('package.json', changeSetPackage);
43
+ await $`pnpm install`;
44
+ await $`rm package.json pnpm-lock.yaml`
45
+ await $`mv package.json.bak package.json`
46
+ await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`
47
+ await $`pnpm changeset version`;
48
+ console.log('✅ Changeset versioning complete.');
49
+ }
50
+
51
+ async function commitTagCommand() {
52
+ console.log('📌 Committing and tagging the new version...');
53
+ await setGitInfo();
54
+ await $`git add .`;
55
+ await $`git commit -m "chore: version bump and changelog"`;
56
+ await $`git push origin`;
57
+ const newVersion = (await $`node -p "require('./package.json').version"`).stdout.trim();
58
+ await $`git tag v${newVersion}`;
59
+ await $`git push origin --tags`;
60
+ console.log(`✅ Version ${newVersion} tagged and pushed.`);
61
+ }
62
+
63
+ // Command: validate
64
+ program
65
+ .command('validate <path>')
66
+ .description('Validate changesets for the provided PR ID')
67
+ .action(async (path) => {
68
+ console.log('🔍 Validating changesets...');
69
+ try {
70
+ await validateChangesets(path);
71
+ console.log('✅ Changeset validation passed.');
72
+ } catch (error) {
73
+ console.error(
74
+ '❌ No changeset found. Please add a changeset to this PR. Please see more information at https://docupacellc.atlassian.net/wiki/spaces/PM/pages/1350893571/Creating+changesets+for+Docupace+Next'
75
+ );
76
+ process.exit(1);
77
+ }
78
+ });
79
+ // Command: version
80
+ program
81
+ .command('version')
82
+ .description('Run Changeset versioning')
83
+ .action(async () => {
84
+ await versionCommand();
85
+ });
86
+
87
+ // Command: commit-and-tag
88
+ program
89
+ .command('commit-tag')
90
+ .description('Commit and tag the new version')
91
+ .action(async () => {
92
+ await commitTagCommand();
93
+ });
94
+
95
+ // Command: all
96
+ program
97
+ .command('version-commit-tag')
98
+ .description('Run versioning and commit-and-tag in sequence')
99
+ .action(async () => {
100
+ console.log('📦 Running all steps...');
101
+ await versionCommand();
102
+ await commitTagCommand();
103
+ });
104
+
105
+ // Parse arguments
106
+ program.parse(args);
@@ -0,0 +1,46 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ export async function validateChangesets(directoryPath) {
5
+ try {
6
+ // Step 1: Read the directory for md files excluding README.md
7
+ const allFiles = fs.readdirSync(directoryPath);
8
+ const mdFiles = allFiles.filter(file => file.endsWith('.md') && file !== 'README.md');
9
+
10
+ // Step 2: Check for pre.json and parse it
11
+ const preJsonPath = path.join(directoryPath, 'pre.json');
12
+ let preJson;
13
+
14
+ if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
15
+ console.error("Error: No pre.json and no md files found.");
16
+ process.exit(1);
17
+ }
18
+
19
+ if (fs.existsSync(preJsonPath)) {
20
+ preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
21
+
22
+ if(preJson.mode == 'pre') {
23
+ // Step 4a: Get list of changesets from pre.json
24
+ const changesets = preJson.changesets || [];
25
+ const changesetNames = changesets.map(change => change);
26
+
27
+ // Step 4b: Match files with the list of changesets
28
+ const mdFileNamesWithoutExt = mdFiles.map(file => path.basename(file, '.md'));
29
+ const unmatchedFiles = mdFileNamesWithoutExt.filter(fileName => !changesetNames.includes(fileName));
30
+
31
+ if (unmatchedFiles.length == 0) {
32
+ console.error("No new MD files found:", unmatchedFiles);
33
+ process.exit(1);
34
+ }
35
+ }
36
+ }
37
+
38
+ console.log("Validation successful.");
39
+ } catch (error) {
40
+ console.error("Error while processing:", error);
41
+ process.exit(1);
42
+ }
43
+ }
44
+
45
+
46
+