Skip to content

Commit

Permalink
fix: symlink lingering in public folder and added to git (#92)
Browse files Browse the repository at this point in the history
* fix: export types

* fix: add rest & local symlink to main gitignore

* fix: `_next-video` smylink. no collide & recognize
  • Loading branch information
luwes committed Nov 2, 2023
1 parent 3d9c428 commit 84ccc55
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ import { Argv, Arguments } from 'yargs';

import os from 'node:os';
import { exec } from 'node:child_process';
import { access, mkdir, stat, readFile, writeFile } from 'node:fs/promises';
import { access, mkdir, stat, readFile, writeFile, appendFile } from 'node:fs/promises';
import path from 'node:path';

import log, { Logger } from '../logger.js';
import { checkPackageJsonForNextVideo, updateTSConfigFileContent } from './lib/json-configs.js';
import updateNextConfigFile from './lib/next-config.js';

const GITIGNORE_CONTENTS = `*
!*.json
!*.js
!*.ts`;

const TYPES_FILE_CONTENTS = `/// <reference types="next-video/video-types/global" />\n`;

const DEFAULT_DIR = 'videos';
const DEV_SCRIPT = '& npx next-video sync -w';

const gitIgnoreContents = (videosDir: string) => `
${videosDir}/*
${videosDir}/!*.json
${videosDir}/!*.js
${videosDir}/!*.ts
public/_next-video`;

async function preInitCheck(dir: string) {
try {
await stat(dir);
Expand Down Expand Up @@ -75,7 +76,7 @@ async function createVideoDir(dir: string) {
const fullPath = path.join(process.cwd(), dir);

await mkdir(fullPath, { recursive: true });
await writeFile(path.join(dir, '.gitignore'), GITIGNORE_CONTENTS);
await appendFile('.gitignore', gitIgnoreContents(dir));
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const FILES_FOLDER = `${config.folder ?? 'videos'}/`;

export const toSymlinkPath = (path?: string) => {
if (!path?.startsWith(FILES_FOLDER)) return path;
return path?.replace(FILES_FOLDER, `_${FILES_FOLDER}`);
return path?.replace(FILES_FOLDER, `_next-video/`);
}

// Note: doesn't get updated when the callback function changes
Expand Down
6 changes: 6 additions & 0 deletions src/components/video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ export function getVideoProps(allProps: VideoProps, state: { asset?: Asset }) {
}

export default NextVideo;

export type {
VideoLoaderProps,
VideoProps,
DefaultPlayerProps,
};
2 changes: 1 addition & 1 deletion src/with-next-video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default async function withNextVideo(nextConfig: any, videoConfig: VideoC
env['NEXT_PUBLIC_DEV_VIDEO_OPTS'] = JSON.stringify({ path, folder });

const VIDEOS_PATH = join(process.cwd(), folder)
const TMP_PUBLIC_VIDEOS_PATH = join(process.cwd(), 'public', `_${folder}`);
const TMP_PUBLIC_VIDEOS_PATH = join(process.cwd(), 'public', `_next-video`);

await symlinkDir(VIDEOS_PATH, TMP_PUBLIC_VIDEOS_PATH);

Expand Down

0 comments on commit 84ccc55

Please sign in to comment.