Skip to content

Commit f048f63

Browse files
authored
fix: cli polyfill (bytedance#365)
* fix: cli polyfill * fix: run playwright in e2e folder
1 parent a6d61d3 commit f048f63

File tree

2 files changed

+94
-91
lines changed

2 files changed

+94
-91
lines changed

.github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: node common/scripts/install-run-rush.js build
2525

2626
- name: Install Playwright Browsers
27-
run: npx playwright install --with-deps
27+
run: pushd e2e/fixed-layout && npx playwright install --with-deps && popd
2828

2929
- name: Run E2E tests
3030
run: node common/scripts/install-run-rush.js e2e:test --verbose

apps/create-app/src/index.ts

Lines changed: 93 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -20,113 +20,116 @@ const updateFlowGramVersions = (dependencies: any[], latestVersion: string) => {
2020
}
2121
}
2222

23-
program
24-
.version('1.0.0')
25-
.description('Create a demo project')
26-
.action(async () => {
27-
console.log(chalk.green('Welcome to @flowgram.ai/create-app CLI!'));
28-
const latest = execSync('npm view @flowgram.ai/demo-fixed-layout version --tag=latest latest').toString().trim();
29-
30-
let folderName = ''
31-
32-
if (!args?.length) {
33-
// 询问用户选择 demo 项目
34-
const { repo } = await inquirer.prompt([
35-
{
36-
type: 'list',
37-
name: 'repo',
38-
message: 'Select a demo to create:',
39-
choices: [
40-
{ name: 'Fixed Layout Demo', value: 'demo-fixed-layout' },
41-
{ name: 'Free Layout Demo', value: 'demo-free-layout' },
42-
{ name: 'Fixed Layout Demo Simple', value: 'demo-fixed-layout-simple' },
43-
{ name: 'Free Layout Demo Simple', value: 'demo-free-layout-simple' },
44-
{ name: 'Free Layout Nextjs Demo', value: 'demo-nextjs' },
45-
{ name: 'Free Layout Vite Demo Simple', value: 'demo-vite' }
46-
],
47-
},
48-
]);
49-
50-
folderName = repo;
23+
const main = async () => {
24+
console.log(chalk.green('Welcome to @flowgram.ai/create-app CLI!'));
25+
const latest = execSync('npm view @flowgram.ai/demo-fixed-layout version --tag=latest latest').toString().trim();
26+
27+
let folderName = ''
28+
29+
if (!args?.length) {
30+
// 询问用户选择 demo 项目
31+
const { repo } = await inquirer.prompt([
32+
{
33+
type: 'list',
34+
name: 'repo',
35+
message: 'Select a demo to create:',
36+
choices: [
37+
{ name: 'Fixed Layout Demo', value: 'demo-fixed-layout' },
38+
{ name: 'Free Layout Demo', value: 'demo-free-layout' },
39+
{ name: 'Fixed Layout Demo Simple', value: 'demo-fixed-layout-simple' },
40+
{ name: 'Free Layout Demo Simple', value: 'demo-free-layout-simple' },
41+
{ name: 'Free Layout Nextjs Demo', value: 'demo-nextjs' },
42+
{ name: 'Free Layout Vite Demo Simple', value: 'demo-vite' }
43+
],
44+
},
45+
]);
46+
47+
folderName = repo;
48+
} else {
49+
if (['fixed-layout', 'free-layout', 'fixed-layout-simple', 'free-layout-simple', 'nextjs'].includes(args[0])) {
50+
folderName = `demo-${args[0]}`;
5151
} else {
52-
if (['fixed-layout', 'free-layout', 'fixed-layout-simple', 'free-layout-simple', 'nextjs'].includes(args[0])) {
53-
folderName = `demo-${args[0]}`;
54-
} else {
55-
console.error('Invalid argument. Please run "npx create-app" to choose demo.');
56-
return;
57-
}
52+
console.error('Invalid argument. Please run "npx create-app" to choose demo.');
53+
return;
5854
}
55+
}
5956

60-
try {
61-
const targetDir = path.join(process.cwd());
62-
// 下载 npm 包的 tarball
63-
const downloadPackage = async () => {
64-
try {
65-
// 从 npm registry 下载 tarball 文件
66-
const tarballBuffer = await download(`https://registry.npmjs.org/@flowgram.ai/${folderName}/-/${folderName}-${latest}.tgz`);
57+
try {
58+
const targetDir = path.join(process.cwd());
59+
// 下载 npm 包的 tarball
60+
const downloadPackage = async () => {
61+
try {
62+
// 从 npm registry 下载 tarball 文件
63+
const tarballBuffer = await download(`https://registry.npmjs.org/@flowgram.ai/${folderName}/-/${folderName}-${latest}.tgz`);
6764

68-
// 确保目标文件夹存在
69-
fs.ensureDirSync(targetDir);
65+
// 确保目标文件夹存在
66+
fs.ensureDirSync(targetDir);
7067

71-
// 创建一个临时文件名来保存 tarball 数据
72-
const tempTarballPath = path.join(process.cwd(), `${folderName}.tgz`);
68+
// 创建一个临时文件名来保存 tarball 数据
69+
const tempTarballPath = path.join(process.cwd(), `${folderName}.tgz`);
7370

74-
// 将下载的 tarball 写入临时文件
75-
fs.writeFileSync(tempTarballPath, tarballBuffer);
71+
// 将下载的 tarball 写入临时文件
72+
fs.writeFileSync(tempTarballPath, tarballBuffer);
7673

77-
// 解压 tarball 文件到目标文件夹
78-
await tar.x({
79-
file: tempTarballPath,
80-
C: targetDir,
81-
});
74+
// 解压 tarball 文件到目标文件夹
75+
await tar.x({
76+
file: tempTarballPath,
77+
C: targetDir,
78+
});
8279

83-
fs.renameSync(path.join(targetDir, 'package'), path.join(targetDir, folderName))
80+
fs.renameSync(path.join(targetDir, 'package'), path.join(targetDir, folderName))
8481

85-
// 删除下载的 tarball 文件
86-
fs.unlinkSync(tempTarballPath);
87-
return true;
82+
// 删除下载的 tarball 文件
83+
fs.unlinkSync(tempTarballPath);
84+
return true;
8885

89-
} catch (error) {
90-
console.error(`Error downloading or extracting package: ${error}`);
91-
return false;
92-
}
93-
};
94-
const res = await downloadPackage();
86+
} catch (error) {
87+
console.error(`Error downloading or extracting package: ${error}`);
88+
return false;
89+
}
90+
};
91+
const res = await downloadPackage();
9592

96-
// 下载完成后,执行操作,替换 package.json 文件内部的所有 @flowgram.ai 包版本为 latest
97-
const pkgJsonPath = path.join(targetDir, folderName, 'package.json');
98-
const data = fs.readFileSync(pkgJsonPath, 'utf-8');
93+
// 下载完成后,执行操作,替换 package.json 文件内部的所有 @flowgram.ai 包版本为 latest
94+
const pkgJsonPath = path.join(targetDir, folderName, 'package.json');
95+
const data = fs.readFileSync(pkgJsonPath, 'utf-8');
9996

100-
const packageLatestVersion = execSync('npm view @flowgram.ai/core version --tag=latest latest').toString().trim();
97+
const packageLatestVersion = execSync('npm view @flowgram.ai/core version --tag=latest latest').toString().trim();
10198

102-
const jsonData = JSON.parse(data);
103-
if (jsonData.dependencies) {
104-
updateFlowGramVersions(jsonData.dependencies, packageLatestVersion);
105-
}
99+
const jsonData = JSON.parse(data);
100+
if (jsonData.dependencies) {
101+
updateFlowGramVersions(jsonData.dependencies, packageLatestVersion);
102+
}
106103

107-
if (jsonData.devDependencies) {
108-
updateFlowGramVersions(jsonData.devDependencies, packageLatestVersion);
109-
}
104+
if (jsonData.devDependencies) {
105+
updateFlowGramVersions(jsonData.devDependencies, packageLatestVersion);
106+
}
110107

111-
// 修改完成后写入
112-
fs.writeFileSync(pkgJsonPath, JSON.stringify(jsonData, null, 2), 'utf-8');
108+
// 修改完成后写入
109+
fs.writeFileSync(pkgJsonPath, JSON.stringify(jsonData, null, 2), 'utf-8');
113110

114-
if (res) {
115-
// 克隆项目
116-
console.log(chalk.green(`${folderName} Demo project created successfully!`));
111+
if (res) {
112+
// 克隆项目
113+
console.log(chalk.green(`${folderName} Demo project created successfully!`));
117114

118-
console.log(chalk.yellow('Run the following commands to start:'));
119-
console.log(chalk.cyan(` cd ${folderName}`));
120-
console.log(chalk.cyan(' npm install'));
121-
console.log(chalk.cyan(' npm start'));
122-
} else {
123-
console.log(chalk.red('Download failed'))
124-
}
125-
126-
} catch (error) {
127-
console.error('Error downloading repo:', error);
128-
return;
115+
console.log(chalk.yellow('Run the following commands to start:'));
116+
console.log(chalk.cyan(` cd ${folderName}`));
117+
console.log(chalk.cyan(' npm install'));
118+
console.log(chalk.cyan(' npm start'));
119+
} else {
120+
console.log(chalk.red('Download failed'))
129121
}
130-
});
122+
123+
} catch (error) {
124+
console.error('Error downloading repo:', error);
125+
return;
126+
}
127+
}
128+
129+
program
130+
.version('1.0.0')
131+
.description('Create a demo project')
131132

132133
program.parse(process.argv);
134+
135+
main();

0 commit comments

Comments
 (0)