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

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.30",
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,120 @@
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/dp-cloud/docupace-graphql-server.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
+ const nodeDocker = `
38
+ # Use a Node.js base image
39
+ FROM node:18
40
+
41
+ # Set the working directory inside the container
42
+ WORKDIR /app
43
+
44
+ # Install pnpm globally
45
+ RUN npm install -g pnpm
46
+
47
+ # Default command (can be overridden in the docker run command)
48
+ CMD ["node"]
49
+ `
50
+
51
+ async function versionCommand() {
52
+ console.log('📦 Running Changeset versioning...');
53
+ await setGitInfo();
54
+ await $`mv package.json package.json.bak`
55
+ await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`
56
+ await fs.promises.writeFile('package.json', changeSetPackage);
57
+ await $`pnpm install`;
58
+ await $`rm package.json pnpm-lock.yaml`
59
+ await $`mv package.json.bak package.json`
60
+ await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`
61
+ await $`pnpm changeset version`;
62
+ console.log('✅ Changeset versioning complete.');
63
+ }
64
+
65
+ async function commitTagCommand() {
66
+ console.log('📌 Committing and tagging the new version...');
67
+ await setGitInfo();
68
+ await $`git add .`;
69
+ await $`git commit -m "chore: version bump and changelog"`;
70
+ await $`git push origin`;
71
+ const newVersion = (await $`node -p "require('./package.json').version"`).stdout.trim();
72
+ await $`git tag v${newVersion}`;
73
+ await $`git push origin --tags`;
74
+ console.log(`✅ Version ${newVersion} tagged and pushed.`);
75
+ }
76
+
77
+ // Command: validate
78
+ program
79
+ .command('validate <path>')
80
+ .description('Validate changesets for the provided PR ID')
81
+ .action(async (path) => {
82
+ console.log('🔍 Validating changesets...');
83
+ try {
84
+ await validateChangesets(path);
85
+ console.log('✅ Changeset validation passed.');
86
+ } catch (error) {
87
+ console.error(
88
+ '❌ 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'
89
+ );
90
+ process.exit(1);
91
+ }
92
+ });
93
+ // Command: version
94
+ program
95
+ .command('version')
96
+ .description('Run Changeset versioning')
97
+ .action(async () => {
98
+ await versionCommand();
99
+ });
100
+
101
+ // Command: commit-and-tag
102
+ program
103
+ .command('commit-tag')
104
+ .description('Commit and tag the new version')
105
+ .action(async () => {
106
+ await commitTagCommand();
107
+ });
108
+
109
+ // Command: all
110
+ program
111
+ .command('version-commit-tag')
112
+ .description('Run versioning and commit-and-tag in sequence')
113
+ .action(async () => {
114
+ console.log('📦 Running all steps...');
115
+ await versionCommand();
116
+ await commitTagCommand();
117
+ });
118
+
119
+ // Parse arguments
120
+ 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
+