generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:adobecom/mas into MWPW-162020
- Loading branch information
Showing
59 changed files
with
3,751 additions
and
2,230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# gen-locales.mjs | ||
|
||
## Description | ||
The `gen-locales.mjs` script is used to generate locale content tree for a MAS sub tenant in Odin. | ||
|
||
## Usage | ||
|
||
### Prerequisites | ||
- Node.js installed on your machine | ||
|
||
- Required environment variables: | ||
- `accessToken`: The IMS access token of a user, copy it from your IMS session in MAS Studio. | ||
- `apiKey`: The API key for authentication, api key used in MAS Studio. | ||
|
||
- Required parameters: | ||
- `bucket`: The AEM bucket name, e.g: author-p22655-e155390 for Odin QA | ||
- `consumer`: The consumer identifier, e.g: ccd | ||
|
||
### Running the Script | ||
3. Run the script: | ||
```sh | ||
export accessToken="your-access-token" | ||
export apiKey="your-api-key" | ||
|
||
node gen-locales.mjs author-p22655-e155390 drafts | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import https from 'https'; | ||
|
||
/** | ||
* This script creates locale tree for the locales below for a given bucket(env) and consumer in Odin. | ||
* e.g: node gen-locales.mjs author-p22655-e155390 drafts | ||
*/ | ||
|
||
const locales = [ | ||
'cs_CZ', | ||
'da_DK', | ||
'es_ES', | ||
'fi_FI', | ||
'hu_HU', | ||
'id_ID', | ||
'it_IT', | ||
'ko_KR', | ||
'nb_NO', | ||
'nl_NL', | ||
'pl_PL', | ||
'pt_BR', | ||
'ru_RU', | ||
'sv_SE', | ||
'th_TH', | ||
'tr_TR', | ||
'uk_UA', | ||
'vi_VN', | ||
'zh_CN', | ||
'zh_TW', | ||
'ja_JP', | ||
'de_DE', | ||
'es_MX', | ||
'fr_CA', | ||
'fr_FR', | ||
'en_US', // displayed first in AEM by default | ||
]; | ||
|
||
const args = process.argv.slice(2); | ||
const bucket = args[0]; | ||
const consumer = args[1]; | ||
|
||
const accessToken = process.env.MAS_ACCESS_TOKEN; | ||
const apiKey = process.env.MAS_API_KEY; | ||
|
||
if (!bucket || !consumer || !accessToken || !apiKey) { | ||
console.error('Usage: node gen-locales.mjs <bucket> <consumer>'); | ||
console.error( | ||
'Ensure MAS_ACCESS_TOKEN and MAS_API_KEY are set as environment variables.', | ||
); | ||
process.exit(1); | ||
} | ||
|
||
async function run() { | ||
const batchSize = 5; | ||
for (let i = 0; i < locales.length; i += batchSize) { | ||
const batch = locales.slice(i, i + batchSize).map((locale) => ({ | ||
path: `/content/dam/mas/${consumer}/${locale}`, | ||
title: locale, | ||
})); | ||
|
||
const options = { | ||
hostname: `${bucket}.adobeaemcloud.com`, | ||
path: '/adobe/folders/', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Adobe-Accept-Experimental': '1', | ||
Authorization: `Bearer ${accessToken}`, | ||
'x-api-key': apiKey, | ||
}, | ||
}; | ||
|
||
await new Promise((resolve, reject) => { | ||
const req = https.request(options, (res) => { | ||
let data = ''; | ||
|
||
res.on('data', (chunk) => { | ||
data += chunk; | ||
}); | ||
|
||
res.on('end', () => { | ||
if (res.statusCode >= 200 && res.statusCode < 300) { | ||
console.log( | ||
`Batch processed successfully: ${JSON.stringify(batch)}`, | ||
); | ||
resolve(); | ||
} else { | ||
console.error( | ||
`Failed to process batch: ${JSON.stringify(batch)}`, | ||
res.statusCode, | ||
data, | ||
); | ||
reject( | ||
new Error( | ||
`Failed to process batch: ${res.statusCode}`, | ||
), | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
req.on('error', (error) => { | ||
console.error( | ||
`Error processing batch: ${JSON.stringify(batch)}`, | ||
error, | ||
); | ||
reject(error); | ||
}); | ||
|
||
req.write(JSON.stringify(batch)); | ||
req.end(); | ||
}); | ||
} | ||
|
||
console.log('All batches processed.'); | ||
} | ||
|
||
run(); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.