Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions packages/cli/src/skills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -35,14 +49,24 @@ export const skillsCommand = (args: string[], logLevel: LogLevel) => {
}

const command = process.platform === 'win32' ? 'npx.cmd' : 'npx';
const fullArgs = [
'-y',
'--loglevel=error',
'skills@1.5.20',
subcommand,
'remotion-dev/skills',
...restArgs,
];
const fullArgs =
subcommand === 'add'
? [
'--loglevel=error',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code passed -y as an npx flag to suppress the installation confirmation prompt. The new code removes it and puts --yes at the end of the arg list, which is passed to the skills CLI rather than to npx. If skills@1.5.20 is not already cached, npx will prompt interactively. Consider keeping -y in the npx args (before the package name) as a belt-and-suspenders measure alongside the --yes for the skills CLI.

'skills@1.5.20',
'add',
'remotion-dev/skills',
...restArgs,
'--yes',
]
: [
'--loglevel=error',
'skills',
'update',
...remotionSkillNames,
...restArgs,
'--yes',
];

const child = spawn(command, fullArgs, {
stdio: 'inherit',
Expand Down
118 changes: 118 additions & 0 deletions packages/cli/src/test/skills.test.ts
Original file line number Diff line number Diff line change
@@ -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',
'skills@1.5.20',
'add',
'remotion-dev/skills',
'--yes',
]);
expect(updateArguments).toEqual([
'--loglevel=error',
'skills',
'update',
...remotionSkillNames,
'--yes',
]);
} finally {
rmSync(temporaryDirectory, {recursive: true, force: true});
}
});
1 change: 1 addition & 0 deletions packages/studio-server/src/test/insert-element.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const makeFixture = () => {
return prepareElementInstallHandler({
binariesDirectory: null,
configFile: null,
getDefaultEditor: () => null,
entryPoint: compositionFile,
input,
logLevel: 'error',
Expand Down
Loading