-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathnew
More file actions
executable file
·248 lines (218 loc) · 6.52 KB
/
Copy pathnew
File metadata and controls
executable file
·248 lines (218 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env bun
import {randomUUID} from 'node:crypto';
import {tmpdir} from 'node:os';
import {
cpSync,
existsSync,
mkdirSync,
readFileSync,
readdirSync,
writeFileSync,
} from 'node:fs';
import {basename, dirname, join, relative} from 'node:path';
import {pathToFileURL} from 'node:url';
import {
addTailwindRootCss,
addTailwindToConfig,
} from './packages/create-video/src/add-tailwind';
import {createPublicFolder} from './packages/create-video/src/create-public-folder';
import {patchPackageJson} from './packages/create-video/src/patch-package-json';
import {patchReadmeMd} from './packages/create-video/src/patch-readme';
import {FEATURED_TEMPLATES} from './packages/create-video/src/templates';
import {localPackageRootKey} from './packages/studio-server/src/helpers/get-local-package-override';
const repositoryRoot = import.meta.dir;
const agentPluginRoot = join(repositoryRoot, 'packages', 'agent-plugin');
const useOldVersion = process.argv.includes('--old');
const useCreateVideo = process.argv.includes('--create');
const run = (command: string[], cwd = repositoryRoot) => {
const result = Bun.spawnSync(command, {
cwd,
stdin: 'inherit',
stdout: 'inherit',
stderr: 'inherit',
});
if (result.exitCode !== 0) {
throw new Error(`Command failed: ${command.join(' ')}`);
}
};
if (useCreateVideo) {
console.log('Building create-video...');
run(['bunx', 'turbo', 'run', 'make', '--filter=create-video', '--no-update-notifier']);
console.log('\nRunning create-video...');
run(
[
'node',
join(repositoryRoot, 'packages', 'create-video', 'bin.js'),
'--yes',
'--blank',
'--tmp',
],
tmpdir(),
);
process.exit(0);
}
if (!useOldVersion) {
console.log('Building the current repository state...');
run(['bunx', 'turbo', 'run', 'make', '--no-update-notifier']);
}
console.log('\nBuilding agent skills...');
run(['bun', 'run', 'build'], agentPluginRoot);
const projectRoot = join('/tmp', `remotion-video-${randomUUID().slice(0, 8)}`);
mkdirSync(projectRoot);
const listedFiles = Bun.spawnSync(
[
'git',
'ls-files',
'--cached',
'--others',
'--exclude-standard',
'--',
'packages/template-blank',
],
{cwd: repositoryRoot},
);
if (listedFiles.exitCode !== 0) {
throw new Error(listedFiles.stderr.toString());
}
for (const file of listedFiles.stdout.toString().trim().split('\n')) {
if (file === '') {
continue;
}
const relativePath = relative('packages/template-blank', file);
const destination = join(projectRoot, relativePath);
mkdirSync(dirname(destination), {recursive: true});
cpSync(join(repositoryRoot, file), destination, {dereference: true});
}
const blankTemplate = FEATURED_TEMPLATES.find(
(template) => template.cliId === 'blank',
);
if (!blankTemplate) {
throw new Error('Could not find the blank create-video template.');
}
addTailwindToConfig(projectRoot);
addTailwindRootCss(projectRoot);
createPublicFolder(projectRoot);
patchReadmeMd(projectRoot, 'npm', blankTemplate);
const currentVersion = JSON.parse(
readFileSync(
join(repositoryRoot, 'packages', 'core', 'package.json'),
'utf8',
),
).version as string;
let remotionVersion = currentVersion;
if (useOldVersion) {
const publishedVersions = Bun.spawnSync(
['npm', 'view', 'remotion', 'versions', '--json'],
{cwd: repositoryRoot},
);
if (publishedVersions.exitCode !== 0) {
throw new Error(publishedVersions.stderr.toString());
}
const stableVersions = (
JSON.parse(publishedVersions.stdout.toString()) as string[]
).filter((version) => /^\d+\.\d+\.\d+$/.test(version));
if (stableVersions.length < 2) {
throw new Error('Could not find two published stable Remotion versions.');
}
remotionVersion = stableVersions[stableVersions.length - 2];
console.log(`Using the previous stable Remotion release: ${remotionVersion}`);
}
patchPackageJson({
projectRoot,
projectName: basename(projectRoot),
latestRemotionVersion: remotionVersion,
packageManager: 'npm',
addTailwind: true,
});
if (!useOldVersion) {
const localPackageOverrides: Record<string, string> = {};
const packagesRoot = join(repositoryRoot, 'packages');
for (const directory of readdirSync(packagesRoot)) {
const packageDirectory = join(packagesRoot, directory);
const packageJsonPath = join(packageDirectory, 'package.json');
if (!existsSync(packageJsonPath)) {
continue;
}
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
if (
packageJson.private ||
(packageJson.name !== 'remotion' &&
!packageJson.name?.startsWith('@remotion/'))
) {
continue;
}
localPackageOverrides[packageJson.name] =
pathToFileURL(packageDirectory).href;
}
const projectPackageJsonPath = join(projectRoot, 'package.json');
const projectPackageJson = JSON.parse(
readFileSync(projectPackageJsonPath, 'utf8'),
);
for (const dependencyType of ['dependencies', 'devDependencies'] as const) {
for (const dependency of Object.keys(
projectPackageJson[dependencyType] ?? {},
)) {
const localPackageOverride = localPackageOverrides[dependency];
if (localPackageOverride) {
projectPackageJson[dependencyType][dependency] = localPackageOverride;
}
}
}
projectPackageJson[localPackageRootKey] = repositoryRoot;
writeFileSync(
projectPackageJsonPath,
JSON.stringify(projectPackageJson, null, 2),
);
}
const gitInit = Bun.spawnSync(['git', 'init', '--quiet'], {
cwd: projectRoot,
stderr: 'inherit',
});
if (gitInit.exitCode === 0) {
Bun.spawnSync(['git', 'add', '--all'], {cwd: projectRoot});
Bun.spawnSync(
['git', 'commit', '--quiet', '-m', 'Create new Remotion video'],
{
cwd: projectRoot,
},
);
Bun.spawnSync(['git', 'branch', '-M', 'main'], {cwd: projectRoot});
}
console.log('\nInstalling the freshly built agent skills...');
run(
[
'bunx',
'-y',
'--loglevel=error',
'skills@1.5.26',
'add',
agentPluginRoot,
'--yes',
],
projectRoot,
);
console.log('\nInstalling npm dependencies...');
run(['npm', 'i'], projectRoot);
if (gitInit.exitCode === 0) {
Bun.spawnSync(['git', 'add', '--all'], {cwd: projectRoot});
Bun.spawnSync(
['git', 'commit', '--quiet', '-m', 'Install dependencies and agent skills'],
{
cwd: projectRoot,
},
);
}
console.log(`\nNew Remotion project ready at ${projectRoot}`);
process.chdir(projectRoot);
if (process.stdin.isTTY && process.stdout.isTTY) {
console.log('Opening a shell in the new project. Run `exit` to return.\n');
const shell = process.env.SHELL ?? '/bin/sh';
const result = Bun.spawnSync([shell, '-l'], {
cwd: projectRoot,
stdin: 'inherit',
stdout: 'inherit',
stderr: 'inherit',
});
process.exit(result.exitCode);
}
console.log(`Run: cd ${projectRoot}`);