Skip to content

Conversation

varshini-adiga
Copy link
Collaborator

@varshini-adiga varshini-adiga commented Jun 30, 2025

Description

Launch playground from samples in the documentation site
https://jira.corp.adobe.com/browse/WXP-4953

Changes include:

  1. Encoding sample id along with mode and session as a query param and pass it to Express url.
  2. New Try button in the code block.
  3. Script which runs on build to upload samples to FFC.

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@varshini-adiga varshini-adiga changed the title Vadiga/launch samples deeplink [PoC] launch playground from samples Jun 30, 2025
@varshini-adiga varshini-adiga changed the title [PoC] launch playground from samples [WXP-4953] Launch code playground (script mode) from samples in the documentation site Jul 18, 2025
@varshini-adiga varshini-adiga requested a review from xerxovksi July 21, 2025 11:52
@varshini-adiga varshini-adiga removed the request for review from vamshich13 September 22, 2025 06:31
Copy link
Collaborator

@xerxovksi xerxovksi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need to understand what these 2 files do:

  1. src/@adobe/gatsby-theme-aio/components/Code/index.js
  2. src/@adobe/gatsby-theme-aio/components/Code/styles.css

Comment on lines 92 to 95
PLAYGROUND_CLIENT_ID: ${{ secrets.PLAYGROUND_CLIENT_ID }}
PLAYGROUND_CLIENT_SECRET: ${{ secrets.PLAYGROUND_CLIENT_SECRET }}
PLAYGROUND_AUTH_CODE: ${{ secrets.PLAYGROUND_AUTH_CODE }}
PLAYGROUND_API_KEY: ${{ secrets.PLAYGROUND_API_KEY }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need these to be set with the secrets for the test workflow? Can't they just be empty strings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


const SCAN_DIRECTORY = "./src/pages";
const MARKDOWN_EXTENSION = ".md";
const IMS_BASE_URL = "https://ims-na1-stg1.adobelogin.com";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using the stage endpoint?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this. Have set these URLs to stage and prod ones in the deploy.yml

const MARKDOWN_EXTENSION = ".md";
const IMS_BASE_URL = "https://ims-na1-stg1.adobelogin.com";
const IMS_TOKEN_ENDPOINT = "/ims/token/v1";
const FFC_BASE_URL = "https://ffc-addon-stage.adobe.io/";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question - why stage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this. Have set these URLs to stage and prod ones in the deploy.yml

package.json Outdated
"fix:lint": "./node_modules/.bin/markdownlint --config .github/linters/.markdownlint.yml src --fix",
"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"
"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",
"upload-playground-samples": "node upload-playground-samples.js"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"upload-playground-samples": "node upload-playground-samples.js"
"_postbuild": "node upload-playground-samples.js"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have added new build:deploy command which runs the samples

package.json Outdated
"dev": "gatsby develop",
"dev:https": "gatsby develop --https --host localhost.corp.adobe.com --port 9000",
"build": "gatsby build",
"build": "gatsby build && yarn upload-playground-samples",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested a change below to use _postbuild for syncing the samples. You can remove && ... from here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have added new build:deploy command which runs the samples


/**
* Exchange an IMS authorization code for a service token.
* @returns access_token.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @returns access_token.
* @returns Service token.

try {
const accessToken = await getImsServiceToken();
const url = new URL(
`${FFC_PLAYGROUND_ENDPOINT}/${encodeURIComponent(projectId)}`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is encodeURIComponent() required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. Removed


require('dotenv').config();

const fs = require("fs").promises;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use ESM instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using fs-extra


while ((match = CODE_BLOCK_REGEX.exec(content)) !== null) {
const [, language, explicitId, code] = match;
const id = explicitId || Math.random().toString(36).substring(2, 8);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't id be mandatory? If not, with the random generated id how will we manage updates to the code sample?

let match;
CODE_BLOCK_REGEX.lastIndex = 0;

while ((match = CODE_BLOCK_REGEX.exec(content)) !== null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming this does the job :)

GATSBY_FEDS_PRIVACY_ID: ${{ secrets.AIO_FEDS_PRIVACY_ID }}
GATSBY_SITE_DOMAIN_URL: https://developer-stage.adobe.com
NODE_OPTIONS: "--max_old_space_size=8192"
IMS_BASE_URL: "https://ims-na1-stg1.adobelogin.com"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use stage environments?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Developer docs is deployed on stage. We are planning to hand over the task of adding try tags on relevant samples to devEx team. I feel uploading samples in stage environment will help them in testing the flow.

GATSBY_SITE_DOMAIN_URL: https://developer-stage.adobe.com
NODE_OPTIONS: "--max_old_space_size=8192"
IMS_BASE_URL: "https://ims-na1-stg1.adobelogin.com"
FFC_BASE_URL: "https://ffc-addon-stage.adobe.io/"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the product instance only.

const getLoader = require("prismjs/dependencies");
const components = require("prismjs/components");

const componentsToLoad = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these copied from some template? Do we need all these here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unwanted components.

package.json Outdated
"dev": "gatsby develop",
"dev:https": "gatsby develop --https --host localhost.corp.adobe.com --port 9000",
"build": "gatsby build",
"build:deploy": "gatsby build && yarn run postbuild",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Generally when you name a script as postbuild, it runs on its own after the build.

Copy link
Collaborator Author

@varshini-adiga varshini-adiga Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure but I guess yarn doesn't run postbuild after build because the post build script is not automatically run after build.
Renamed this command now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants