-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fedac90
commit 0f56875
Showing
17 changed files
with
511 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,80 @@ | ||
import extensionsAndMIMETypes from '@/data/extensionsAndMIMETypes.json'; | ||
import roles from '@/data/roles.json'; | ||
import type { DocumentType } from '@/types'; | ||
import utis from '@/data/utis.json'; | ||
import { DocumentType } from '@/lib/macos/launchServices/interfaces'; | ||
import { DocumentTypeSchema } from '@/lib/macos/launchServices/schemas'; | ||
import { faker } from '@faker-js/faker'; | ||
import { Factory } from 'fishery'; | ||
|
||
class DocumentTypeFactory extends Factory<DocumentType> {} | ||
|
||
export const documentTypeFactory = DocumentTypeFactory.define(() => { | ||
const [extension, mimeType] = faker.helpers.objectEntry( | ||
extensionsAndMIMETypes, | ||
); | ||
|
||
const role = faker.helpers.arrayElement(roles); | ||
const appID = | ||
faker.internet.domainSuffix() + | ||
'.' + | ||
faker.internet.domainWord() + | ||
'.' + | ||
faker.word.noun(); | ||
|
||
return { | ||
CFBundleTypeExtensions: [extension], | ||
CFBundleTypeMIMETypes: [mimeType], | ||
CFBundleTypeRole: role as DocumentType['CFBundleTypeRole'], | ||
uti: faker.helpers.arrayElement(utis), | ||
role: faker.helpers.arrayElement(roles) as DocumentType['role'], | ||
appID, | ||
appVersion: faker.system.semver(), | ||
type: 'DocumentType' as DocumentType['type'], | ||
}; | ||
}); | ||
|
||
class DocumentTypeSchemaFactory extends Factory<DocumentTypeSchema> {} | ||
|
||
export const documentTypeSchemaFactory = DocumentTypeSchemaFactory.define( | ||
() => { | ||
const documentType = documentTypeFactory.build(); | ||
const LSHandlerContentType = documentType.uti; | ||
const { appID, appVersion } = documentType; | ||
|
||
switch (documentType.role) { | ||
case 'Viewer': | ||
return { | ||
LSHandlerContentType, | ||
LSHandlerRoleViewer: appID, | ||
LSHandlerPreferredVersions: { | ||
LSHandlerRoleViewer: appVersion, | ||
}, | ||
}; | ||
case 'Shell': | ||
return { | ||
LSHandlerContentType, | ||
LSHandlerRoleShell: appID, | ||
LSHandlerPreferredVersions: { | ||
LSHandlerRoleShell: appVersion, | ||
}, | ||
}; | ||
case 'QLGenerator': | ||
return { | ||
LSHandlerContentType, | ||
LSHandlerRoleQLGenerator: appID, | ||
LSHandlerPreferredVersions: { | ||
LSHandlerRoleQLGenerator: appVersion, | ||
}, | ||
}; | ||
case 'None': | ||
return { | ||
LSHandlerContentType, | ||
LSHandlerRoleNone: appID, | ||
LSHandlerPreferredVersions: { | ||
LSHandlerRoleNone: appVersion, | ||
}, | ||
}; | ||
case 'All': | ||
return { | ||
LSHandlerContentType, | ||
LSHandlerRoleAll: appID, | ||
LSHandlerPreferredVersions: { | ||
LSHandlerRoleAll: appVersion, | ||
}, | ||
}; | ||
default: | ||
throw new Error(); | ||
Check failure on line 77 in src/factories/documentType.ts
|
||
} | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { documentTypeFactory } from './documentType'; | ||
export { infoPlistFactory } from './infoPlist'; | ||
export { lsHandlerFactory } from './lsHandler'; | ||
export { urlTypeFactory } from './urlType'; | ||
export { documentTypeFactory, documentTypeSchemaFactory } from './documentType'; | ||
export { launchServicesSchemaFactory } from './launchServices'; | ||
export { lsHandlerFactory, lsHandlerSchemaFactory } from './lsHandler'; | ||
export { urlSchemeFactory, urlSchemeSchemaFactory } from './urlScheme'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { LaunchServicesSchema } from '@/lib/macos/launchServices/schemas'; | ||
import { Factory } from 'fishery'; | ||
import { lsHandlerSchemaFactory } from './lsHandler'; | ||
|
||
class LaunchServicesSchemaFactory extends Factory<LaunchServicesSchema> {} | ||
|
||
export const launchServicesSchemaFactory = LaunchServicesSchemaFactory.define( | ||
() => { | ||
const launchServices = lsHandlerSchemaFactory.buildList(25); | ||
return { | ||
LSHandlers: launchServices, | ||
}; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,42 @@ | ||
import roles from '@/data/roles.json'; | ||
import urlSchemes from '@/data/urlSchemes.json'; | ||
import utis from '@/data/utis.json'; | ||
import type { | ||
LSHandler, | ||
LSHandlerDocumentType, | ||
LSHandlerURLScheme, | ||
} from '@/types'; | ||
import { LSHandler } from '@/lib/macos/launchServices/interfaces'; | ||
import { LSHandlerSchema } from '@/lib/macos/launchServices/schemas'; | ||
import { faker } from '@faker-js/faker'; | ||
import { Factory } from 'fishery'; | ||
|
||
class LSHandlerFactory extends Factory< | ||
LSHandler, | ||
{ documentType?: boolean; urlScheme?: boolean } | ||
> { | ||
buildDocumentType() { | ||
return this.transient({ | ||
documentType: true, | ||
}).build() as LSHandlerDocumentType; | ||
} | ||
|
||
buildURLScheme() { | ||
return this.transient({ | ||
urlScheme: true, | ||
}).build() as LSHandlerURLScheme; | ||
import { documentTypeFactory, documentTypeSchemaFactory } from './documentType'; | ||
import { urlSchemeFactory, urlSchemeSchemaFactory } from './urlScheme'; | ||
|
||
class LSHandlerFactory extends Factory<LSHandler> {} | ||
|
||
export const lsHandlerFactory = LSHandlerFactory.define(() => { | ||
const lsHandlerType = faker.helpers.arrayElement([ | ||
'DocumentType', | ||
'URLScheme', | ||
]); | ||
|
||
switch (lsHandlerType) { | ||
case 'DocumentType': | ||
return documentTypeFactory.build(); | ||
case 'URLScheme': | ||
return urlSchemeFactory.build(); | ||
default: | ||
throw new Error(); | ||
} | ||
} | ||
|
||
export const lsHandlerFactory = LSHandlerFactory.define( | ||
({ transientParams }) => { | ||
const appName = faker.word.noun(); | ||
const domain = faker.internet.domainName(); | ||
const bundleId = domain.split(',').reverse().join('.') + '.' + appName; | ||
|
||
let role = ''; | ||
const lsHandler = { | ||
LSHandlerPreferredVersions: {}, | ||
}; | ||
|
||
if (transientParams.documentType) { | ||
role = faker.helpers.arrayElement(roles); | ||
const uti = faker.helpers.arrayElement(utis); | ||
|
||
// @ts-expect-error 'ignoring implicit any error' | ||
lsHandler['LSHandlerContentType'] = uti; | ||
} else if (transientParams.urlScheme) { | ||
role = 'All'; | ||
const urlScheme = faker.helpers.arrayElement(urlSchemes); | ||
|
||
// @ts-expect-error 'ignoring implicit any error' | ||
lsHandler['LSHandlerURLScheme'] = urlScheme; | ||
} else { | ||
}); | ||
|
||
class LSHandlerSchemaFactory extends Factory<LSHandlerSchema> {} | ||
|
||
export const lsHandlerSchemaFactory = LSHandlerSchemaFactory.define(() => { | ||
const lsHandlerType = faker.helpers.arrayElement([ | ||
'DocumentType', | ||
'URLScheme', | ||
]); | ||
|
||
switch (lsHandlerType) { | ||
case 'DocumentType': | ||
return documentTypeSchemaFactory.build(); | ||
case 'URLScheme': | ||
return urlSchemeSchemaFactory.build(); | ||
default: | ||
throw new Error(); | ||
} | ||
|
||
// @ts-expect-error 'ignoring implicit any error' | ||
lsHandler[`LSHandlerRole${role}`] = bundleId; | ||
|
||
// @ts-expect-error 'ignoring implicit any error' | ||
lsHandler.LSHandlerPreferredVersions[`LSHandlerRole${role}`] = '-'; | ||
|
||
return lsHandler as LSHandler; | ||
}, | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import urlSchemes from '@/data/urlSchemes.json'; | ||
import { URLScheme } from '@/lib/macos/launchServices/interfaces'; | ||
import { URLSchemeSchema } from '@/lib/macos/launchServices/schemas'; | ||
import { faker } from '@faker-js/faker'; | ||
import { Factory } from 'fishery'; | ||
|
||
class URLSchemeFactory extends Factory<URLScheme> {} | ||
|
||
export const urlSchemeFactory = URLSchemeFactory.define(() => { | ||
const appID = | ||
faker.internet.domainSuffix() + | ||
'.' + | ||
faker.internet.domainWord() + | ||
'.' + | ||
faker.word.noun(); | ||
|
||
return { | ||
scheme: faker.helpers.arrayElement(urlSchemes), | ||
role: 'All' as URLScheme['role'], | ||
appID, | ||
appVersion: '-' as URLScheme['appVersion'], | ||
type: 'URLScheme' as URLScheme['type'], | ||
}; | ||
}); | ||
|
||
class URLSchemeSchemaFactory extends Factory<URLSchemeSchema> {} | ||
|
||
export const urlSchemeSchemaFactory = URLSchemeSchemaFactory.define(() => { | ||
const urlScheme = urlSchemeFactory.build(); | ||
const { scheme, appID, appVersion } = urlScheme; | ||
|
||
return { | ||
LSHandlerURLScheme: scheme, | ||
LSHandlerRoleAll: appID, | ||
LSHandlerPreferredVersions: { | ||
LSHandlerRoleAll: appVersion, | ||
}, | ||
}; | ||
}); |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { fs } from './fs'; | ||
export { launchServices } from './launchServices'; | ||
export { fs } from './fileSystem'; | ||
export { launchServices } from './launchServices/api'; |
2 changes: 1 addition & 1 deletion
2
src/lib/macos/launchServices.ts → src/lib/macos/launchServices/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export interface DocumentType { | ||
uti: string; | ||
role: 'Viewer' | 'Shell' | 'QLGenerator' | 'None' | 'All'; | ||
appID: string; | ||
appVersion: string; | ||
type: 'DocumentType'; | ||
} | ||
|
||
export interface URLScheme { | ||
scheme: string; | ||
role: 'All'; | ||
appID: string; | ||
appVersion: '-'; | ||
type: 'URLScheme'; | ||
} | ||
|
||
export type LSHandler = DocumentType | URLScheme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.