Skip to content

Commit

Permalink
Chore: Add dev options to pixi version config generator
Browse files Browse the repository at this point in the history
  • Loading branch information
bbazukun123 committed Dec 21, 2023
1 parent fd9b693 commit 388178e
Show file tree
Hide file tree
Showing 106 changed files with 1,192 additions and 90 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ yarn-error.log*
.idea
.eslintcache

scripts/pixiVersions.json
scripts/pixiVersions.json

.ghtoken
15 changes: 7 additions & 8 deletions docs/pixi-version.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"versionLabel": "prerelease-v8",
"version": "8.0.0-rc",
"releaseNotes": "https://github.com/pixijs/pixijs/releases/tag/v8.0.0-rc",
"build": "https://pixijs.download/v8.0.0-rc/pixi.min.js",
"docs": "https://pixijs.download/v8.0.0-rc/docs/index.html",
"npm": "8.0.0-rc",
"prerelease": true,
"latest": false
"versionLabel": "next-v8",
"version": "dev",
"releaseNotes": "https://github.com/pixijs/pixijs/releases",
"build": "https://pixijs.download/next-v8/pixi.min.js",
"docs": "https://pixijs.download/release/docs",
"npm": "https://pkg.csb.dev/pixijs/pixijs/commit/5b66fdf1",
"dev": true
}
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const config = {
},

current: {
label: 'prerelease-v8',
label: 'next-v8',
},
},
},
Expand Down
1,003 changes: 997 additions & 6 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"husky": "^8.0.0",
"inquirer": "^8.2.6",
"lint-staged": "^13.2.0",
"octokit": "^3.1.2",
"prettier": "^2.8.4",
"recast": "^0.23.4",
"typescript": "^4.9.4"
Expand Down
15 changes: 7 additions & 8 deletions pixi-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
"isCurrent": false
},
{
"versionLabel": "prerelease-v8",
"version": "8.0.0-rc",
"releaseNotes": "https://github.com/pixijs/pixijs/releases/tag/v8.0.0-rc",
"build": "https://pixijs.download/v8.0.0-rc/pixi.min.js",
"docs": "https://pixijs.download/v8.0.0-rc/docs/index.html",
"npm": "8.0.0-rc",
"prerelease": true,
"latest": false,
"versionLabel": "next-v8",
"version": "dev",
"releaseNotes": "https://github.com/pixijs/pixijs/releases",
"build": "https://pixijs.download/next-v8/pixi.min.js",
"docs": "https://pixijs.download/release/docs",
"npm": "https://pkg.csb.dev/pixijs/pixijs/commit/7f31f584",
"dev": true,
"isCurrent": true
}
]
2 changes: 1 addition & 1 deletion scripts/generate-example-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function go()
const EXAMPLES_MD_PATH = resolve(DOCS_PATH, 'examples');
const pixiVersion = require(versionFile);
const VERSION = pixiVersion.version;
const EXAMPLES_JS_PATH = resolve(ROOT, 'src', 'examples', `v${VERSION}`);
const EXAMPLES_JS_PATH = resolve(ROOT, 'src', 'examples', VERSION === 'dev' ? VERSION : `v${VERSION}`);
const examplesData = require(`${EXAMPLES_JS_PATH}/examplesData.json`);

const directories = Object.keys(examplesData);
Expand Down
147 changes: 117 additions & 30 deletions scripts/generate-pixi-version-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const shell = require('shelljs');
const inquirer = require('inquirer');
const { compareVersions } = require('compare-versions');
const glob = require('glob');
const axios = require('axios');
const { Octokit, App } = require('octokit');

const PARAM = process.argv[2];
const ROOT = resolve(__dirname, '..');
Expand All @@ -22,6 +24,49 @@ if (existsSync(OUT_PATH))
// Compile out a list of all the versions of pixi.js
shell.exec('npm view pixi.js --json > scripts/pixiVersions.json');

// Github
const devBranches = ['next-v8', 'dev'];
const tokenPath = resolve(ROOT, '.ghtoken');
const auth = existsSync(tokenPath) ? readFileSync(tokenPath, 'utf8').trim() : null;
const octokit = auth ? new Octokit({ auth }) : undefined;
const owner = 'pixijs';
const repo = 'pixijs';

async function getLatestCommitSHA(branch = 'master')
{
if (!octokit)
{
console.warn('No auth token found. Please add please generate and add a token to \'.ghtoken\' on root...');

return null;
}

try
{
const result = await octokit.request(`GET /repos/${owner}/${repo}/branches/${branch}`, {
owner,
repo,
branch,
headers: {
'X-GitHub-Api-Version': '2022-11-28',
},
});

if (result.status === 200)
{
return result.data.commit.sha;
}

return null;
}
catch (e)
{
console.error(`Error getting the branch ${branch}. Please try again...`);

return null;
}
}

// Import the compiled list of versions
const pixiVersions = require('./pixiVersions.json');
const tags = pixiVersions['dist-tags'];
Expand Down Expand Up @@ -51,8 +96,10 @@ if (compareVersions(tags.prerelease, tags.latest) <= 0)
const all = '[>] all versions';
const back = '[<] back';
const cancel = '[x] cancel';
const options1 = [all, ...tagKeys];
const dev = '[>] dev';
const options1 = [all, dev, ...tagKeys];
const options2 = [back, ...allVersions];
const optionsDev = [back, ...devBranches];
const intro = `${config ? 'Altering' : 'Generating'} ${PATH_FROM_ROOT}/${OUT_NAME}...\n`;
const prompt = config
? `Config for PixiJS v${config.version} exists. Which version would you like to replace it with?`
Expand Down Expand Up @@ -101,9 +148,11 @@ async function doesVersionConfigExist(version)
let version;
let choice;
let tag;
let branch;
let sha;

