mirror of
https://github.com/zen-browser/surfer.git
synced 2025-07-08 17:30:02 +02:00
🐛 Don't copy all optional files in copyOptional([])
This commit is contained in:
parent
40bb62a414
commit
4398215ead
2 changed files with 44 additions and 11 deletions
21
src/commands/setup-project.test.ts
Normal file
21
src/commands/setup-project.test.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import { shouldSkipOptionalCopy } from './setup-project'
|
||||||
|
|
||||||
|
describe('shouldSkipOptionalCopy', () => {
|
||||||
|
it('Returns true if the file is not optional', () => {
|
||||||
|
expect(
|
||||||
|
shouldSkipOptionalCopy('something/somethingelse', ["doesn't matter"])
|
||||||
|
).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Returns true if the file is not in the array', () => {
|
||||||
|
expect(
|
||||||
|
shouldSkipOptionalCopy('something/somethingelse.optional', ['not_here'])
|
||||||
|
).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Returns false if the file is optional and in the array', () => {
|
||||||
|
expect(
|
||||||
|
shouldSkipOptionalCopy('something/somethingelse.optional', ['something'])
|
||||||
|
).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
|
@ -6,7 +6,7 @@ import { copyFile } from 'node:fs/promises'
|
||||||
import { join, dirname } from 'node:path'
|
import { join, dirname } from 'node:path'
|
||||||
|
|
||||||
import prompts from 'prompts'
|
import prompts from 'prompts'
|
||||||
import { bin_name } from '..'
|
import { BIN_NAME } from '../constants'
|
||||||
|
|
||||||
import { log } from '../log'
|
import { log } from '../log'
|
||||||
import {
|
import {
|
||||||
|
@ -165,7 +165,7 @@ export async function setupProject(): Promise<void> {
|
||||||
log.success(
|
log.success(
|
||||||
'Project setup complete!',
|
'Project setup complete!',
|
||||||
'',
|
'',
|
||||||
`You can start downloading the Firefox source code by running |${bin_name} download|`,
|
`You can start downloading the Firefox source code by running |${BIN_NAME} download|`,
|
||||||
'Or you can follow the getting started guide at https://docs.gluon.dev/getting-started/overview/'
|
'Or you can follow the getting started guide at https://docs.gluon.dev/getting-started/overview/'
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -187,15 +187,8 @@ export const templateDirectory = join(__dirname, '../..', 'template')
|
||||||
*/
|
*/
|
||||||
async function copyOptional(files: string[]) {
|
async function copyOptional(files: string[]) {
|
||||||
const directoryContents = await walkDirectory(templateDirectory)
|
const directoryContents = await walkDirectory(templateDirectory)
|
||||||
|
|
||||||
for (const file of directoryContents) {
|
for (const file of directoryContents) {
|
||||||
if (
|
if (shouldSkipOptionalCopy(file, files)) continue
|
||||||
!file.includes('.optional') &&
|
|
||||||
!files
|
|
||||||
.map((induvidualFile) => file.includes(induvidualFile))
|
|
||||||
.some(Boolean)
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
|
|
||||||
const outLocation = join(
|
const outLocation = join(
|
||||||
projectDirectory,
|
projectDirectory,
|
||||||
|
@ -209,6 +202,26 @@ async function copyOptional(files: string[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to determine if a file should be copied or not. This is exported only so
|
||||||
|
* that it can be unit tested
|
||||||
|
*
|
||||||
|
* @param file The file that should be copied
|
||||||
|
* @param files A list of files / directories that we want to match to
|
||||||
|
* @returns If the file should be skipped
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
export function shouldSkipOptionalCopy(file: string, files: string[]): boolean {
|
||||||
|
// We want to skip copying this file if:
|
||||||
|
// - It is not optional
|
||||||
|
// - It is not in the files array
|
||||||
|
return (
|
||||||
|
!file.includes('.optional') ||
|
||||||
|
!files.map((f) => file.includes(f)).some(Boolean)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy all non-optional files from the template directory
|
* Copy all non-optional files from the template directory
|
||||||
*/
|
*/
|
||||||
|
@ -217,7 +230,6 @@ async function copyRequired() {
|
||||||
|
|
||||||
for (const file of directoryContents) {
|
for (const file of directoryContents) {
|
||||||
if (file.includes('.optional')) continue
|
if (file.includes('.optional')) continue
|
||||||
|
|
||||||
const outLocation = join(
|
const outLocation = join(
|
||||||
projectDirectory,
|
projectDirectory,
|
||||||
file.replace(templateDirectory, '')
|
file.replace(templateDirectory, '')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue