Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(js-scripts): First iteration to share scripts #1

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,30 @@ dmypy.json
#Intillij
.idea/

# Config
js-scripts/update-ff/*.json

# Node.js
node_modules/

# Logs
logs
*.log
npm-debug.log*

# Dependency directories
pids
logs
*.pid
*.seed
*.pid.lock

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

20 changes: 20 additions & 0 deletions js-scripts/dot-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This can be env vars configured by the developer
export const DOTCMS_HOST = 'http://localhost:8080';
export const DOTCMS_USER = {
username: '[email protected]',
password: 'admin'
};

// API Endpoints
export const DOTCMS_SYSTEM_TABLE_API = `${DOTCMS_HOST}/api/v1/system-table`;
export const DOTCMS_TOKEN_API = `${DOTCMS_HOST}/api/v1/authentication/api-token`;
export const DOTCMS_EMA_CONFIG_API = `${DOTCMS_HOST}/api/v1/apps/dotema-config-v2/`;
export const DOTCMS_EXP_CONFIG_API = `${DOTCMS_HOST}/api/v1/apps/dotAnalytics-config/`;
export const DOTCMS_SITES_API = `${DOTCMS_HOST}/api/v1/site?filter=*&per_page=15&archive=false`;
export const DOTCMS_COMPANY_INFO_API = `${DOTCMS_HOST}/api/config/saveCompanyBasicInfo`;

// Common Constants
export const BTOA_USER = btoa(`${DOTCMS_USER.username}:${DOTCMS_USER.password}`);
export const BASIC_AUTH = `Basic ${BTOA_USER}`;
export const DOTCMS_JVM_INFO_API = `${DOTCMS_HOST}/api/v1/jvm`;
export const DEMO_SITE_HOSTNAME = 'demo.dotcms.com';
20 changes: 20 additions & 0 deletions js-scripts/get-docker-image/get-docker-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { BASIC_AUTH, DOTCMS_JVM_INFO_API } from '../dot-config.js';

const DOCKER_TAG = 'dotcms/dotcms:trunk_';

// Just get the current Docker Image
fetch(DOTCMS_JVM_INFO_API, {
method: 'GET',
headers: {
accept: '*/*',
Authorization: BASIC_AUTH
}
}).then((response) => {
if (response.ok) {
response.json().then((data) => {
console.log(`DotCMS Docker Image: [${DOCKER_TAG + data.release.buildNumber}]`);
});
} else {
console.log('Something occured while fetching the JVM information');
}
});
44 changes: 44 additions & 0 deletions js-scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions js-scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "scripts",
"version": "1.0.0",
"description": "",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"prompts": "^2.4.2"
}
}
40 changes: 40 additions & 0 deletions js-scripts/update-colors/update-colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { BASIC_AUTH, DOTCMS_COMPANY_INFO_API } from '../dot-config.js';
import queryString from 'querystring';

const primaryColor = process.argv[2] ?? '#426BF0'; // Fallback to design system color
const secondaryColor = process.argv[3] ?? '#7042F0'; // Fallback to design system color

// This is the data that is for default in this endpoint, I just changed the colors
const formData = {
portalURL: 'localhost',
mx: '',
emailAddress: 'dotCMS Website <[email protected]>',
size: '#1b3359',
type: primaryColor,
street: secondaryColor,
homeURL: '/html/images/backgrounds/bg-11.jpg',
city: '/dA/bc66ae086e242991d89e386d353c7529/asset/dotCMS-400x200.png'
};

const body = `portalURL=${queryString.encode(formData)}`; // We need to encode the object to send it as a string

fetch(DOTCMS_COMPANY_INFO_API, {
headers: {
accept: '*/*',
Authorization: BASIC_AUTH,
'content-type': 'application/x-www-form-urlencoded'
},
body,
method: 'POST'
}).then((response) => {
if (response.ok) {
response.text().then(() => {
console.log('Colors updated\n', {
primaryColor,
secondaryColor
});
});
} else {
console.log('Something occured while updating the colors');
}
});
36 changes: 36 additions & 0 deletions js-scripts/update-ema-config/update-ema-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { DOTCMS_EMA_CONFIG_API, BASIC_AUTH } from '../dot-config.js';
import { getDemoSite } from '../utils.js';

const projectURL = process.argv[2] ?? 'http://localhost:3000'; // Fallback to localhost:3000 which is NextJS

const emaConfig = {
// Basic config to test UVE Headless
config: [
{
pattern: '.*',
url: projectURL
}
]
};

const stringEmaConfig = JSON.stringify(emaConfig);

const demoSite = await getDemoSite();

fetch(`${DOTCMS_EMA_CONFIG_API}${demoSite.identifier}`, {
method: 'POST',
headers: {
Authorization: BASIC_AUTH,
'Content-Type': 'application/json'
},
body: JSON.stringify({
configuration: {
hidden: false,
value: stringEmaConfig
}
})
}).then((response) => {
response.json().then((data) => {
if (data.entity === 'Ok') console.log('EMA Config updated');
});
});
41 changes: 41 additions & 0 deletions js-scripts/update-exp-config/update-exp-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { DOTCMS_EXP_CONFIG_API, BASIC_AUTH } from '../dot-config.js';
import { getDemoSite } from '../utils.js';

// This is the config for testing experiments locally
const expConfig = {
clientId: {
hidden: false,
value: 'analytics-customer-customer1'
},
clientSecret: {
hidden: true,
value: 'testsecret'
},
analyticsConfigUrl: {
hidden: false,
value: 'http://host.docker.internal:8088/c/customer1/cluster1/keys'
},
analyticsWriteUrl: {
hidden: false,
value: 'http://host.docker.internal:8081/api/v1/event'
},
analyticsReadUrl: {
hidden: false,
value: 'http://host.docker.internal:4001/'
}
};

const demoSite = await getDemoSite();

fetch(`${DOTCMS_EXP_CONFIG_API}${demoSite.identifier}`, {
method: 'POST',
headers: {
Authorization: BASIC_AUTH,
'Content-Type': 'application/json'
},
body: JSON.stringify(expConfig)
}).then((response) => {
response.json().then((data) => {
if (data.entity === 'Ok') console.log('Experiments Config updated');
});
});
Loading