// Prompt the user to select a version
while (!version || choice === all || choice === back)
while (!version && !sha)
{
choice = await inquirer.prompt([
{
Expand All @@ -123,6 +172,29 @@ async function doesVersionConfigExist(version)
shell.rm('./scripts/pixiVersions.json');
shell.exit(0);
}
else if (choice.selected === dev)
{
choice = await inquirer.prompt([
{
type: 'list',
name: 'selected',
message: 'Which dev version would you want to use?',
choices: optionsDev,
loop: false,
},
]);

if (choice.selected !== back)
{
branch = choice.selected;
const result = await getLatestCommitSHA(branch);

if (result)
{
sha = result;
}
}
}
else if (choice.selected === all)
{
choice = await inquirer.prompt([
Expand All @@ -149,39 +221,54 @@ async function doesVersionConfigExist(version)
}
}

const parts = version.split('.');
const major = parts[0];
const minor = parts[1];
const patch = parts[2].split('-')[0];
const isPrelease = parts[2].includes('-rc');
const isLatest = version === tags.latest;
let versionLabel;

if (isLatest)
if (sha)
{
versionLabel = `v${[major, 'x'].join('.')} (Latest)`;
}
else if (tag)
{
const extracted = tag.replace('latest-', '');

versionLabel = extracted.match(/^\d/) ? `v${extracted}` : extracted;
config = {
versionLabel: branch,
version: 'dev',
releaseNotes: 'https://github.com/pixijs/pixijs/releases',
build: `https://pixijs.download/${branch}/pixi.min.js`,
docs: 'https://pixijs.download/release/docs',
npm: `https://pkg.csb.dev/pixijs/pixijs/commit/${sha.substring(0, 8)}`,
dev: true,
};
}
else
{
versionLabel = `v${version}`;
}
const parts = version.split('.');
const major = parts[0];
const minor = parts[1];
const patch = parts[2].split('-')[0];
const isPrelease = parts[2].includes('-rc');
const isLatest = version === tags.latest;
let versionLabel;

if (isLatest)
{
versionLabel = `v${[major, 'x'].join('.')} (Latest)`;
}
else if (tag)
{
const extracted = tag.replace('latest-', '');

config = {
versionLabel,
version,
releaseNotes: `https://github.com/pixijs/pixijs/releases/tag/v${version}`,
build: `https://pixijs.download/v${version}/pixi.min.js`,
docs: `https://pixijs.download/v${version}/docs/index.html`,
npm: version,
prerelease: isPrelease,
latest: isLatest,
};
versionLabel = extracted.match(/^\d/) ? `v${extracted}` : extracted;
}
else
{
versionLabel = `v${version}`;
}

config = {
versionLabel,
version,
releaseNotes: `https://github.com/pixijs/pixijs/releases/tag/v${version}`,
build: `https://pixijs.download/v${version}/pixi.min.js`,
docs: `https://pixijs.download/v${version}/docs/index.html`,
npm: version,
prerelease: isPrelease,
latest: isLatest,
};
}

const json = JSON.stringify(config, null, 2);

Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-tutorial-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function go()
const TUTORIALS_MD_PATH = resolve(DOCS_PATH, 'tutorials');
const pixiVersion = require(versionFile);
const VERSION = pixiVersion.version;
const TUTORIALS_JS_PATH = resolve(ROOT, 'src', 'tutorials', `v${VERSION}`);
const TUTORIALS_JS_PATH = resolve(ROOT, 'src', 'tutorials', VERSION === 'dev' ? VERSION : `v${VERSION}`);
const tutorialsData = require(`${TUTORIALS_JS_PATH}/tutorialsData.json`);

const fileData = tutorialsData.map((tutorialKey) =>
Expand Down
3 changes: 1 addition & 2 deletions src/components/Example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export default function Example({ id, pixiVersion }: { id: string; pixiVersion:
{() => (
<PixiPlayground
code={source}
pixiVersion={pixiVersion.version}
isPixiDevVersion={pixiVersion.dev}
pixiVersion={pixiVersion}
isPixiWebWorkerVersion={entry?.usesWebWorkerLibrary}
mode="example"
/>
Expand Down
10 changes: 4 additions & 6 deletions src/components/Playground/PixiPlayground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useCallback, useEffect, useState } from 'react';
import classNames from 'classnames';
import { SandpackLayout, SandpackPreview, SandpackProvider, useActiveCode, useSandpack } from '@codesandbox/sandpack-react';
import { useContainerClassNameModifier } from '@site/src/hooks/useContainerClassNameModifier';
import { latestVersion } from './usePixiVersions';
import type { IVersion } from './usePixiVersions';
import { latestPixiVersion } from './usePixiVersions';
import MonacoEditor from './MonacoEditor';
import { useSandpackConfiguration } from './useSandpackConfiguration';
import type { CodeChangeCallbackType } from './MonacoEditor';
Expand Down Expand Up @@ -75,8 +76,7 @@ function BasePlayground({ mode, onCodeChanged }: BasePlaygroundProps)
type PixiPlaygroundProps = {
code: string;
isPixiWebWorkerVersion?: boolean;
isPixiDevVersion?: boolean;
pixiVersion?: string;
pixiVersion?: IVersion;
mode?: BasePlaygroundMode;
onCodeChanged?: CodeChangeCallbackType;
};
Expand All @@ -85,16 +85,14 @@ export default function PixiPlayground({
code,
onCodeChanged,
isPixiWebWorkerVersion = false,
isPixiDevVersion = false,
pixiVersion = latestVersion,
pixiVersion = latestPixiVersion,
mode = 'example',
}: PixiPlaygroundProps)
{
const { colorMode } = useColorMode();

const { key, files, customSetup } = useSandpackConfiguration({
code,
isPixiDevVersion,
isPixiWebWorkerVersion,
pixiVersion,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const propEq
(object: Record<string, any>): boolean =>
object[prop] === value;

export const latestVersion = ((versions as IVersion[]).find(propEq('latest', true)) as IVersion).version;
export const latestPixiVersion = (versions as IVersion[]).find(propEq('latest', true)) as IVersion;

type UsePixiVersionsParams = {
selectedVersionId: string;
Expand Down
Loading

0 comments on commit 388178e

Please sign in to comment.