create-ts-vite-project 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { JSDOM } from 'jsdom';
3
+ import { setupCounter } from './counter';
4
+
5
+ describe('counter increments when clicked', () => {
6
+ const dom = new JSDOM(`<!DOCTYPE html><html><body>
7
+ <button id="counter" type="button"></button>
8
+ </body></html>`);
9
+ const document = dom.window.document;
10
+
11
+ const counter = document.querySelector<HTMLButtonElement>('#counter')!;
12
+ setupCounter(counter);
13
+
14
+ it('initial state', () => {
15
+ expect(counter.textContent).toBe('count is 0');
16
+ });
17
+
18
+ it('first click', () => {
19
+ counter.click();
20
+ expect(counter.textContent).toBe('count is 1');
21
+ });
22
+
23
+ it('double click', () => {
24
+ counter.click();
25
+ counter.click();
26
+ expect(counter.textContent).toBe('count is 3');
27
+ });
28
+ });
29
+
30
+ describe('Arithmetic test', () => {
31
+ it('1 + 1 equals 2', () => {
32
+ expect(1 + 1).toBe(2);
33
+ });
34
+
35
+ it('2 * 2 equals 4', () => {
36
+ expect(2 * 2).toBe(4);
37
+ });
38
+ });
@@ -0,0 +1,9 @@
1
+ export function setupCounter(element: HTMLButtonElement): void {
2
+ let counter = 0;
3
+ const setCounter = (count: number): void => {
4
+ counter = count;
5
+ element.innerHTML = `count is ${counter}`;
6
+ };
7
+ element.addEventListener('click', () => setCounter(counter + 1));
8
+ setCounter(0);
9
+ }
@@ -0,0 +1,36 @@
1
+ export function createFile(
2
+ filename: string,
3
+ content: string,
4
+ options: {
5
+ mimeType?: string;
6
+ onSuccess?: () => void;
7
+ onError?: (error: Error) => void;
8
+ } = {},
9
+ ): void {
10
+ const { mimeType = 'text/plain', onSuccess, onError } = options;
11
+
12
+ try {
13
+ const blob = new Blob([content], { type: mimeType });
14
+ const url = URL.createObjectURL(blob);
15
+
16
+ const link = document.createElement('a');
17
+ link.href = url;
18
+ link.download = filename;
19
+ link.style.display = 'none';
20
+
21
+ link.addEventListener('click', () => {
22
+ // Освобождаем память после клика
23
+ setTimeout(() => {
24
+ URL.revokeObjectURL(url);
25
+ onSuccess?.();
26
+ }, 100);
27
+ });
28
+
29
+ document.body.appendChild(link);
30
+ link.click();
31
+ document.body.removeChild(link);
32
+ } catch (error) {
33
+ onError?.(error as Error);
34
+ console.error('Ошибка при создании файла:', error);
35
+ }
36
+ }
@@ -0,0 +1,44 @@
1
+ import './assets/style.css';
2
+ import { setupCounter } from './counter';
3
+ // import { createFile } from './create';
4
+ // import { readFile } from './read';
5
+ import typescriptLogo from '/typescript.svg';
6
+ import viteLogo from '/vite.svg';
7
+
8
+ document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
9
+ <div>
10
+ <a href="https://vite.dev" target="_blank">
11
+ <img src="${viteLogo}" class="logo" alt="Vite logo" />
12
+ </a>
13
+ <a href="https://www.typescriptlang.org/" target="_blank">
14
+ <img src="${typescriptLogo}" class="logo vanilla" alt="TypeScript logo" />
15
+ </a>
16
+ <h1>Vite + TypeScript</h1>
17
+ <div class="card">
18
+ <button id="counter" type="button"></button>
19
+ </div>
20
+ <p class="read-the-docs">
21
+ Click on the Vite and TypeScript logos to learn more
22
+ </p>
23
+ <div class="card" id="license"></div>
24
+ </div>
25
+ `;
26
+
27
+ setupCounter(document.querySelector<HTMLButtonElement>('#counter')!);
28
+
29
+ /*
30
+ const licenseContent = await readFile('license.txt');
31
+ const license = document.querySelector<HTMLButtonElement>('#license');
32
+
33
+ if (license && licenseContent) {
34
+ license.innerHTML = licenseContent;
35
+ }
36
+
37
+ const licenseText = `MIT License
38
+
39
+ Copyright (c) 2024 My Electron App
40
+
41
+ Permission is hereby granted, free of charge...`;
42
+
43
+ createFile(`${Date.now()}.txt`, licenseText);
44
+ */
@@ -0,0 +1,15 @@
1
+ export async function readFile(filename: string): Promise<string | undefined> {
2
+ try {
3
+ const response = await fetch(filename);
4
+
5
+ if (!response.ok) {
6
+ throw new Error(`HTTP error! status: ${response.status}`);
7
+ }
8
+
9
+ const content = await response.text();
10
+ return content;
11
+ } catch (error) {
12
+ console.error('Ошибка при чтении файла:', error);
13
+ throw new Error('Не удалось загрузить файл лицензии');
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,40 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": ["ES2022", "DOM", "Decorators"],
4
+ "types": ["node", "vitest/globals"],
5
+
6
+ "target": "ES2022",
7
+ "module": "ESNext",
8
+ "moduleResolution": "bundler",
9
+
10
+ "outDir": "./dist",
11
+ "rootDir": "./",
12
+
13
+ "strict": true,
14
+ "declaration": true,
15
+ "esModuleInterop": true,
16
+ "skipLibCheck": true,
17
+ "forceConsistentCasingInFileNames": true,
18
+ "exactOptionalPropertyTypes": false,
19
+ "noUncheckedIndexedAccess": true,
20
+ "noImplicitReturns": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+ "removeComments": true,
23
+ "strictNullChecks": true,
24
+ "isolatedModules": true,
25
+ "noEmitOnError": true
26
+ },
27
+ "include": [
28
+ "src/**/*",
29
+ "electron/**/*"
30
+ ],
31
+ "exclude": [
32
+ "build",
33
+ "dist",
34
+ "out",
35
+ "node_modules",
36
+ "**/*.case.ts",
37
+ "**/*.test.ts",
38
+ "**/*.spec.ts"
39
+ ]
40
+ }
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ export default defineConfig({
4
+ base: './',
5
+ build: {},
6
+ server: {
7
+ port: 8080
8
+ }
9
+ });
@@ -0,0 +1,21 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ export default defineConfig({
4
+ base: './',
5
+ logLevel: 'warning',
6
+ build: {
7
+ minify: 'terser',
8
+ terserOptions: {
9
+ compress: {
10
+ passes: 2
11
+ },
12
+ mangle: true,
13
+ format: {
14
+ comments: false
15
+ }
16
+ }
17
+ },
18
+ server: {
19
+ port: 8080
20
+ },
21
+ });
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'jsdom',
7
+ // setupFiles: './src/setupTests.js',
8
+ coverage: {
9
+ provider: 'v8',
10
+ reporter: ['text-summary', 'html'],
11
+ },
12
+ },
13
+ });