Skip to content

Commit

Permalink
chore: Link package (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
zjxxxxxxxxx authored Dec 6, 2024
1 parent 3fc07c9 commit b0ebda5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 23 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"private": true,
"name": "@open-editor/monorepo",
"workspaces": [
"packages/*"
"packages/*",
"playgrounds/*"
],
"type": "module",
"description": "🚀 A web devtools for fast find source code.",
Expand Down
38 changes: 20 additions & 18 deletions scripts/create-codesandbox-tasks.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { readdirSync } from 'node:fs';
import { resolve } from 'node:path';
import { readjson, writejson } from './utils';
import { playgrounds, readjson, writejson } from './utils';

const TASKS_PATH = resolve('.codesandbox/tasks.json');

const taskJson = readjson(TASKS_PATH);
const names = readdirSync(resolve('playgrounds'));
main();

let port = 4000;
names.flatMap((name) => {
const task = `@playground/${name}`;
taskJson.tasks[name] = {
name: `Preview ${task}`,
command: `pnpm --filter ${task} dev`,
runAtStart: true,
preview: {
port: port++,
prLink: 'direct',
},
};
});
function main() {
const taskJson = readjson(TASKS_PATH);

writejson(TASKS_PATH, taskJson);
let port = 4000;
playgrounds.forEach((name) => {
const task = `@playground/${name}`;
taskJson.tasks[name] = {
name: `Preview ${task}`,
command: `pnpm --filter ${task} dev`,
runAtStart: true,
preview: {
port: port++,
prLink: 'direct',
},
};
});

writejson(TASKS_PATH, taskJson);
}
30 changes: 27 additions & 3 deletions scripts/start.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { resolve } from 'node:path';
import { readdirSync } from 'node:fs';
import consola from 'consola';
import enquirer from 'enquirer';
import minimist from 'minimist';

import { exec, readjson } from './utils';
import {
exec,
playgrounds,
projectRoot,
readjson,
rollupRoot,
viteRoot,
webpackRoot,
} from './utils';

main();

Expand All @@ -13,6 +20,24 @@ async function main() {
const { playground = await selectPlayground(), script = await selectScript(playground) } =
minimist(process.argv.slice(1));

let packagePath: string;
if (playground.includes('rollup')) {
packagePath = rollupRoot;
} else if (playground.includes('vite')) {
packagePath = viteRoot;
} else {
packagePath = webpackRoot;
}

consola.info(`Link ${packagePath}`);
exec(
[
`cd ${resolve(projectRoot, `playgrounds/${playground}`)}`,
`pnpm link ${packagePath}`,
`cd ${projectRoot}`,
].join(' && '),
);

consola.info(`Run ${playground}:${script}`);
exec(`pnpm --filter @playground/${playground} ${script}`);
} catch {
Expand All @@ -22,7 +47,6 @@ async function main() {
}

async function selectPlayground() {
const playgrounds = readdirSync(resolve('playgrounds'));
const { playground } = await enquirer.prompt<{
playground: string;
}>({
Expand Down
10 changes: 9 additions & 1 deletion scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isPromise } from 'node:util/types';
import { ExecSyncOptions, execSync } from 'node:child_process';
import { PathOrFileDescriptor, readFileSync, writeFileSync } from 'node:fs';
import { PathOrFileDescriptor, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { fileURLToPath, URL } from 'node:url';
import { resolve } from 'node:path';

Expand All @@ -10,6 +10,14 @@ export const projectRoot = joinURLToPath(import.meta.url, '../');
export const clientRoot = resolve(projectRoot, 'packages/client');
// Package shared root
export const sharedRoot = resolve(projectRoot, 'packages/shared');
// Package rollup root
export const rollupRoot = resolve(projectRoot, 'packages/rollup');
// Package vite root
export const viteRoot = resolve(projectRoot, 'packages/vite');
// Package webpack root
export const webpackRoot = resolve(projectRoot, 'packages/webpack');

export const playgrounds = readdirSync(resolve(projectRoot, 'playgrounds'));

export function joinURLToPath(url: string, relative: string) {
return fileURLToPath(new URL(relative, url));
Expand Down

0 comments on commit b0ebda5

Please sign in to comment.