@docupace/pipeline 1.0.39-matttest.36 → 1.0.39-matttest.39
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/package.json +1 -1
- package/src/changeset/create.js +52 -29
- package/src/changeset/package-util.js +86 -0
package/package.json
CHANGED
package/src/changeset/create.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { $ } from 'zx';
|
|
2
1
|
import OpenAI from 'openai';
|
|
3
2
|
import z from 'zod';
|
|
4
3
|
import { zodResponseFormat } from 'openai/helpers/zod';
|
|
5
4
|
import fs from 'fs';
|
|
6
5
|
import path from 'path';
|
|
7
|
-
import { getAllAppPackages, getAllPackages, isMonoRepo } from '../next/util.js';
|
|
8
6
|
import inquirer from 'inquirer';
|
|
9
7
|
import { getMainPackage, getPackage } from './util.js';
|
|
8
|
+
import { getPackageNames } from './package-util.js';
|
|
9
|
+
import { execSync } from 'child_process';
|
|
10
10
|
|
|
11
11
|
async function createChangesetDirectory() {
|
|
12
12
|
try {
|
|
@@ -24,11 +24,18 @@ async function createChangesetDirectory() {
|
|
|
24
24
|
* Gets the current git branch name
|
|
25
25
|
*/
|
|
26
26
|
async function getCurrentBranch() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
try {
|
|
28
|
+
const branchName = execSync('git branch --show-current', {
|
|
29
|
+
encoding: 'utf8',
|
|
30
|
+
shell: true,
|
|
31
|
+
}).trim();
|
|
32
|
+
console.log(`Current branch: ${branchName}`);
|
|
33
|
+
return branchName;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error('Error getting current branch:', error.message);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
30
38
|
}
|
|
31
|
-
|
|
32
39
|
/**
|
|
33
40
|
* Extracts a Jira ticket ID from a branch name
|
|
34
41
|
*/
|
|
@@ -103,14 +110,14 @@ async function generateReleaseNotes(jiraTicketData) {
|
|
|
103
110
|
/**
|
|
104
111
|
* Writes the changeset file
|
|
105
112
|
*/
|
|
106
|
-
async function writeChangesetFile(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
async function writeChangesetFile(packages, jiraTicketId, changeType, summary) {
|
|
114
|
+
// Generate the YAML frontmatter for multiple packages
|
|
115
|
+
const packageEntries = packages
|
|
116
|
+
.map((pkg) => `'${pkg.name}': ${changeType}`)
|
|
117
|
+
.join('\n');
|
|
118
|
+
|
|
112
119
|
const changesetContent = `---
|
|
113
|
-
|
|
120
|
+
${packageEntries}
|
|
114
121
|
---
|
|
115
122
|
|
|
116
123
|
${summary} [${jiraTicketId}]
|
|
@@ -127,31 +134,47 @@ ${summary} [${jiraTicketId}]
|
|
|
127
134
|
*/
|
|
128
135
|
|
|
129
136
|
export async function createChangeset() {
|
|
130
|
-
|
|
131
|
-
|
|
137
|
+
const packages = getPackageNames();
|
|
138
|
+
|
|
139
|
+
if (packages.length > 1) {
|
|
140
|
+
const allPackages = packages;
|
|
132
141
|
const response = await inquirer.prompt([
|
|
133
142
|
{
|
|
134
|
-
type: '
|
|
135
|
-
name: '
|
|
136
|
-
message: 'Which
|
|
137
|
-
choices: allPackages.map((appPackage) =>
|
|
143
|
+
type: 'checkbox',
|
|
144
|
+
name: 'packages',
|
|
145
|
+
message: 'Which packages do you want to generate changesets for?',
|
|
146
|
+
choices: allPackages.map((appPackage) => ({
|
|
147
|
+
name: appPackage.name,
|
|
148
|
+
value: appPackage.name,
|
|
149
|
+
})),
|
|
150
|
+
validate: (input) => {
|
|
151
|
+
if (input.length === 0) {
|
|
152
|
+
return 'Please select at least one package.';
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
},
|
|
138
156
|
},
|
|
139
157
|
]);
|
|
140
158
|
|
|
141
|
-
const
|
|
142
|
-
(appPackage
|
|
159
|
+
const selectedPackages = allPackages.filter((appPackage) =>
|
|
160
|
+
response.packages.includes(appPackage.name),
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
// Get package contents for all selected packages
|
|
164
|
+
const selectedPackageContents = await Promise.all(
|
|
165
|
+
selectedPackages.map(async (selectedPackage) => {
|
|
166
|
+
return await getPackage(selectedPackage.path);
|
|
167
|
+
}),
|
|
143
168
|
);
|
|
144
169
|
|
|
145
|
-
|
|
146
|
-
await createChangesetForPackage(selectedPackageContent);
|
|
170
|
+
await createChangesetForPackage(selectedPackageContents);
|
|
147
171
|
} else {
|
|
148
172
|
const mainPackage = await getMainPackage();
|
|
149
|
-
await createChangesetForPackage(mainPackage);
|
|
173
|
+
await createChangesetForPackage([mainPackage]);
|
|
150
174
|
}
|
|
151
175
|
}
|
|
152
176
|
|
|
153
|
-
export async function createChangesetForPackage(
|
|
154
|
-
const componentName = mainPackage.name;
|
|
177
|
+
export async function createChangesetForPackage(packages) {
|
|
155
178
|
try {
|
|
156
179
|
// Step 1: Get the current branch name
|
|
157
180
|
const branchName = await getCurrentBranch();
|
|
@@ -171,10 +194,10 @@ export async function createChangesetForPackage(mainPackage) {
|
|
|
171
194
|
console.log(`Change type: ${change_type}`);
|
|
172
195
|
console.log(`Release note: ${summary}`);
|
|
173
196
|
|
|
174
|
-
// Step 5: Create a changeset .md file
|
|
175
|
-
await writeChangesetFile(
|
|
197
|
+
// Step 5: Create a changeset .md file for all packages
|
|
198
|
+
await writeChangesetFile(packages, jiraTicketId, change_type, summary);
|
|
176
199
|
|
|
177
|
-
console.log('
|
|
200
|
+
console.log('Changeset created successfully!');
|
|
178
201
|
} catch (err) {
|
|
179
202
|
console.error(`Error: ${err.message}`);
|
|
180
203
|
process.exit(1);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
export function getPackageNames(rootPath = '.') {
|
|
5
|
+
const appsDir = path.join(rootPath, 'apps');
|
|
6
|
+
const packagesDir = path.join(rootPath, 'packages');
|
|
7
|
+
const rootPackageJson = path.join(rootPath, 'package.json');
|
|
8
|
+
|
|
9
|
+
// Check if this is a monorepo (has apps and/or packages directories)
|
|
10
|
+
const hasAppsDir =
|
|
11
|
+
fs.existsSync(appsDir) && fs.statSync(appsDir).isDirectory();
|
|
12
|
+
const hasPackagesDir =
|
|
13
|
+
fs.existsSync(packagesDir) && fs.statSync(packagesDir).isDirectory();
|
|
14
|
+
|
|
15
|
+
if (hasAppsDir || hasPackagesDir) {
|
|
16
|
+
// This is a monorepo
|
|
17
|
+
const packages = [];
|
|
18
|
+
|
|
19
|
+
// Get packages from apps directory
|
|
20
|
+
if (hasAppsDir) {
|
|
21
|
+
const appsPackages = getPackagesFromDirectory(appsDir);
|
|
22
|
+
packages.push(...appsPackages);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Get packages from packages directory
|
|
26
|
+
if (hasPackagesDir) {
|
|
27
|
+
const packagesPackages = getPackagesFromDirectory(packagesDir);
|
|
28
|
+
packages.push(...packagesPackages);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return packages;
|
|
32
|
+
} else {
|
|
33
|
+
// This is not a monorepo, return single package
|
|
34
|
+
if (fs.existsSync(rootPackageJson)) {
|
|
35
|
+
try {
|
|
36
|
+
const packageJson = JSON.parse(
|
|
37
|
+
fs.readFileSync(rootPackageJson, 'utf8'),
|
|
38
|
+
);
|
|
39
|
+
return packageJson.name
|
|
40
|
+
? [{ name: packageJson.name, path: rootPath }]
|
|
41
|
+
: [];
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('Error reading root package.json:', error);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getPackagesFromDirectory(dirPath) {
|
|
52
|
+
const packages = [];
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const items = fs.readdirSync(dirPath);
|
|
56
|
+
|
|
57
|
+
for (const item of items) {
|
|
58
|
+
const itemPath = path.join(dirPath, item);
|
|
59
|
+
const packageJsonPath = path.join(itemPath, 'package.json');
|
|
60
|
+
|
|
61
|
+
// Check if item is a directory and has package.json
|
|
62
|
+
if (
|
|
63
|
+
fs.statSync(itemPath).isDirectory() &&
|
|
64
|
+
fs.existsSync(packageJsonPath)
|
|
65
|
+
) {
|
|
66
|
+
try {
|
|
67
|
+
const packageJson = JSON.parse(
|
|
68
|
+
fs.readFileSync(packageJsonPath, 'utf8'),
|
|
69
|
+
);
|
|
70
|
+
if (packageJson.name) {
|
|
71
|
+
packages.push({
|
|
72
|
+
name: packageJson.name,
|
|
73
|
+
path: itemPath,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error(`Error reading package.json in ${itemPath}:`, error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error(`Error reading directory ${dirPath}:`, error);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return packages;
|
|
86
|
+
}
|