Skip to content

Commit 930f37c

Browse files
authored
Merge pull request #194 from AdobeDocs/eds-migration
Eds migration
2 parents e271b97 + e10e853 commit 930f37c

File tree

17 files changed

+285
-30
lines changed

17 files changed

+285
-30
lines changed

.github/workflows/deploy.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,20 @@ jobs:
121121
- name: Clean cache on stage
122122
if: needs.set-state.outputs.clean_cache == 'true' && needs.set-state.outputs.deploy_stage == 'true'
123123
run: |
124-
bash .github/scripts/process-mds.sh cache stage ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
124+
bash .github/scripts/process-mds.sh cache stage ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
125125
126126
- name: Clean cache on prod
127127
if: needs.set-state.outputs.clean_cache == 'true' && needs.set-state.outputs.deploy_prod == 'true'
128128
run: |
129-
bash .github/scripts/process-mds.sh cache prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
129+
bash .github/scripts/process-mds.sh cache prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
130130
131131
- name: Deploy to stage
132132
if: needs.set-state.outputs.deploy_stage == 'true'
133133
run: |
134-
bash .github/scripts/process-mds.sh preview stage ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
134+
bash .github/scripts/process-mds.sh preview stage ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
135135
136136
- name: Deploy to prod
137137
if: needs.set-state.outputs.deploy_prod == 'true'
138-
run: |
139-
bash .github/scripts/process-mds.sh preview prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
140-
bash .github/scripts/process-mds.sh live prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
138+
run: |
139+
bash .github/scripts/process-mds.sh preview prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"
140+
bash .github/scripts/process-mds.sh live prod ${{ needs.set-state.outputs.branch_short_ref }} "${{ needs.set-state.outputs.path_prefix }}"

buildRedirections.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path');
2-
const fs = require('node:fs');
32
const { pathPrefix } = require('./gatsby-config.js');
43
const { globSync }= require('glob');
4+
const { writeRedirectionsFile } = require('./scriptUtils.js');
55

66
try {
77
if(!pathPrefix) {
@@ -39,17 +39,7 @@ try {
3939
}
4040
});
4141

42-
let redirectionsData =
43-
{
44-
"total" : data.length,
45-
"offset": 0,
46-
"limit": data.length,
47-
"data" : data,
48-
":type": "sheet"
49-
};
50-
51-
let redirectionsFilePath = path.resolve(__dirname + '/src/pages/redirects.json');
52-
fs.writeFileSync(redirectionsFilePath, JSON.stringify(redirectionsData));
42+
writeRedirectionsFile(data);
5343

