mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 13:57:10 -04:00
Merge 729a10c68e
into b59942ad9f
This commit is contained in:
commit
e90dd641c0
9 changed files with 306 additions and 11 deletions
|
@ -2,6 +2,9 @@ import { createApp } from 'vue';
|
|||
import { createPinia } from 'pinia';
|
||||
import { createHead } from '@vueuse/head';
|
||||
|
||||
import { install as VueMonacoEditorPlugin, loader } from '@guolao/vue-monaco-editor';
|
||||
import * as monaco from 'monaco-editor';
|
||||
|
||||
import { registerSW } from 'virtual:pwa-register';
|
||||
import { plausible } from './plugins/plausible.plugin';
|
||||
|
||||
|
@ -13,10 +16,14 @@ import App from './App.vue';
|
|||
import router from './router';
|
||||
import { i18nPlugin } from './plugins/i18n.plugin';
|
||||
|
||||
// loaded monaco-editor from `node_modules`
|
||||
loader.config({ monaco });
|
||||
|
||||
registerSW();
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
app.use(VueMonacoEditorPlugin);
|
||||
app.use(createPinia());
|
||||
app.use(createHead());
|
||||
app.use(i18nPlugin);
|
||||
|
|
19
src/tools/docker-compose-validator/composeverter.d.ts
vendored
Normal file
19
src/tools/docker-compose-validator/composeverter.d.ts
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
declare module 'composeverter' {
|
||||
interface Configuration {
|
||||
expandVolumes?: boolean;
|
||||
expandPorts?: boolean;
|
||||
indent?: number;
|
||||
}
|
||||
interface DockerComposeValidatioError {
|
||||
line?: number;
|
||||
message: string;
|
||||
helpLink?: string;
|
||||
}
|
||||
export function validateDockerComposeToCommonSpec(content: string): DockerComposeValidatioError[];
|
||||
export function migrateFromV2xToV3x(content: string, configuration?: Configuration = null): string;
|
||||
export function migrateFromV3xToV2x(content: string, configuration?: Configuration = null): string;
|
||||
export function migrateFromV1ToV2x(content: string, configuration?: Configuration = null): string;
|
||||
export function migrateToCommonSpec(content: string, configuration?: Configuration = null): string;
|
||||
export function migrateFromV2xToV3x(content: string, configuration?: Configuration = null): string;
|
||||
export function getDockerComposeSchemaWithoutFormats(): object;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<script setup lang="ts">
|
||||
import {
|
||||
validateDockerComposeToCommonSpec,
|
||||
} from 'composeverter';
|
||||
|
||||
const dockerCompose = ref(
|
||||
`version: '3.3'
|
||||
services:
|
||||
nginx:
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- '/var/run/docker.sock:/tmp/docker.sock:ro'
|
||||
restart: always
|
||||
logging:
|
||||
options:
|
||||
max-size: 1g
|
||||
image: nginx`,
|
||||
);
|
||||
|
||||
const conversionResult = computed(() => {
|
||||
try {
|
||||
return validateDockerComposeToCommonSpec(dockerCompose.value);
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString().split('\n').map((err: string) => ({ line: -1, message: err, helpLink: '' }));
|
||||
}
|
||||
});
|
||||
|
||||
const errors = computed(() => conversionResult.value);
|
||||
|
||||
const MONACO_EDITOR_OPTIONS = {
|
||||
automaticLayout: true,
|
||||
formatOnType: true,
|
||||
formatOnPaste: true,
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-label label="Paste your Docker Compose file content:">
|
||||
<div relative w-full>
|
||||
<c-monaco-editor
|
||||
v-model:value="dockerCompose"
|
||||
theme="vs-dark"
|
||||
language="yaml"
|
||||
height="250px"
|
||||
:options="MONACO_EDITOR_OPTIONS"
|
||||
/>
|
||||
</div>
|
||||
</c-label>
|
||||
|
||||
<div v-if="errors.length > 0">
|
||||
<n-alert title="The following errors occured" type="error" mt-5>
|
||||
<ul>
|
||||
<li v-for="(message, index) of errors" :key="index">
|
||||
{{ message.message }} (<n-a v-if="message.helpLink" target="_blank" rel="noreferer noopener">
|
||||
See Docker Compose help
|
||||
</n-a>)
|
||||
</li>
|
||||
</ul>
|
||||
</n-alert>
|
||||
</div>
|
||||
<div v-else>
|
||||
<n-alert type="success" mt-5>
|
||||
Validation successful!
|
||||
</n-alert>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
12
src/tools/docker-compose-validator/index.ts
Normal file
12
src/tools/docker-compose-validator/index.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { BrandDocker } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Docker Compose Validator',
|
||||
path: '/docker-compose-validator',
|
||||
description: 'Validate Docker Compose files against CommonSpec schema',
|
||||
keywords: ['docker', 'compose', 'validator', 'commonspec'],
|
||||
component: () => import('./docker-compose-validator.vue'),
|
||||
icon: BrandDocker,
|
||||
createdAt: new Date('2024-01-25'),
|
||||
});
|
|
@ -6,6 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
|||
|
||||
import { tool as textToUnicode } from './text-to-unicode';
|
||||
import { tool as safelinkDecoder } from './safelink-decoder';
|
||||
import { tool as dockerComposeValidator } from './docker-compose-validator';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
|
@ -146,6 +147,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||
sqlPrettify,
|
||||
chmodCalculator,
|
||||
dockerRunToDockerComposeConverter,
|
||||
dockerComposeValidator,
|
||||
xmlFormatter,
|
||||
yamlViewer,
|
||||
],
|
||||
|
|
124
src/ui/c-monaco-editor/c-monaco-editor.vue
Normal file
124
src/ui/c-monaco-editor/c-monaco-editor.vue
Normal file
|
@ -0,0 +1,124 @@
|
|||
<script setup lang="ts">
|
||||
import * as monacoEditor from 'monaco-editor';
|
||||
import type { MonacoEditor } from '@guolao/vue-monaco-editor';
|
||||
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
||||
import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
|
||||
import CssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
|
||||
import HtmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
|
||||
import TsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
|
||||
const props = withDefaults(defineProps<EditorProps>(), {
|
||||
theme: 'vs',
|
||||
options: () => ({}),
|
||||
overrideServices: () => ({}),
|
||||
saveViewState: true,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
});
|
||||
|
||||
const emits = defineEmits<{
|
||||
(e: 'update:value', value: string | undefined): void
|
||||
(e: 'beforeMount', monaco: MonacoEditor): void
|
||||
(e: 'mount', editor: monacoEditor.editor.IStandaloneCodeEditor, monaco: MonacoEditor): void
|
||||
(e: 'change', value: string | undefined, event: monacoEditor.editor.IModelContentChangedEvent): void
|
||||
(e: 'validate', markers: monacoEditor.editor.IMarker[]): void
|
||||
}>();
|
||||
|
||||
interface MonacoEnvironment {
|
||||
getWorker(_: any, label: string): Worker
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
declare module globalThis {
|
||||
let MonacoEnvironment: MonacoEnvironment;
|
||||
}
|
||||
|
||||
const value = useVModel(props, 'value', emits);
|
||||
|
||||
globalThis.MonacoEnvironment = {
|
||||
getWorker(_: any, label: string) {
|
||||
if (label === 'json') {
|
||||
return new JsonWorker();
|
||||
}
|
||||
if (label === 'css' || label === 'scss' || label === 'less') {
|
||||
return new CssWorker();
|
||||
}
|
||||
if (label === 'html' || label === 'handlebars' || label === 'razor') {
|
||||
return new HtmlWorker();
|
||||
}
|
||||
if (label === 'typescript' || label === 'javascript') {
|
||||
return new TsWorker();
|
||||
}
|
||||
return new EditorWorker();
|
||||
},
|
||||
};
|
||||
|
||||
export interface EditorProps {
|
||||
defaultValue?: string
|
||||
defaultPath?: string
|
||||
defaultLanguage?: string
|
||||
value?: string
|
||||
language?: string
|
||||
path?: string
|
||||
|
||||
/* === */
|
||||
|
||||
theme: 'vs' | string
|
||||
line?: number
|
||||
options?: monacoEditor.editor.IStandaloneEditorConstructionOptions
|
||||
overrideServices?: monacoEditor.editor.IEditorOverrideServices
|
||||
saveViewState?: boolean
|
||||
|
||||
/* === */
|
||||
|
||||
width?: number | string
|
||||
height?: number | string
|
||||
className?: string
|
||||
}
|
||||
|
||||
monacoEditor.editor.defineTheme('it-tools-dark', {
|
||||
base: 'vs-dark',
|
||||
inherit: true,
|
||||
rules: [],
|
||||
colors: {
|
||||
'editor.background': '#00000000',
|
||||
},
|
||||
});
|
||||
|
||||
monacoEditor.editor.defineTheme('it-tools-light', {
|
||||
base: 'vs',
|
||||
inherit: true,
|
||||
rules: [],
|
||||
colors: {
|
||||
'editor.background': '#00000000',
|
||||
},
|
||||
});
|
||||
|
||||
const styleStore = useStyleStore();
|
||||
|
||||
watch(
|
||||
() => styleStore.isDarkTheme,
|
||||
isDarkTheme => monacoEditor.editor.setTheme(isDarkTheme ? 'it-tools-dark' : 'it-tools-light'),
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const attrs = useAttrs();
|
||||
const inheritedAttrs = { ...attrs, ...props };
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
inheritAttrs: false,
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<vue-monaco-editor
|
||||
v-bind="inheritedAttrs"
|
||||
v-model:value="value"
|
||||
@before-mount="(monaco: MonacoEditor) => emits('beforeMount', monaco)"
|
||||
@mount="(editor: monacoEditor.editor.IStandaloneCodeEditor, monaco: MonacoEditor) => emits('mount', editor, monaco)"
|
||||
@change="(value: string | undefined, event: monacoEditor.editor.IModelContentChangedEvent) => emits('change', value, event)"
|
||||
@validate="(markers: monacoEditor.editor.IMarker[]) => emits('validate', markers)"
|
||||
/>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue