🎥 Make videos programmatically with React
`@remotion/cli`: Update skills commands (#9940)
Jonny Burger73965b0c4cfc
diff --git a/packages/cli/src/skills.ts b/packages/cli/src/skills.tsindex 9891480afd..af46717396 100644--- a/packages/cli/src/skills.ts+++ b/packages/cli/src/skills.ts@@ -3,6 +3,20 @@ import type {LogLevel} from '@remotion/renderer';import {chalk} from './chalk';import {Log} from './log';+const remotionSkillNames = [+ 'remotion-best-practices',+ 'remotion-captions',+ 'remotion-create',+ 'remotion-docs',+ 'remotion-interactivity',+ 'remotion-maps',+ 'remotion-markup',+ 'remotion-multimedia',+ 'remotion-render',+ 'remotion-saas',+ 'remotion-upgrade',+];+export const printSkillsHelp = (logLevel: LogLevel) => {Log.info({indent: false, logLevel}, chalk.blue('remotion skills'));Log.info(@@ -35,14 +49,24 @@ export const skillsCommand = (args: string[], logLevel: LogLevel) => {}const command = process.platform === 'win32' ? 'npx.cmd' : 'npx';- const fullArgs = [- '-y',- '--loglevel=error',- '[email protected]',- subcommand,- 'remotion-dev/skills',- ...restArgs,- ];+ const fullArgs =+ subcommand === 'add'+ ? [+ '--loglevel=error',+ '[email protected]',+ 'add',+ 'remotion-dev/skills',+ ...restArgs,+ '--yes',+ ]+ : [+ '--loglevel=error',+ 'skills',+ 'update',+ ...remotionSkillNames,+ ...restArgs,+ '--yes',+ ];const child = spawn(command, fullArgs, {stdio: 'inherit',diff --git a/packages/cli/src/test/skills.test.ts b/packages/cli/src/test/skills.test.tsnew file mode 100644index 0000000000..db92d52fd1--- /dev/null+++ b/packages/cli/src/test/skills.test.ts@@ -0,0 +1,118 @@+import {expect, test} from 'bun:test';+import {spawn} from 'node:child_process';+import {+ chmodSync,+ mkdtempSync,+ readdirSync,+ readFileSync,+ rmSync,+ writeFileSync,+} from 'node:fs';+import {tmpdir} from 'node:os';+import path from 'node:path';++const runSkillsCommand = ({+ args,+ fakeNpxDirectory,+ outputFile,+}: {+ args: string[];+ fakeNpxDirectory: string;+ outputFile: string;+}) => {+ return new Promise<void>((resolve, reject) => {+ const cliPath = path.join(__dirname, '..', '..', 'remotion-cli.js');+ const child = spawn(process.execPath, [cliPath, 'skills', ...args], {+ env: {+ ...process.env,+ PATH: `${fakeNpxDirectory}${path.delimiter}${process.env.PATH}`,+ REMOTION_SKILLS_TEST_OUTPUT: outputFile,+ },+ stdio: 'inherit',+ });++ child.on('error', reject);+ child.on('exit', (code) => {+ if (code === 0) {+ resolve();+ } else {+ reject(new Error(`Remotion CLI exited with code ${code}`));+ }+ });+ });+};++test('forwards the correct arguments to the skills CLI', async () => {+ const temporaryDirectory = mkdtempSync(+ path.join(tmpdir(), 'remotion-skills-cli-'),+ );+ const fakeNpxPath = path.join(+ temporaryDirectory,+ process.platform === 'win32' ? 'npx.cmd' : 'npx',+ );+ const outputFile = path.join(temporaryDirectory, 'arguments.jsonl');+ const fakeNpxScript = `import {appendFileSync} from 'node:fs';+appendFileSync(process.env.REMOTION_SKILLS_TEST_OUTPUT, JSON.stringify(process.argv.slice(2)) + '\\n');+`;++ try {+ if (process.platform === 'win32') {+ const fakeNpxScriptPath = path.join(temporaryDirectory, 'fake-npx.mjs');+ writeFileSync(fakeNpxScriptPath, fakeNpxScript);+ writeFileSync(+ fakeNpxPath,+ `@"${process.execPath}" "${fakeNpxScriptPath}" %*\r\n`,+ );+ } else {+ writeFileSync(fakeNpxPath, `#!${process.execPath}\n${fakeNpxScript}`);+ chmodSync(fakeNpxPath, 0o755);+ }++ await runSkillsCommand({+ args: ['add'],+ fakeNpxDirectory: temporaryDirectory,+ outputFile,+ });+ await runSkillsCommand({+ args: ['update'],+ fakeNpxDirectory: temporaryDirectory,+ outputFile,+ });++ const [addArguments, updateArguments] = readFileSync(outputFile, 'utf8')+ .trim()+ .split('\n')+ .map((line) => JSON.parse(line));+ const skillsDirectory = path.join(+ __dirname,+ '..',+ '..',+ '..',+ 'skills',+ 'skills',+ );+ const remotionSkillNames = readdirSync(skillsDirectory, {+ withFileTypes: true,+ })+ .filter((entry) => entry.isDirectory())+ .map((entry) => entry.name)+ .sort();++ expect(addArguments).toEqual([+ '--loglevel=error',+ '[email protected]',+ 'add',+ 'remotion-dev/skills',+ '--yes',+ ]);+ expect(updateArguments).toEqual([+ '--loglevel=error',+ 'skills',+ 'update',+ ...remotionSkillNames,+ '--yes',+ ]);+ } finally {+ rmSync(temporaryDirectory, {recursive: true, force: true});+ }+});diff --git a/packages/studio-server/src/test/insert-element.test.ts b/packages/studio-server/src/test/insert-element.test.tsindex 21c102b741..da8c79ce79 100644--- a/packages/studio-server/src/test/insert-element.test.ts+++ b/packages/studio-server/src/test/insert-element.test.ts@@ -120,6 +120,7 @@ const makeFixture = () => {return prepareElementInstallHandler({binariesDirectory: null,configFile: null,+ getDefaultEditor: () => null,entryPoint: compositionFile,input,logLevel: 'error',