5444
} catch (err) {
5545
console.error(err);

normalizeLinks.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const path = require('path');
2+
const fs = require('node:fs');
3+
const matchAll = require('string.prototype.matchall');
4+
const {
5+
getMarkdownFiles,
6+
replaceLinksInFile,
7+
getFindPatternForMarkdownFiles: getFindPattern,
8+
getReplacePatternForMarkdownFiles: getReplacePattern,
9+
} = require('./scriptUtils.js');
10+
11+
function normalizeLinksInMarkdownFile(file, files) {
12+
const relativeToDir = path.dirname(file);
13+
const relativeFiles = files.map(file => path.relative(relativeToDir, file));
14+
const linkMap = new Map();
15+
16+
const linkPattern = getFindPattern('[^)#]*');
17+
let data = fs.readFileSync(file, 'utf8');
18+
const links = matchAll(data, new RegExp(linkPattern, "gm"));
19+
[...links].forEach(link => {
20+
const optionalPrefix = link[2] ?? '';
21+
const from = link[3] ?? '';
22+
let to = from;
23+
24+
// ensure link includes file name and extension
25+
if(to.endsWith('/') || optionalPrefix.endsWith('/') && !to) {
26+
to = `${to}index.md`
27+
}
28+
if(!to.endsWith('.md') && to) {
29+
to = `${to}.md`;
30+
}
31+
32+
to = to.replaceAll('/', path.sep);
33+
34+
// ensure simplest relative path
35+
// this removes trailing slash, so need to do this after the file name and extension checks above
36+
const absolute = path.resolve(relativeToDir, to);
37+
const relative = path.relative(relativeToDir, absolute);
38+
to = relative;
39+
40+
// ensure the link we constructed above exists
41+
const toExists = relativeFiles.find(file => to === file);
42+
43+
to = to.replaceAll(path.sep, '/');
44+
45+
if(to !== from && toExists) {
46+
linkMap.set(from, to);
47+
}
48+
})
49+
50+
replaceLinksInFile({
51+
file,
52+
linkMap,
53+
getFindPattern,
54+
getReplacePattern,
55+
});
56+
}
57+
58+
try {
59+
const files = getMarkdownFiles();
60+
files.forEach(file => {
61+
normalizeLinksInMarkdownFile(file, files);
62+
});
63+
64+
} catch (err) {
65+
console.error(err);
66+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
"test:links": "remark src/pages --quiet --frail",
3434
"lint": "docker run --rm -e RUN_LOCAL=true --env-file '.github/super-linter.env' -v \"$PWD\":/tmp/lint github/super-linter:slim-v4.10.1",
3535
"buildNavigation": "node buildNavigation.js",
36-
"buildRedirections": "node buildRedirections.js"
36+
"buildRedirections": "node buildRedirections.js",
37+
"renameFiles": "node renameFiles.js",
38+
"normalizeLinks": "node normalizeLinks.js"
3739
},
3840
"remarkConfig": {
3941
"plugins": [

renameFiles.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
const path = require('path');
2+
const fs = require('node:fs');
3+
const { pathPrefix } = require('./gatsby-config.js');
4+
const {
5+
readRedirectionsFile,
6+
writeRedirectionsFile,
7+
getRedirectionsFilePath,
8+
getMarkdownFiles,
9+
getFindPatternForMarkdownFiles,
10+
getReplacePatternForMarkdownFiles,
11+
replaceLinksInFile
12+
} = require('./scriptUtils.js');
13+
14+
function toKebabCase(str) {
15+
const isScreamingSnakeCase = new RegExp(/^[A-Z0-9_]*$/gm).test(str);
16+
str = isScreamingSnakeCase ? str.toLowerCase() : str;
17+
return str
18+
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
19+
.map(x => x.toLowerCase())
20+
.join('-');
21+
}
22+
23+
function toEdsCase(str) {
24+
const isValid = Boolean((/^([a-z0-9-]*)$/.test(str)));
25+
return isValid ? str : toKebabCase(str);
26+
}
27+
28+
function toUrl(file, renameBaseWithoutExt = name => name) {
29+
const base = path.basename(file);
30+
const ext = path.extname(file);
31+
const end = file.length - base.length;
32+
const baseWithoutExt = base.substring(0, base.length - ext.length);
33+
const newBaseWithoutExt = renameBaseWithoutExt(baseWithoutExt);
34+
return `${file.substring(0, end)}${newBaseWithoutExt}`
35+
}
36+
37+
function renameFile(file, renameBaseWithoutExt) {
38+
const url = toUrl(file, renameBaseWithoutExt);
39+
const ext = path.extname(file);
40+
return `${url}${ext}`
41+
}
42+
43+
function getFileMap(files) {
44+
const map = new Map();
45+
files.forEach(from => {
46+
const to = renameFile(from, toEdsCase)
47+
if(to !== from) {
48+
map.set(from, to)
49+
}
50+
});
51+
return map;
52+
}
53+
54+
function getLinkMap(fileMap, relativeToDir) {
55+
const linkMap = new Map();
56+
fileMap.forEach((toFile, fromFile) => {
57+
let fromRelFile = path.relative(relativeToDir, fromFile);
58+
fromRelFile = fromRelFile.replaceAll(path.sep, '/');
59+
60+
let toRelFile = path.relative(relativeToDir, toFile);
61+
toRelFile = toRelFile.replaceAll(path.sep, '/');
62+
63+
linkMap.set(fromRelFile, toRelFile);
64+
});
65+
return linkMap;
66+
}
67+
68+
function renameLinksInMarkdownFile(fileMap, file) {
69+
const dir = path.dirname(file);
70+
replaceLinksInFile({
71+
file,
72+
linkMap: getLinkMap(fileMap, dir),
73+
getFindPattern: getFindPatternForMarkdownFiles,
74+
getReplacePattern: getReplacePatternForMarkdownFiles,
75+
});
76+
}
77+
78+
function renameLinksInRedirectsFile(fileMap) {
79+
const file = getRedirectionsFilePath();
80+
const dir = path.dirname(file);
81+
replaceLinksInFile({
82+
file,
83+
linkMap: getLinkMap(fileMap, dir),
84+
getFindPattern: (from) => `(['"]?)(Source|Destination)(['"]?\\s*:\\s*['"])(${pathPrefix}${toUrl(from)})(/?)(#[^'"]*)?(['"])`,
85+
getReplacePattern: (to) => `$1$2$3${pathPrefix}${toUrl(to)}$5$6$7`,
86+
});
87+
}
88+
89+
function renameLinksInGatsbyConfigFile(fileMap, file) {
90+
const dir = path.join('src', 'pages');
91+
replaceLinksInFile({
92+
file,
93+
linkMap: getLinkMap(fileMap, dir),
94+
getFindPattern: (from) => `(['"]?path['"]?\\s*:\\s*['"])(/|./)?(${from})(#[^'"]*)?(['"])`,
95+
getReplacePattern: (to) => `$1$2${to}$4$5`,
96+
});
97+
}
98+
99+
function appendRedirects(fileMap) {
100+
const file = getRedirectionsFilePath();
101+
const dir = path.dirname(file);
102+
const linkMap = getLinkMap(fileMap, dir);
103+
const newData = [];
104+
linkMap.forEach((to, from) => {
105+
newData.push({
106+
Source: `${pathPrefix}${toUrl(from)}`,
107+
Destination: `${pathPrefix}${toUrl(to)}`,
108+
})
109+
});
110+
const currData = readRedirectionsFile();
111+
const data = [...currData, ...newData];
112+
writeRedirectionsFile(data);
113+
}
114+
115+
function renameFiles(map) {
116+
map.forEach((to, from) => {
117+
fs.renameSync(from, to);
118+
});
119+
}
120+
121+
try {
122+
const markdownFiles = getMarkdownFiles();
123+
const fileMap = getFileMap(markdownFiles);
124+
markdownFiles.forEach(file => {
125+
renameLinksInMarkdownFile(fileMap, file);
126+
});
127+
renameFiles(fileMap);
128+
129+
const redirectsFile = getRedirectionsFilePath();
130+
if(fs.existsSync(redirectsFile)) {
131+
renameLinksInRedirectsFile(fileMap);
132+
appendRedirects(fileMap);
133+
}
134+
135+
const gatsbyConfigFile = 'gatsby-config.js';
136+
if(fs.existsSync(gatsbyConfigFile)) {
137+
renameLinksInGatsbyConfigFile(fileMap, gatsbyConfigFile);
138+
}
139+
140+
} catch (err) {
141+
console.error(err);
142+
}

scriptUtils.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const path = require('path');
2+
const fs = require('node:fs');
3+
const { globSync }= require('glob');
4+
5+
function getRedirectionsFilePath() {
6+
const redirectionsFilePath = path.join(__dirname, 'src', 'pages', 'redirects.json');
7+
return path.resolve(redirectionsFilePath);
8+
}
9+
10+
function readRedirectionsFile() {
11+
const redirectionsFilePath = getRedirectionsFilePath();
12+
return JSON.parse(fs.readFileSync(redirectionsFilePath)).data;
13+
}
14+
15+
function writeRedirectionsFile(data) {
16+
let redirectionsData =
17+
{
18+
"total" : data.length,
19+
"offset": 0,
20+
"limit": data.length,
21+
"data" : data,
22+
":type": "sheet"
23+
};
24+
25+
let redirectionsFilePath = getRedirectionsFilePath();
26+
fs.writeFileSync(redirectionsFilePath, JSON.stringify(redirectionsData));
27+
}
28+
29+
function getMarkdownFiles() {
30+
return globSync(__dirname + '/src/pages/**/*.md')
31+
.map(f => path.resolve(f));
32+
}
33+
34+
const getFindPatternForMarkdownFiles = (from) => `(\\[[^\\]]*]\\()(/|./)?(${from})(#[^\\()]*)?(\\))`;
35+
const getReplacePatternForMarkdownFiles = (to) => `$1$2${to}$4$5`;
36+
37+
function replaceLinksInFile({ file, linkMap, getFindPattern, getReplacePattern }) {
38+
let data = fs.readFileSync(file, 'utf8');
39+
linkMap.forEach((to, from) => {
40+
const find = getFindPattern(from);
41+
const replace = getReplacePattern(to);
42+
data = data.replaceAll(new RegExp(find, "gm"), replace);
43+
});
44+
fs.writeFileSync(file, data, 'utf-8');
45+
}
46+
47+
module.exports = {
48+
getRedirectionsFilePath,
49+
readRedirectionsFile,
50+
writeRedirectionsFile,
51+
getMarkdownFiles,
52+
getFindPatternForMarkdownFiles,
53+
getReplacePatternForMarkdownFiles,
54+
replaceLinksInFile
55+
};

src/pages/guides/authentication/ServerToServerAuthentication/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Read our OAuth Server-to-server credential implementation guide -
4848

4949
<InlineAlert slots="text"/>
5050

51-
The Service Account (JWT) credentials have been deprecated in favor of the OAuth Server-to-Server credentials. Your applications using the Service Account (JWT) credentials will stop working after Jun 30, 2025. You must migrate to the new credential by **Jun 30, 2025**, to ensure your application continues functioning. [Learn more](../ServerToServerAuthentication/migration.md).
51+
The Service Account (JWT) credentials have been deprecated in favor of the OAuth Server-to-Server credentials. Your applications using the Service Account (JWT) credentials will stop working after Jun 30, 2025. You must migrate to the new credential by **Jun 30, 2025**, to ensure your application continues functioning. [Learn more](migration.md).
5252

5353
Service Account (JWT) credentials rely on the JWT token exchange mechanism to generate access tokens. This credential's details include two secrets a `client_secret` and a `private.key` (part of a public certificate private key pair).
5454

src/pages/guides/authentication/UserAuthentication/implementation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# User Authentication Implementation Guide
22

3-
The following guide goes over finer implementation details for user authentication credentials. At the end of this guide is a list of recommended industry-standard OAuth2 libraries. Before proceeding, we recommend you familiarize yourself with the 3-legged OAuth flow in our [user authentication guide](../UserAuthentication/index.md).
3+
The following guide goes over finer implementation details for user authentication credentials. At the end of this guide is a list of recommended industry-standard OAuth2 libraries. Before proceeding, we recommend you familiarize yourself with the 3-legged OAuth flow in our [user authentication guide](index.md).
44

55
## User authentication credential types
66

src/pages/guides/plugins/plugin-distribution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This guide provides instructions for distributing a Plugin created in Adobe Developer Console.
44

5-
For information on how to build a plugin, please being by reading the [plugin overview](../plugins/index.md).
5+
For information on how to build a plugin, please being by reading the [plugin overview](index.md).
66

77
## Select plugin project
88

src/pages/guides/services/services-add-api-jwt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
<InlineAlert slots="text"/>
44

5-
Service Account (JWT) credentials have been deprecated in favor of the OAuth Server-to-Server credentials. View our [migration guide](../authentication/ServerToServerAuthentication/migration.md) to know more. The new version of this guide that uses OAuth Server-to-Server credentials is now available here - [**Add API to project using OAuth Server-to-Server credentials**](../services/services-add-api-oauth-s2s.md).
5+
Service Account (JWT) credentials have been deprecated in favor of the OAuth Server-to-Server credentials. View our [migration guide](../authentication/ServerToServerAuthentication/migration.md) to know more. The new version of this guide that uses OAuth Server-to-Server credentials is now available here - [**Add API to project using OAuth Server-to-Server credentials**](services-add-api-oauth-s2s.md).

0 commit comments

Comments
 (0)