@docupace/pipeline 1.0.5-4.ervins → 1.0.5-alpha.0

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 (46) hide show
  1. package/.prettierrc.cjs +12 -12
  2. package/bin/next-changeset-validate.sh +8 -8
  3. package/eslint.config.js +1 -1
  4. package/next/changeset.sh +75 -75
  5. package/next/copy.sh +34 -34
  6. package/next/deploy.sh +40 -40
  7. package/next/execute.sh +117 -123
  8. package/next/sonar.sh +23 -23
  9. package/package.json +35 -50
  10. package/src/changeset/cli.js +254 -200
  11. package/src/changeset/validate.js +47 -84
  12. package/src/next/cli.js +72 -228
  13. package/src/next/config.js +0 -96
  14. package/src/next/copy.js +30 -61
  15. package/src/next/deploy.js +249 -595
  16. package/src/next/publish.js +48 -71
  17. package/src/next/pull.js +7 -7
  18. package/src/next/sonar.js +23 -23
  19. package/README.md +0 -136
  20. package/bin/azuread_update_callbacks_for_app.sh +0 -58
  21. package/src/auth0/alias.js +0 -72
  22. package/src/auth0/cli.js +0 -76
  23. package/src/auth0/configure.js +0 -783
  24. package/src/auth0/export.js +0 -43
  25. package/src/auth0/metadata.js +0 -132
  26. package/src/auth0/vault.js +0 -107
  27. package/src/changeset/changeset-config.js +0 -34
  28. package/src/changeset/create.js +0 -205
  29. package/src/changeset/package-util.js +0 -86
  30. package/src/changeset/util.js +0 -43
  31. package/src/changeset/version.js +0 -102
  32. package/src/jenkins/setParams.groovy +0 -58
  33. package/src/next/alias.js +0 -53
  34. package/src/next/apache.js +0 -73
  35. package/src/next/connect.js +0 -227
  36. package/src/next/haproxy.js +0 -71
  37. package/src/next/jenkins.js +0 -123
  38. package/src/next/jira.js +0 -84
  39. package/src/next/logger.js +0 -17
  40. package/src/next/pipline.js +0 -114
  41. package/src/next/util.js +0 -93
  42. package/src/next/vault.js +0 -45
  43. package/terraform/apply.sh +0 -37
  44. package/terraform/init.sh +0 -72
  45. package/terraform/plan.sh +0 -76
  46. package/terraform/validate.sh +0 -17
@@ -1,43 +0,0 @@
1
- import { getVaultSecrets } from './vault.js';
2
- import { getVaultSecretsConfigs } from '../next/config.js';
3
- import { dump } from 'auth0-deploy-cli';
4
-
5
- export async function exportConf(site, env) {
6
- try {
7
- console.log(
8
- `Exporting Auth0 configuration for site: ${site} and env: ${env}`,
9
- );
10
-
11
- const siteCommonSecretsPath =
12
- getVaultSecretsConfigs(site).siteCommonSecretsPath;
13
- console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`);
14
- const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
15
-
16
- const auth0Domain = `docupace-${env}-${site}.us.auth0.com`;
17
- const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
18
- const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
19
-
20
- const config = {
21
- config: {
22
- AUTH0_DOMAIN: auth0Domain,
23
- AUTH0_CLIENT_ID: auth0ClientId,
24
- AUTH0_CLIENT_SECRET: auth0ClientSecret,
25
- },
26
- format: 'directory',
27
- output_folder: `./auth0-${site}-export`,
28
- export_ids: false,
29
- env: false,
30
- debug: true,
31
- };
32
-
33
- console.log(`Starting Auth0 ${site} configuration export...`);
34
- await dump(config);
35
- console.log(`Auth0 ${site} configuration export completed successfully!`);
36
- } catch (error) {
37
- console.error(
38
- `Error during Auth0 ${site} configuration export:`,
39
- error.message,
40
- );
41
- process.exit(1);
42
- }
43
- }
@@ -1,132 +0,0 @@
1
- import fs from 'fs-extra';
2
- import axios from 'axios';
3
- import path from 'path';
4
- import { cloneRepository, pushDeployConfig } from '../next/deploy.js';
5
- import { getAuth0AuthToken } from './configure.js';
6
- import { getVaultSecrets } from './vault.js';
7
- import { getVaultSecretsConfigs } from '../next/config.js';
8
-
9
- export async function getAuth0Metadata(site, env) {
10
- try {
11
- const connectDeployRepoPath = await cloneRepository('connect-deploy');
12
-
13
- // mapping of env to env
14
- const envMap = {
15
- dev: 'dev',
16
- preprod: 'qa',
17
- stage: 'stage',
18
- uat: 'uat',
19
- 'prod-www3': 'prod',
20
- };
21
- process.chdir(`${connectDeployRepoPath}/envs/${env}/${site}`);
22
-
23
- const configPath = path.join('conf', 'application.conf');
24
- const appConf = await fs.readFile(configPath, 'utf-8');
25
- const connectContext = appConf.match(
26
- /application\.context\s*=\s*"(.*?)"/,
27
- )?.[1];
28
-
29
- if (!connectContext) {
30
- console.error('connectContext not found in application.conf. Exiting...');
31
- process.exit(1);
32
- }
33
-
34
- const siteHost = appConf.match(
35
- /docupace\.baseUrlClient\s*=\s*"?https?:\/\/([^/]+)"?/,
36
- )?.[1];
37
-
38
- if (!siteHost) {
39
- console.error('siteHost not found in application.conf. Exiting...');
40
- process.exit(1);
41
- }
42
-
43
- const connectEndpoint = `https://${siteHost}${connectContext}`;
44
- console.log('CONNECT_ENDPOINT:', connectEndpoint);
45
-
46
- console.log('Requesting token from Auth0...');
47
- const siteCommonSecretsPath =
48
- getVaultSecretsConfigs(site).siteCommonSecretsPath;
49
- console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`);
50
- const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
51
- const auth0Domain = `docupace-${envMap[env]}-${site}.us.auth0.com`;
52
- const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
53
- const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
54
- const auth0Token = await getAuth0AuthToken(
55
- auth0Domain,
56
- auth0ClientId,
57
- auth0ClientSecret,
58
- );
59
-
60
- const auth0Response = await axios.get(
61
- `https://${auth0Domain}/api/v2/clients`,
62
- {
63
- headers: { authorization: `Bearer ${auth0Token}` },
64
- },
65
- );
66
-
67
- const connectClient = auth0Response.data.find(
68
- (client) => client.name === 'docupace-connect',
69
- );
70
-
71
- if (!connectClient) {
72
- console.error('Client "docupace-connect" not found.');
73
- process.exit(1);
74
- }
75
-
76
- const clientId = connectClient.client_id;
77
- console.log('Found client_id:', clientId);
78
-
79
- const metadataRes = await axios.get(
80
- `https://${auth0Domain}/samlp/metadata/${clientId}`,
81
- {
82
- responseType: 'text',
83
- },
84
- );
85
-
86
- const metadata = metadataRes.data;
87
-
88
- if (metadata.length < 2000) {
89
- console.error(
90
- 'Downloaded metadata looks incorrect (too small). Exiting...',
91
- );
92
- process.exit(1);
93
- }
94
- await fs.ensureDir('conf/saml');
95
- await fs.writeFile('conf/saml/auth0.xml', metadata);
96
- console.log('SAML metadata written to conf/saml/auth0.xml');
97
-
98
- let newConfig = appConf;
99
-
100
- if (/useSAML\s*=/.test(appConf)) {
101
- newConfig = newConfig.replace(/useSAML\s*=.*/, 'useSAML=true');
102
- } else {
103
- newConfig += '\nuseSAML=true';
104
- }
105
-
106
- const replacements = {
107
- 'saml.clients.auth0.idpMetadataPath': '${samlEnvPath}"/auth0.xml"',
108
- 'saml.clients.auth0.spEntityId': `"${connectEndpoint}"`,
109
- 'saml.clients.auth0.redirectFormInput': '"RelayState"',
110
- 'saml.clients.auth0.idpLoginUrl': `"https://${auth0Domain}/v2/logout?client_id=${clientId}&returnTo=${connectEndpoint}"`,
111
- };
112
-
113
- for (const [key, value] of Object.entries(replacements)) {
114
- const pattern = new RegExp(`${key}\\s*=.*`, 'g');
115
- if (pattern.test(newConfig)) {
116
- newConfig = newConfig.replace(pattern, `${key}=${value}`);
117
- } else {
118
- newConfig += `\n${key}=${value}`;
119
- }
120
- }
121
-
122
- await fs.writeFile(configPath, newConfig);
123
- console.log('The application.conf has been updated.');
124
- await pushDeployConfig(
125
- connectDeployRepoPath,
126
- `Auth0 SAML metadata update for site: (${site}) in env: (${env})`,
127
- );
128
- } catch (error) {
129
- console.error('Error:', error.message);
130
- process.exit(1);
131
- }
132
- }
@@ -1,107 +0,0 @@
1
- import axios from 'axios';
2
-
3
- /**
4
- * Fetch secrets from Vault.
5
- * @param {string} vaultPath - The path in Vault to fetch secrets from.
6
- * @returns {Promise<Object>} - The secret data as a JSON object.
7
- */
8
- export async function getVaultSecrets(vaultPath) {
9
- if (!vaultPath) {
10
- console.error('Error: VAULT_PATH is required.');
11
- throw new Error('VAULT_PATH is required.');
12
- }
13
-
14
- const vaultToken = process.env.VAULT_TOKEN;
15
- const vaultAddr = process.env.VAULT_ADDR;
16
-
17
- if (!vaultToken || !vaultAddr) {
18
- console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
19
- throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
20
- }
21
-
22
- try {
23
- // Disable SSL verification globally by setting environment variable
24
- if (process.env.VAULT_SKIP_VERIFY === 'true') {
25
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
26
- }
27
-
28
- // Fetch the secret from Vault
29
- const response = await axios.get(`${vaultAddr}/v1/${vaultPath}`, {
30
- headers: {
31
- 'X-Vault-Token': vaultToken,
32
- },
33
- });
34
-
35
- // Validate the response contains JSON data
36
- const data = response.data;
37
- if (data && typeof data === 'object') {
38
- // console.log(`Secrets fetched successfully from Vault at ${JSON.stringify(data.data.data)})`);
39
- return data.data.data;
40
- } else {
41
- console.error('Error: Invalid JSON received from Vault.');
42
- throw new Error('Invalid JSON received from Vault.');
43
- }
44
- } catch (error) {
45
- if (error.response) {
46
- console.error(
47
- `Error: Failed to connect to Vault server at ${vaultAddr}. Response: ${error.response.status} ${error.response.statusText}`,
48
- );
49
- } else {
50
- console.error(`Error: ${error.message}`);
51
- }
52
- // throw error;
53
- }
54
- }
55
-
56
- /**
57
- * Update a secret in Vault.
58
- * @param {string} vaultPath - The path in Vault where the secret should be updated.
59
- * @param {Object} secretData - The secret data to be stored (as a JSON object).
60
- * @returns {Promise<Object>} - The response from Vault as a JSON object.
61
- */
62
- export async function updateVaultSecrets(vaultPath, secretData) {
63
- if (!vaultPath || !secretData) {
64
- console.error('Usage: updateVaultSecret(vaultPath, secretData)');
65
- throw new Error('Both vaultPath and secretData are required.');
66
- }
67
-
68
- const vaultToken = process.env.VAULT_TOKEN;
69
- const vaultAddr = process.env.VAULT_ADDR;
70
-
71
- if (!vaultToken || !vaultAddr) {
72
- console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
73
- throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
74
- }
75
-
76
- try {
77
- // Disable SSL verification globally if VAULT_SKIP_VERIFY is set
78
- if (process.env.VAULT_SKIP_VERIFY === 'true') {
79
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
80
- }
81
-
82
- // Make the POST request to update the Vault secret
83
- const response = await axios.post(
84
- `${vaultAddr}/v1/${vaultPath}`,
85
- secretData,
86
- {
87
- headers: {
88
- 'X-Vault-Token': vaultToken,
89
- 'Content-Type': 'application/json',
90
- },
91
- },
92
- );
93
-
94
- // Return the response from Vault
95
- console.log(response.data);
96
- return response.data;
97
- } catch (error) {
98
- if (error.response) {
99
- console.error(
100
- `Error: Failed to update secret at ${vaultPath}. Response: ${error.response.status} ${error.response.statusText}`,
101
- );
102
- } else {
103
- console.error(`Error: ${error.message}`);
104
- }
105
- // throw error;
106
- }
107
- }
@@ -1,34 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
-
4
- // Get absolute path to .changeset/config.json using current working directory
5
- const configPath = path.join(process.cwd(), '.changeset', 'config.json');
6
-
7
- // Function to update baseBranch to BITBUCKET_BRANCH
8
- export function updateBaseBranch() {
9
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
10
- if (!process.env.BITBUCKET_BRANCH) {
11
- return null;
12
- }
13
- let originalbaseBranch = config.baseBranch;
14
- config.baseBranch = process.env.BITBUCKET_BRANCH;
15
-
16
- if (!config.baseBranch) {
17
- throw new Error('BITBUCKET_BRANCH environment variable is not set.');
18
- }
19
-
20
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
21
- console.log(`baseBranch updated to ${process.env.BITBUCKET_BRANCH}`);
22
-
23
- return originalbaseBranch;
24
- }
25
-
26
- // Function to revert baseBranch to original value
27
- export function revertBaseBranch(originalBaseBranch) {
28
- if (!originalBaseBranch) return;
29
-
30
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
31
- config.baseBranch = originalBaseBranch;
32
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
33
- console.log(`baseBranch reverted to ${originalBaseBranch}`);
34
- }
@@ -1,205 +0,0 @@
1
- import OpenAI from 'openai';
2
- import z from 'zod';
3
- import { zodResponseFormat } from 'openai/helpers/zod';
4
- import fs from 'fs';
5
- import path from 'path';
6
- import inquirer from 'inquirer';
7
- import { getMainPackage, getPackage, findJiraTicketId } from './util.js';
8
- import { getPackageNames } from './package-util.js';
9
- import { execSync } from 'child_process';
10
-
11
- async function createChangesetDirectory() {
12
- try {
13
- // Use path.join to build a safe path to `.changeset`
14
- const targetDir = path.join(process.cwd(), '.changeset');
15
-
16
- // Create the directory recursively if it doesn't exist
17
- await fs.promises.mkdir(targetDir, { recursive: true });
18
- } catch (error) {
19
- console.error('Error creating .changeset directory:', error);
20
- }
21
- }
22
-
23
- /**
24
- * Gets the current git branch name
25
- */
26
- async function getCurrentBranch() {
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
- }
38
- }
39
- /**
40
- * Extracts a Jira ticket ID from a branch name
41
- */
42
- function extractJiraTicketId(branchName) {
43
- const jiraTicketId = findJiraTicketId(branchName);
44
- if (!jiraTicketId) {
45
- throw new Error('No Jira ticket found in the branch name.');
46
- }
47
- return jiraTicketId;
48
- }
49
-
50
- /**
51
- * Fetches Jira ticket data from Jira API
52
- */
53
- async function fetchJiraTicketData(jiraTicketId) {
54
- const jiraBaseUrl = 'https://docupacellc.atlassian.net';
55
- const jiraEmail = process.env.JIRA_API_EMAIL;
56
- const jiraApiKey = process.env.JIRA_API_KEY;
57
- const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
58
- const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
59
-
60
- const jiraResponse = await fetch(jiraUrl, {
61
- headers: {
62
- Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
63
- 'Content-Type': 'application/json',
64
- },
65
- });
66
-
67
- if (!jiraResponse.ok) {
68
- throw new Error(
69
- `Failed to fetch Jira ticket ${jiraTicketId}. Status: ${jiraResponse.status}, Ticket URL: ${jiraUrl}`,
70
- );
71
- }
72
-
73
- return await jiraResponse.json();
74
- }
75
-
76
- /**
77
- * Generates release notes using OpenAI
78
- */
79
- async function generateReleaseNotes(jiraTicketData) {
80
- const openaiClient = new OpenAI({
81
- apiKey: process.env['OPENAI_API_KEY'],
82
- });
83
-
84
- const ChangeRequestSchema = z.object({
85
- change_type: z.enum(['patch', 'minor']),
86
- summary: z.string(),
87
- jira_ticket_id: z.string(),
88
- });
89
-
90
- const openAiResponse = await openaiClient.chat.completions.create({
91
- model: 'gpt-4o-mini',
92
- messages: [
93
- {
94
- role: 'system',
95
- content: `Process JSON from a Jira ticket to generate simple maximum 2 sentence release note for the ticket and determine the change type for bug it should be a patch for new feature it should be a minor change`,
96
- },
97
- {
98
- role: 'user',
99
- content: JSON.stringify(jiraTicketData),
100
- },
101
- ],
102
- response_format: zodResponseFormat(ChangeRequestSchema, 'changeset_schema'),
103
- temperature: 0,
104
- });
105
-
106
- const assistantResponse = openAiResponse.choices[0].message.content;
107
- return JSON.parse(assistantResponse);
108
- }
109
-
110
- /**
111
- * Writes the changeset file
112
- */
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
-
119
- const changesetContent = `---
120
- ${packageEntries}
121
- ---
122
-
123
- ${summary} [${jiraTicketId}]
124
- `;
125
- const changesetFile = `./.changeset/${jiraTicketId}.md`;
126
-
127
- await createChangesetDirectory();
128
- await fs.promises.writeFile(changesetFile, changesetContent);
129
- console.log(`Created changeset file at ${changesetFile}`);
130
- }
131
-
132
- /**
133
- * Main function to create a changeset
134
- */
135
-
136
- export async function createChangeset() {
137
- const packages = getPackageNames();
138
-
139
- if (packages.length > 1) {
140
- const allPackages = packages;
141
- const response = await inquirer.prompt([
142
- {
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
- },
156
- },
157
- ]);
158
-
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
- }),
168
- );
169
-
170
- await createChangesetForPackage(selectedPackageContents);
171
- } else {
172
- const mainPackage = await getMainPackage();
173
- await createChangesetForPackage([mainPackage]);
174
- }
175
- }
176
-
177
- export async function createChangesetForPackage(packages) {
178
- try {
179
- // Step 1: Get the current branch name
180
- const branchName = await getCurrentBranch();
181
-
182
- // Step 2: Extract Jira ticket number
183
- const jiraTicketId = extractJiraTicketId(branchName);
184
-
185
- // Step 3: Fetch Jira ticket data
186
- const jiraTicketData = await fetchJiraTicketData(jiraTicketId);
187
- const jiraSummary = jiraTicketData.fields.summary;
188
- console.log(
189
- `Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
190
- );
191
-
192
- // Step 4: Generate release notes using OpenAI
193
- const { change_type, summary } = await generateReleaseNotes(jiraTicketData);
194
- console.log(`Change type: ${change_type}`);
195
- console.log(`Release note: ${summary}`);
196
-
197
- // Step 5: Create a changeset .md file for all packages
198
- await writeChangesetFile(packages, jiraTicketId, change_type, summary);
199
-
200
- console.log('Changeset created successfully!');
201
- } catch (err) {
202
- console.error(`Error: ${err.message}`);
203
- process.exit(1);
204
- }
205
- }
@@ -1,86 +0,0 @@
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
- }
@@ -1,43 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs';
3
-
4
- async function fileExists(filePath) {
5
- try {
6
- await fs.promises.access(filePath);
7
- return true;
8
- } catch {
9
- return false;
10
- }
11
- }
12
- export async function getMainPackage() {
13
- const mainModulePath = process.cwd();
14
- return getPackage(mainModulePath);
15
- }
16
-
17
- export async function getPackage(mainModulePath) {
18
- if (mainModulePath) {
19
- const packageJsonPath = path.join(mainModulePath, 'package.json');
20
- if (await fileExists(packageJsonPath)) {
21
- const fileContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
22
- const packageJson = JSON.parse(fileContent);
23
- return packageJson;
24
- }
25
- }
26
- throw new Error('Main package.json not found');
27
- }
28
-
29
- /**
30
- * Locates and extracts a JIRA Ticket ID from a given string.
31
- * <p>
32
- * The JIRA Ticket ID is expected to follow the pattern of uppercase letters (at least two) followed by a hyphen and digits (e.g., DC-1234, INFP-9).
33
- * @param str the string to search for a JIRA ticket ID
34
- * @returns {JIRA-TicketID|null}
35
- */
36
- export function findJiraTicketId(str) {
37
- if (!str) {
38
- return null;
39
- }
40
- const regex = /([A-Z]{2,}-\d+)/;
41
- const matches = str.match(regex);
42
- return matches ? matches[0] : null;
43
- }