diff --git a/cli.ts b/cli.ts index 8f38341..e20f774 100644 --- a/cli.ts +++ b/cli.ts @@ -4,7 +4,7 @@ import { Colors } from "./deps.ts"; import { buildAddon } from "./cli/main.ts"; import type { AddonType } from "./lib/common.ts"; -const VERSION = '1.1.13' +const VERSION = '1.1.14' type LostCommand = 'none' | 'help' | 'version' | 'build' | 'create' | 'serve'; diff --git a/cli/get-addon-files.ts b/cli/get-addon-files.ts index c4c2938..c12ce3c 100644 --- a/cli/get-addon-files.ts +++ b/cli/get-addon-files.ts @@ -1,9 +1,10 @@ import type { LostConfig, FileDependencyType } from "../lib/common.ts"; -import { LOGGER } from "./misc.ts"; +import { getMIMEFileType, LOGGER } from "./misc.ts"; import { ADDON_FILES_FOLDER_PATH } from "./paths.ts"; export interface AddonFile { filename: string; + fileType?: string; path: string; dependencyType: FileDependencyType; } @@ -25,10 +26,12 @@ export async function getAddonFiles(config: LostConfig<'plugin' | 'behavior'>) { } else { LOGGER.Info(`Founded file: ${entry.name}`, `Loading with default type: ${(entry.name.endsWith('.css')) ? 'external-css' : 'copy-to-output'}`); } + const dependencyType = (fileInConfig) ? fileInConfig.Type : (entry.name.endsWith('.css')) ? 'external-css' : 'copy-to-output'; files.push({ filename: entry.name, + fileType: (dependencyType === 'copy-to-output') ? getMIMEFileType(entry.name) : undefined, path: `${path}/${entry.name}`, - dependencyType: (fileInConfig) ? fileInConfig.Type : (entry.name.endsWith('.css')) ? 'external-css' : 'copy-to-output' + dependencyType: dependencyType }) } } diff --git a/cli/get-addon-scripts.ts b/cli/get-addon-scripts.ts index 76278db..2def12c 100644 --- a/cli/get-addon-scripts.ts +++ b/cli/get-addon-scripts.ts @@ -4,6 +4,7 @@ import { ADDON_SCRIPTS_FOLDER_PATH } from "./paths.ts"; export interface AddonScript { filename: string; + scriptType?: 'module'; path: string; dependencyType: ScriptDependencyType; } @@ -27,6 +28,7 @@ export async function getAddonScripts(config: LostConfig<'plugin' | 'behavior'>) } scripts.push({ filename: entry.name, + scriptType: (scriptInConfig && scriptInConfig.Type === 'external-dom-script' && scriptInConfig.ScriptType) ? scriptInConfig.ScriptType : undefined, path: `${path}/${entry.name}`, dependencyType: (scriptInConfig) ? scriptInConfig.Type : 'external-dom-script' }) diff --git a/cli/misc.ts b/cli/misc.ts index 50be066..876dc22 100644 --- a/cli/misc.ts +++ b/cli/misc.ts @@ -1,4 +1,5 @@ export { LOGGER } from "./misc/logger.ts"; export { ErrorMessage, WarningMessage } from "./misc/errors.ts"; export { getModule } from "./misc/get-module.ts"; -export { findDuplicatesInArray } from "./misc/find-duplicates.ts"; \ No newline at end of file +export { findDuplicatesInArray } from "./misc/find-duplicates.ts"; +export { getMIMEFileType } from "./misc/get-mime-file-type.ts"; \ No newline at end of file diff --git a/cli/misc/get-mime-file-type.ts b/cli/misc/get-mime-file-type.ts new file mode 100644 index 0000000..19ce01d --- /dev/null +++ b/cli/misc/get-mime-file-type.ts @@ -0,0 +1,138 @@ +export type FileMIMEType = + | 'application/json' + | 'application/javascript' + | 'application/pdf' + | 'application/xml' + | 'application/zip' + | 'application/x-www-form-urlencoded' + | 'application/vnd.ms-excel' + | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' + | 'application/vnd.ms-powerpoint' + | 'application/vnd.openxmlformats-officedocument.presentationml.presentation' + | 'application/msword' + | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' + | 'audio/mpeg' + | 'audio/wav' + | 'audio/ogg' + | 'audio/webm' + | 'image/jpeg' + | 'image/png' + | 'image/gif' + | 'image/bmp' + | 'image/webp' + | 'image/svg+xml' + | 'text/plain' + | 'text/html' + | 'text/css' + | 'text/javascript' + | 'text/csv' + | 'text/xml' + | 'video/mp4' + | 'video/mpeg' + | 'video/ogg' + | 'video/webm' + | 'video/quicktime'; + +export function getMIMEFileType(filename: string): FileMIMEType | undefined { + if (filename.endsWith('.json')) { + return 'application/json'; + } + if (filename.endsWith('.js')) { + return 'application/javascript'; + } + if (filename.endsWith('.pdf')) { + return 'application/pdf'; + } + if (filename.endsWith('.xml')) { + return 'application/xml'; + } + if (filename.endsWith('.zip')) { + return 'application/zip'; + } + if (filename.endsWith('.urlencoded')) { + return 'application/x-www-form-urlencoded'; + } + if (filename.endsWith('.xls')) { + return 'application/vnd.ms-excel'; + } + if (filename.endsWith('.xlsx')) { + return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + } + if (filename.endsWith('.ppt')) { + return 'application/vnd.ms-powerpoint'; + } + if (filename.endsWith('.pptx')) { + return 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; + } + if (filename.endsWith('.doc')) { + return 'application/msword'; + } + if (filename.endsWith('.docx')) { + return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + } + if (filename.endsWith('.mp3')) { + return 'audio/mpeg'; + } + if (filename.endsWith('.wav')) { + return 'audio/wav'; + } + if (filename.endsWith('.ogg')) { + return 'audio/ogg'; + } + if (filename.endsWith('.webm')) { + return 'audio/webm'; + } + if (filename.endsWith('.jpg') || filename.endsWith('.jpeg')) { + return 'image/jpeg'; + } + if (filename.endsWith('.png')) { + return 'image/png'; + } + if (filename.endsWith('.gif')) { + return 'image/gif'; + } + if (filename.endsWith('.bmp')) { + return 'image/bmp'; + } + if (filename.endsWith('.webp')) { + return 'image/webp'; + } + if (filename.endsWith('.svg')) { + return 'image/svg+xml'; + } + if (filename.endsWith('.txt')) { + return 'text/plain'; + } + if (filename.endsWith('.html') || filename.endsWith('.htm')) { + return 'text/html'; + } + if (filename.endsWith('.css')) { + return 'text/css'; + } + if (filename.endsWith('.mjs')) { + return 'text/javascript'; + } + if (filename.endsWith('.csv')) { + return 'text/csv'; + } + if (filename.endsWith('.xml')) { + return 'text/xml'; + } + if (filename.endsWith('.mp4')) { + return 'video/mp4'; + } + if (filename.endsWith('.mpeg')) { + return 'video/mpeg'; + } + if (filename.endsWith('.ogv')) { + return 'video/ogg'; + } + if (filename.endsWith('.webm')) { + return 'video/webm'; + } + if (filename.endsWith('.mov')) { + return 'video/quicktime'; + } + // Если расширение не найдено, возвращаем undefined + return undefined; +} diff --git a/deno.json b/deno.json index a3c8348..7ef88e1 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@lost-c3/lib", - "version": "1.1.13", + "version": "1.1.14", "exports": { ".": "./mod.ts", "./cli": "./cli.ts"