@stripchatdev/create-stripchat-extension 0.1.45 → 0.1.47
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.
- package/dist/bin/cli/actions/updateAction.d.ts +6 -0
- package/dist/bin/cli/actions/updateAction.js +33 -0
- package/dist/bin/cli/helpers/printCliError.d.ts +1 -0
- package/dist/bin/cli/helpers/printCliError.js +21 -0
- package/dist/bin/cli/index.js +70 -0
- package/dist/bin/create.d.ts +2 -0
- package/dist/bin/create.js +238 -0
- package/dist/package.json +5 -2
- package/dist/src/constants.d.ts +14 -9
- package/dist/src/constants.js +53 -8
- package/dist/src/dependencies/constants.d.ts +2 -0
- package/dist/src/dependencies/constants.js +11 -0
- package/dist/src/dependencies/resolveDependencies.d.ts +6 -0
- package/dist/src/dependencies/resolveDependencies.js +43 -0
- package/dist/src/dependencies/resolveDependencies.test.js +74 -0
- package/dist/src/helpers/error.d.ts +3 -0
- package/dist/src/helpers/error.js +9 -0
- package/dist/src/helpers/error.test.js +15 -0
- package/dist/src/helpers/getIsDirectoryExists.d.ts +7 -0
- package/dist/src/helpers/getIsDirectoryExists.js +23 -0
- package/dist/src/helpers/getIsDirectoryExists.test.js +34 -0
- package/dist/src/helpers/getIsJsxFramework.d.ts +2 -0
- package/dist/src/helpers/getIsJsxFramework.js +2 -0
- package/dist/src/helpers/getIsJsxFramework.test.js +10 -0
- package/dist/src/helpers/getIsTypescript.d.ts +2 -0
- package/dist/src/helpers/getIsTypescript.js +1 -0
- package/dist/src/helpers/getIsTypescript.test.js +10 -0
- package/dist/src/helpers/isSubPath.d.ts +1 -0
- package/dist/src/helpers/isSubPath.js +5 -0
- package/dist/src/helpers/normalizePath.d.ts +2 -0
- package/dist/src/helpers/normalizePath.js +4 -0
- package/dist/src/helpers/normalizePath.test.js +19 -0
- package/dist/src/migrator/executor.d.ts +9 -0
- package/dist/src/migrator/executor.js +112 -0
- package/dist/src/migrator/migration.d.ts +3 -0
- package/dist/src/migrator/migration.js +18 -0
- package/dist/src/migrator/migration.test.js +74 -0
- package/dist/src/migrator/migrations/migrations.test.js +97 -0
- package/dist/src/migrator/migrations/v2/AGENTS_md/001_recreate-with-generated-part.d.ts +2 -0
- package/dist/src/migrator/migrations/v2/AGENTS_md/001_recreate-with-generated-part.js +14 -0
- package/dist/src/migrator/migrations/v2/_project-config_json/001_create.d.ts +2 -0
- package/dist/src/migrator/migrations/v2/_project-config_json/001_create.js +14 -0
- package/dist/src/migrator/migrations/v2/vite_config_ts/001_turn_off_minify_and_assets_inline.d.ts +2 -0
- package/dist/src/migrator/migrations/v2/vite_config_ts/001_turn_off_minify_and_assets_inline.js +118 -0
- package/dist/src/migrator/planner.d.ts +5 -0
- package/dist/src/migrator/planner.js +65 -0
- package/dist/src/migrator/planner.test.js +40 -0
- package/dist/src/migrator/types.d.ts +29 -0
- package/dist/src/migrator/updates/updates.test.js +102 -0
- package/dist/src/migrator/updates/v2/AGENTS_md/001_update-generated-part.d.ts +2 -0
- package/dist/src/migrator/updates/v2/AGENTS_md/001_update-generated-part.js +38 -0
- package/dist/src/migrator/updates/v2/package_json/001_update-versions.d.ts +2 -0
- package/dist/src/migrator/updates/v2/package_json/001_update-versions.js +77 -0
- package/dist/src/migrator/updates/v2/package_json/002_add-cli-commands.d.ts +2 -0
- package/dist/src/migrator/updates/v2/package_json/002_add-cli-commands.js +61 -0
- package/dist/src/migrator/validators/getIsValidMigration.d.ts +2 -0
- package/dist/src/migrator/validators/getIsValidMigration.js +3 -0
- package/dist/src/migrator/validators/getIsValidMigration.test.js +13 -0
- package/dist/src/projectConfig/buildProjectConfig.d.ts +15 -0
- package/dist/src/projectConfig/buildProjectConfig.js +27 -0
- package/dist/src/projectConfig/detectPackageManagerRuntime.d.ts +2 -0
- package/dist/src/{helpers/detectPackageManager.js → projectConfig/detectPackageManagerRuntime.js} +1 -1
- package/dist/src/{helpers/detectPackageManager.test.js → projectConfig/detectPackageManagerRuntime.test.js} +10 -10
- package/dist/src/projectConfig/recoverProjectConfig.d.ts +1 -0
- package/dist/src/projectConfig/recoverProjectConfig.js +34 -0
- package/dist/src/projectConfig/recovery/detectPackageManagerFromFiles.d.ts +2 -0
- package/dist/src/projectConfig/recovery/detectPackageManagerFromFiles.js +16 -0
- package/dist/src/projectConfig/recovery/detectPackageManagerFromFiles.test.d.ts +1 -0
- package/dist/src/projectConfig/recovery/detectPackageManagerFromFiles.test.js +37 -0
- package/dist/src/projectConfig/recovery/parseAgentsMd.d.ts +10 -0
- package/dist/src/projectConfig/recovery/parseAgentsMd.js +52 -0
- package/dist/src/projectConfig/recovery/parseAgentsMd.test.d.ts +1 -0
- package/dist/src/projectConfig/recovery/parseAgentsMd.test.js +67 -0
- package/dist/src/projectConfig/recovery/resolveProjectNameFromDir.d.ts +1 -0
- package/dist/src/projectConfig/recovery/resolveProjectNameFromDir.js +11 -0
- package/dist/src/projectConfig/recovery/resolveProjectNameFromDir.test.d.ts +1 -0
- package/dist/src/projectConfig/recovery/resolveProjectNameFromDir.test.js +21 -0
- package/dist/src/projectConfig/resolveExistsProjectConfig.d.ts +2 -0
- package/dist/src/projectConfig/resolveExistsProjectConfig.js +34 -0
- package/dist/src/projectConfig/updateProjectConfig.d.ts +2 -0
- package/dist/src/projectConfig/updateProjectConfig.js +20 -0
- package/dist/src/projectConfig/validators/getIsValidProjectConfig.d.ts +2 -0
- package/dist/src/projectConfig/validators/getIsValidProjectConfig.js +6 -0
- package/dist/src/projectConfig/validators/getIsValidProjectConfig.test.d.ts +1 -0
- package/dist/src/projectConfig/validators/getIsValidProjectConfig.test.js +33 -0
- package/dist/src/projectConfig/validators/validateProjectConfig.d.ts +2 -0
- package/dist/src/projectConfig/validators/validateProjectConfig.js +30 -0
- package/dist/src/projectConfig/validators/validateProjectConfig.test.d.ts +1 -0
- package/dist/src/projectConfig/validators/validateProjectConfig.test.js +215 -0
- package/dist/src/templater/executor.d.ts +2 -0
- package/dist/src/templater/executor.js +22 -0
- package/dist/src/templater/executor.test.d.ts +1 -0
- package/dist/src/{executor.test.js → templater/executor.test.js} +25 -11
- package/dist/src/templater/helpers/getIsTypescriptOnlyFile.d.ts +1 -0
- package/dist/src/templater/helpers/getIsTypescriptOnlyFile.js +10 -0
- package/dist/src/templater/helpers/getIsTypescriptOnlyFile.test.d.ts +1 -0
- package/dist/src/templater/helpers/getIsTypescriptOnlyFile.test.js +25 -0
- package/dist/src/templater/helpers/resolveTemplateExtension.d.ts +1 -0
- package/dist/src/templater/helpers/resolveTemplateExtension.js +16 -0
- package/dist/src/templater/helpers/resolveTemplateExtension.test.d.ts +1 -0
- package/dist/src/{mappers → templater/mappers}/mapProjectConfigToTemplateModel.d.ts +1 -1
- package/dist/src/{mappers → templater/mappers}/mapProjectConfigToTemplateModel.js +6 -8
- package/dist/src/templater/mappers/mapProjectConfigToTemplateModel.test.d.ts +1 -0
- package/dist/src/{mappers → templater/mappers}/mapProjectConfigToTemplateModel.test.js +29 -23
- package/dist/src/templater/planner.d.ts +2 -0
- package/dist/src/templater/planner.js +104 -0
- package/dist/src/templater/planner.test.d.ts +1 -0
- package/dist/src/templater/planner.test.js +64 -0
- package/dist/src/templates/constants.d.ts +6 -0
- package/dist/src/templates/constants.js +11 -0
- package/dist/src/templates/helpers/resolveTemplatesDir.d.ts +1 -0
- package/dist/src/templates/helpers/resolveTemplatesDir.js +16 -0
- package/dist/src/templates/templates.d.ts +10 -0
- package/dist/src/templates/templates.js +133 -0
- package/dist/src/templates/templates.test.d.ts +1 -0
- package/dist/src/templates/templates.test.js +263 -0
- package/dist/src/templates/types.d.ts +21 -0
- package/dist/src/templates/types.js +1 -0
- package/dist/src/types.d.ts +28 -9
- package/dist/src/validators/getIsValidCategory.d.ts +2 -0
- package/dist/src/validators/getIsValidCategory.js +2 -0
- package/dist/src/validators/getIsValidCategory.test.d.ts +1 -0
- package/dist/src/validators/{isValidCategory.test.js → getIsValidCategory.test.js} +3 -3
- package/dist/src/validators/getIsValidFramework.d.ts +2 -0
- package/dist/src/validators/getIsValidFramework.js +2 -0
- package/dist/src/validators/getIsValidFramework.test.d.ts +1 -0
- package/dist/src/validators/{isValidFramework.test.js → getIsValidFramework.test.js} +3 -3
- package/dist/src/validators/getIsValidLanguage.d.ts +2 -0
- package/dist/src/validators/getIsValidLanguage.js +2 -0
- package/dist/src/validators/getIsValidLanguage.test.d.ts +1 -0
- package/dist/src/validators/{isValidLanguage.test.js → getIsValidLanguage.test.js} +3 -3
- package/dist/src/validators/getIsValidPackageManager.d.ts +2 -0
- package/dist/src/validators/getIsValidPackageManager.js +4 -0
- package/dist/src/validators/getIsValidPackageManager.test.d.ts +1 -0
- package/dist/src/validators/getIsValidPackageManager.test.js +11 -0
- package/dist/src/validators/getIsValidSlot.d.ts +2 -0
- package/dist/src/validators/getIsValidSlot.js +4 -0
- package/dist/src/validators/getIsValidSlot.test.d.ts +1 -0
- package/dist/src/validators/getIsValidSlot.test.js +26 -0
- package/dist/src/validators/validateSlots.js +40 -8
- package/dist/src/validators/validateSlots.test.js +125 -34
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -2
- package/templates/v1/vite.config.ts.ejs +27 -0
- package/templates/v2/.project-config.json.ejs +1 -0
- package/templates/v2/AGENTS.md.ejs +712 -0
- package/templates/v2/README.md.ejs +31 -0
- package/templates/v2/package.json.ejs +26 -0
- package/dist/bin/cli.js +0 -221
- package/dist/src/executor.d.ts +0 -2
- package/dist/src/executor.js +0 -22
- package/dist/src/helpers/detectPackageManager.d.ts +0 -2
- package/dist/src/helpers/isDirectory.d.ts +0 -1
- package/dist/src/helpers/isDirectory.js +0 -9
- package/dist/src/helpers/isDirectory.test.js +0 -22
- package/dist/src/helpers/isTypescriptOnlyFile.d.ts +0 -1
- package/dist/src/helpers/isTypescriptOnlyFile.js +0 -5
- package/dist/src/helpers/isTypescriptOnlyFile.test.js +0 -22
- package/dist/src/helpers/normalizeRelPath.d.ts +0 -1
- package/dist/src/helpers/normalizeRelPath.js +0 -1
- package/dist/src/helpers/normalizeRelPath.test.js +0 -19
- package/dist/src/helpers/resolveTemplateExtension.d.ts +0 -1
- package/dist/src/helpers/resolveTemplateExtension.js +0 -17
- package/dist/src/helpers/resolveTemplatesDir.d.ts +0 -1
- package/dist/src/helpers/resolveTemplatesDir.js +0 -11
- package/dist/src/helpers/resolveTemplatesDir.test.js +0 -21
- package/dist/src/planner.d.ts +0 -2
- package/dist/src/planner.js +0 -126
- package/dist/src/planner.test.js +0 -58
- package/dist/src/validators/index.d.ts +0 -6
- package/dist/src/validators/index.js +0 -6
- package/dist/src/validators/isValidCategory.d.ts +0 -2
- package/dist/src/validators/isValidCategory.js +0 -2
- package/dist/src/validators/isValidFramework.d.ts +0 -2
- package/dist/src/validators/isValidFramework.js +0 -2
- package/dist/src/validators/isValidLanguage.d.ts +0 -2
- package/dist/src/validators/isValidLanguage.js +0 -2
- package/dist/src/validators/validateProjectDir.d.ts +0 -1
- package/dist/src/validators/validateProjectDir.js +0 -6
- package/dist/src/validators/validateProjectDir.test.js +0 -19
- package/dist/bin/{cli.d.ts → cli/index.d.ts} +0 -0
- package/dist/src/{executor.test.d.ts → dependencies/resolveDependencies.test.d.ts} +0 -0
- package/dist/src/helpers/{detectPackageManager.test.d.ts → error.test.d.ts} +0 -0
- package/dist/src/helpers/{isDirectory.test.d.ts → getIsDirectoryExists.test.d.ts} +0 -0
- package/dist/src/helpers/{isTypescriptOnlyFile.test.d.ts → getIsJsxFramework.test.d.ts} +0 -0
- package/dist/src/helpers/{normalizeRelPath.test.d.ts → getIsTypescript.test.d.ts} +0 -0
- package/dist/src/helpers/{resolveTemplateExtension.test.d.ts → normalizePath.test.d.ts} +0 -0
- package/dist/src/{helpers/resolveTemplatesDir.test.d.ts → migrator/migration.test.d.ts} +0 -0
- package/dist/src/{mappers/mapProjectConfigToTemplateModel.test.d.ts → migrator/migrations/migrations.test.d.ts} +0 -0
- package/dist/src/{planner.test.d.ts → migrator/planner.test.d.ts} +0 -0
- package/dist/src/{validators/isValidCategory.test.d.ts → migrator/types.js} +0 -0
- package/dist/src/{validators/isValidFramework.test.d.ts → migrator/updates/updates.test.d.ts} +0 -0
- package/dist/src/{validators/isValidLanguage.test.d.ts → migrator/validators/getIsValidMigration.test.d.ts} +0 -0
- package/dist/src/{validators/validateProjectDir.test.d.ts → projectConfig/detectPackageManagerRuntime.test.d.ts} +0 -0
- package/dist/src/{helpers → templater/helpers}/resolveTemplateExtension.test.js +0 -0
- package/templates/{.gitignore.ejs → v1/.gitignore.ejs} +0 -0
- package/templates/{AGENTS.md.ejs → v1/AGENTS.md.ejs} +0 -0
- package/templates/{CLAUDE.md → v1/CLAUDE.md} +0 -0
- package/templates/{README.md.ejs → v1/README.md.ejs} +0 -0
- package/templates/{package.json.ejs → v1/package.json.ejs} +0 -0
- package/templates/{public → v1/public}/icon.svg +0 -0
- package/templates/{public → v1/public}/manifest.json.ejs +0 -0
- package/templates/{public → v1/public}/resolveSlotPage.js.ejs +0 -0
- package/templates/{src → v1/src}/slots/background/app.ts.ejs +0 -0
- package/templates/{src → v1/src}/slots/background/background.html.ejs +0 -0
- package/templates/{src → v1/src}/slots/background/main.ts.ejs +0 -0
- package/templates/{src/slots/slot/slot.html.ejs → v1/src/slots/slot/__SLOT_KEY__.html.ejs} +0 -0
- package/templates/{src → v1/src}/slots/slot/app.ts.ejs +0 -0
- package/templates/{src → v1/src}/slots/slot/app.tsx.ejs +0 -0
- package/templates/{src → v1/src}/slots/slot/main.css.ejs +0 -0
- package/templates/{src → v1/src}/slots/slot/main.ts.ejs +0 -0
- package/templates/{src → v1/src}/slots/slot/main.tsx.ejs +0 -0
- package/templates/{tsconfig.json.ejs → v1/tsconfig.json.ejs} +0 -0
- package/templates/{vite.config.ts.ejs → v2/vite.config.ts.ejs} +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { AppError } from './error.js';
|
|
3
|
+
describe('AppError', () => {
|
|
4
|
+
it('create error with message, cause, stack and constructor name', () => {
|
|
5
|
+
const appErrorMessage = 'some application error';
|
|
6
|
+
const causeError = new Error('path does not exists');
|
|
7
|
+
const appError = new AppError('some application error', causeError);
|
|
8
|
+
expect(appError).instanceOf(Error);
|
|
9
|
+
expect(appError).instanceOf(AppError);
|
|
10
|
+
expect(appError.message).toBe(appErrorMessage);
|
|
11
|
+
expect(appError.cause).toBe(causeError);
|
|
12
|
+
expect(appError.name).toBe(AppError.name);
|
|
13
|
+
expect(appError.stack).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
export const getIsDirectoryExists = (dirPath) => {
|
|
3
|
+
let stat;
|
|
4
|
+
try {
|
|
5
|
+
stat = statSync(dirPath);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return {
|
|
9
|
+
isExists: false,
|
|
10
|
+
error: `Path does not exists: ${dirPath}`,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
if (!stat.isDirectory()) {
|
|
14
|
+
return {
|
|
15
|
+
isExists: false,
|
|
16
|
+
error: `Path is not a directory: ${dirPath}`,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
isExists: true,
|
|
21
|
+
error: null,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { describe, it, expect, afterAll, beforeAll } from 'vitest';
|
|
5
|
+
import { getIsDirectoryExists } from './getIsDirectoryExists.js';
|
|
6
|
+
describe('getIsDirectoryExists', () => {
|
|
7
|
+
const dir = mkdtempSync(join(tmpdir(), 'sce-getIsDirectoryExists-'));
|
|
8
|
+
const filePath = join(dir, 'test.txt');
|
|
9
|
+
beforeAll(() => {
|
|
10
|
+
writeFileSync(filePath, 'Hello, World!', {
|
|
11
|
+
encoding: 'utf8',
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
afterAll(() => {
|
|
15
|
+
rmSync(dir, { recursive: true, force: true });
|
|
16
|
+
});
|
|
17
|
+
it('exists if checking path is dir', () => {
|
|
18
|
+
expect(getIsDirectoryExists(dir)).toEqual({
|
|
19
|
+
error: null,
|
|
20
|
+
isExists: true,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
it('not exists is checking path is file', () => {
|
|
24
|
+
const { error, isExists } = getIsDirectoryExists(filePath);
|
|
25
|
+
expect(isExists).toBe(false);
|
|
26
|
+
expect(error).toBe(`Path is not a directory: ${filePath}`);
|
|
27
|
+
});
|
|
28
|
+
it('not exists is checking not exists path', () => {
|
|
29
|
+
const notExistsPath = join(dir, '/some/not-exists/path');
|
|
30
|
+
const { error, isExists } = getIsDirectoryExists(notExistsPath);
|
|
31
|
+
expect(isExists).toBe(false);
|
|
32
|
+
expect(error).toBe(`Path does not exists: ${notExistsPath}`);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getIsJsxFramework } from './getIsJsxFramework.js';
|
|
3
|
+
describe('getIsJsxFramework', () => {
|
|
4
|
+
it.each(['preact'])('returns true for jsx framework: %s', (framework) => {
|
|
5
|
+
expect(getIsJsxFramework(framework)).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
it.each(['vanilla'])('returns false for non jsx framework: %s', (framework) => {
|
|
8
|
+
expect(getIsJsxFramework(framework)).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const getIsTypescript = (language) => language === 'ts';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { getIsTypescript } from './getIsTypescript.js';
|
|
3
|
+
describe('getIsTypescript', () => {
|
|
4
|
+
it('return true for typescript language', () => {
|
|
5
|
+
expect(getIsTypescript('ts')).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
it.each(['js'])('return false for non typescript language', (lang) => {
|
|
8
|
+
expect(getIsTypescript(lang)).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isSubPath: (parentPath: string, childPath: string) => boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { toNormalizedRelPath } from './normalizePath.js';
|
|
3
|
+
describe('normalizePath', () => {
|
|
4
|
+
it('replaces backslashes with forward slashes', () => {
|
|
5
|
+
expect(toNormalizedRelPath('src\\slots\\main')).toBe('src/slots/main');
|
|
6
|
+
});
|
|
7
|
+
it('replaces multiple backslashes', () => {
|
|
8
|
+
expect(toNormalizedRelPath('a\\b\\c\\d')).toBe('a/b/c/d');
|
|
9
|
+
});
|
|
10
|
+
it('leaves forward slashes unchanged', () => {
|
|
11
|
+
expect(toNormalizedRelPath('src/slots/main')).toBe('src/slots/main');
|
|
12
|
+
});
|
|
13
|
+
it('handles mixed separators', () => {
|
|
14
|
+
expect(toNormalizedRelPath('src\\slots/main\\file.ts')).toBe('src/slots/main/file.ts');
|
|
15
|
+
});
|
|
16
|
+
it('returns empty string unchanged', () => {
|
|
17
|
+
expect(toNormalizedRelPath('')).toBe('');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TMigrationDiff, TMigrationExecutionPlan } from './types.js';
|
|
2
|
+
export type TExecuteMigrationsOptions = {
|
|
3
|
+
executionPlan: TMigrationExecutionPlan;
|
|
4
|
+
isDryRun: boolean;
|
|
5
|
+
onCommitChange?: (file: string, previewFile: string) => void;
|
|
6
|
+
projectDir: string;
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const executeMigrations: (options: TExecuteMigrationsOptions) => Promise<TMigrationDiff[]>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createPatch } from 'diff';
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, copyFileSync, existsSync, cpSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join, relative } from 'node:path';
|
|
5
|
+
import { executeCommands } from '../templater/executor.js';
|
|
6
|
+
import { mapProjectConfigToTemplateData } from '../templater/mappers/mapProjectConfigToTemplateModel.js';
|
|
7
|
+
import { planProject } from '../templater/planner.js';
|
|
8
|
+
import { executeMigration, } from './migration.js';
|
|
9
|
+
const generateProject = (projectConfig, targetVersion) => {
|
|
10
|
+
const generatedProjectDir = mkdtempSync(join(tmpdir(), 'sce-generated-'));
|
|
11
|
+
const templateData = mapProjectConfigToTemplateData(projectConfig);
|
|
12
|
+
const commands = planProject(generatedProjectDir, targetVersion, templateData);
|
|
13
|
+
executeCommands(commands);
|
|
14
|
+
return generatedProjectDir;
|
|
15
|
+
};
|
|
16
|
+
const createProjectModifiedPreview = (projectDir, managedFiles) => {
|
|
17
|
+
const previewProjectDir = mkdtempSync(join(tmpdir(), 'sce-preview-'));
|
|
18
|
+
const managedFilesMap = {};
|
|
19
|
+
managedFiles.forEach((managedFile) => {
|
|
20
|
+
if (!managedFile.deleted) {
|
|
21
|
+
managedFilesMap[managedFile.relPath] = true;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
for (const managedFile of managedFiles) {
|
|
25
|
+
if (managedFile.deleted) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const srcPath = join(projectDir, managedFile.relPath);
|
|
29
|
+
if (existsSync(srcPath)) {
|
|
30
|
+
cpSync(srcPath, join(previewProjectDir, managedFile.relPath));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return previewProjectDir;
|
|
34
|
+
};
|
|
35
|
+
const getChangeDiff = (projectDir, file, previewFile) => {
|
|
36
|
+
if (!existsSync(previewFile)) {
|
|
37
|
+
if (!existsSync(file)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const targetFileContent = readFileSync(file, 'utf8');
|
|
41
|
+
return createPatch(relative(projectDir, file), targetFileContent, '');
|
|
42
|
+
}
|
|
43
|
+
if (!existsSync(file)) {
|
|
44
|
+
const newFileContent = readFileSync(previewFile, 'utf8');
|
|
45
|
+
return createPatch(relative(projectDir, file), '', newFileContent);
|
|
46
|
+
}
|
|
47
|
+
const fileContent = readFileSync(file, 'utf8');
|
|
48
|
+
const newFileContent = readFileSync(previewFile, 'utf8');
|
|
49
|
+
if (fileContent === newFileContent) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return createPatch(relative(projectDir, file), fileContent, newFileContent);
|
|
53
|
+
};
|
|
54
|
+
const commitChange = (file, previewFile) => {
|
|
55
|
+
const isPreviewFileExists = existsSync(previewFile);
|
|
56
|
+
if (isPreviewFileExists) {
|
|
57
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
58
|
+
copyFileSync(previewFile, file);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
rmSync(file, { force: true });
|
|
62
|
+
};
|
|
63
|
+
export const executeMigrations = async (options) => {
|
|
64
|
+
const { executionPlan, isDryRun, onCommitChange, projectDir, } = options;
|
|
65
|
+
const { migrationPlans, targetProjectConfig, updatedProjectConfig, } = executionPlan;
|
|
66
|
+
const cleanUpTempDirs = [];
|
|
67
|
+
const previewProjectDir = createProjectModifiedPreview(projectDir, targetProjectConfig.managedFiles);
|
|
68
|
+
const generatedProjectDirs = new Map();
|
|
69
|
+
cleanUpTempDirs.push(previewProjectDir);
|
|
70
|
+
try {
|
|
71
|
+
const migrationDiffs = [];
|
|
72
|
+
for (const migrationPlan of migrationPlans) {
|
|
73
|
+
if (!generatedProjectDirs.has(migrationPlan.templateVersion)) {
|
|
74
|
+
const generatedProjectDir = generateProject(updatedProjectConfig, migrationPlan.templateVersion);
|
|
75
|
+
generatedProjectDirs.set(migrationPlan.templateVersion, generatedProjectDir);
|
|
76
|
+
cleanUpTempDirs.push(generatedProjectDir);
|
|
77
|
+
}
|
|
78
|
+
const generatedProjectDir = generatedProjectDirs.get(migrationPlan.templateVersion);
|
|
79
|
+
if (!generatedProjectDir) {
|
|
80
|
+
throw new Error(`Failed to generate project for template version ${migrationPlan.templateVersion}`);
|
|
81
|
+
}
|
|
82
|
+
const ctx = {
|
|
83
|
+
projectDir: previewProjectDir,
|
|
84
|
+
generatedProjectDir,
|
|
85
|
+
targetProjectConfig,
|
|
86
|
+
updatedProjectConfig,
|
|
87
|
+
templateVersion: migrationPlan.templateVersion,
|
|
88
|
+
};
|
|
89
|
+
const changes = await executeMigration(ctx, migrationPlan);
|
|
90
|
+
changes.forEach(({ filePath, relFilePath }) => {
|
|
91
|
+
const originFilePath = join(projectDir, relFilePath);
|
|
92
|
+
const diff = getChangeDiff(projectDir, originFilePath, filePath);
|
|
93
|
+
if (diff) {
|
|
94
|
+
migrationDiffs.push({
|
|
95
|
+
filePath: originFilePath,
|
|
96
|
+
diff,
|
|
97
|
+
});
|
|
98
|
+
if (!isDryRun) {
|
|
99
|
+
commitChange(originFilePath, filePath);
|
|
100
|
+
onCommitChange?.(originFilePath, filePath);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return migrationDiffs;
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
for (const tempDir of cleanUpTempDirs) {
|
|
109
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TMigrationChange, TMigrationContext, TMigrationPlan } from './types';
|
|
2
|
+
export declare const getTemplateMigrationsDir: (type: "migrations" | "updates", version: number, managedFileRelPath: string) => string;
|
|
3
|
+
export declare const executeMigration: (ctx: TMigrationContext, { scriptPath }: TMigrationPlan) => Promise<TMigrationChange[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { basename, dirname, join } from 'node:path';
|
|
2
|
+
import { AppError } from '../helpers/error.js';
|
|
3
|
+
import { getIsValidMigration } from './validators/getIsValidMigration.js';
|
|
4
|
+
const __dirname = import.meta.dirname;
|
|
5
|
+
export const getTemplateMigrationsDir = (type, version, managedFileRelPath) => {
|
|
6
|
+
const base = basename(managedFileRelPath);
|
|
7
|
+
const dir = dirname(managedFileRelPath);
|
|
8
|
+
const migrationBase = base.replaceAll('.', '_');
|
|
9
|
+
return join(__dirname, type, `v${version}`, dir, migrationBase);
|
|
10
|
+
};
|
|
11
|
+
export const executeMigration = async (ctx, { scriptPath }) => {
|
|
12
|
+
const jsPath = scriptPath.replace(/\.(d\.ts|ts)$/, '.js');
|
|
13
|
+
const migration = await import(jsPath);
|
|
14
|
+
if (!getIsValidMigration(migration)) {
|
|
15
|
+
throw new AppError(`Invalid migration script contract: ${jsPath}. Expected named export "up".`);
|
|
16
|
+
}
|
|
17
|
+
return migration.up(ctx);
|
|
18
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { CLI_COMMANDS_MAP, EXT_HELPER_VERSION } from '../constants.js';
|
|
6
|
+
import { buildProjectConfig } from '../projectConfig/buildProjectConfig.js';
|
|
7
|
+
import { MANAGED_TEMPLATES } from '../templates/constants.js';
|
|
8
|
+
import { LAST_TEMPLATE_VERSION, TEMPLATES_DIR } from '../templates/templates.js';
|
|
9
|
+
import { executeMigration, getTemplateMigrationsDir } from './migration.js';
|
|
10
|
+
const testProjectConfig = buildProjectConfig({
|
|
11
|
+
category: 'games-and-fun',
|
|
12
|
+
framework: 'preact',
|
|
13
|
+
lastTemplateVersion: LAST_TEMPLATE_VERSION,
|
|
14
|
+
cliCommands: CLI_COMMANDS_MAP,
|
|
15
|
+
managedTemplates: MANAGED_TEMPLATES,
|
|
16
|
+
templatesDir: TEMPLATES_DIR,
|
|
17
|
+
name: 'test',
|
|
18
|
+
slots: ['EXTENSION_SLOT_MAIN_GAME_FUN', 'EXTENSION_SLOT_BACKGROUND'],
|
|
19
|
+
extHelperVersion: EXT_HELPER_VERSION,
|
|
20
|
+
language: 'ts',
|
|
21
|
+
packageManager: 'npm',
|
|
22
|
+
});
|
|
23
|
+
describe('executeMigration', () => {
|
|
24
|
+
it('exec migration and return expected changes', async () => {
|
|
25
|
+
const testDir = mkdtempSync(join(tmpdir(), 'sce-exec-migration-and-return-changes-'));
|
|
26
|
+
try {
|
|
27
|
+
const projectDir = join(testDir, 'project-dir');
|
|
28
|
+
const generatedProjectDir = join(testDir, 'generated-project-dir');
|
|
29
|
+
mkdirSync(projectDir, { recursive: true });
|
|
30
|
+
mkdirSync(generatedProjectDir, { recursive: true });
|
|
31
|
+
const relFilePath = 'AGENTS.md';
|
|
32
|
+
writeFileSync(join(projectDir, relFilePath), 'project agents md', 'utf-8');
|
|
33
|
+
writeFileSync(join(generatedProjectDir, relFilePath), 'generated fresh agents md', 'utf-8');
|
|
34
|
+
const ctx = {
|
|
35
|
+
projectDir,
|
|
36
|
+
generatedProjectDir,
|
|
37
|
+
templateVersion: 2,
|
|
38
|
+
targetProjectConfig: testProjectConfig,
|
|
39
|
+
updatedProjectConfig: testProjectConfig,
|
|
40
|
+
};
|
|
41
|
+
const result = await executeMigration(ctx, {
|
|
42
|
+
scriptPath: join(getTemplateMigrationsDir('migrations', 2, relFilePath), '001_recreate-with-generated-part.ts'),
|
|
43
|
+
templateRelPath: `${relFilePath}.ejs`,
|
|
44
|
+
templateVersion: 2,
|
|
45
|
+
});
|
|
46
|
+
const expectedChanges = [
|
|
47
|
+
{
|
|
48
|
+
filePath: join(projectDir, relFilePath),
|
|
49
|
+
relFilePath,
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
expect(result).toEqual(expectedChanges);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
rmSync(testDir, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
it('return throw error if migration is not valid', async () => {
|
|
59
|
+
const migrationPlan = {
|
|
60
|
+
scriptPath: '/invalid-path',
|
|
61
|
+
templateVersion: 2,
|
|
62
|
+
templateRelPath: 'AGENTS.md.ejs',
|
|
63
|
+
};
|
|
64
|
+
const ctx = {
|
|
65
|
+
projectDir: '/project-dir',
|
|
66
|
+
targetProjectConfig: testProjectConfig,
|
|
67
|
+
updatedProjectConfig: testProjectConfig,
|
|
68
|
+
templateVersion: migrationPlan.templateVersion,
|
|
69
|
+
generatedProjectDir: '/generated-project-dir',
|
|
70
|
+
};
|
|
71
|
+
const promise = executeMigration(ctx, migrationPlan);
|
|
72
|
+
await expect(promise).rejects.toThrow();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { CLI_COMMANDS_MAP, EXT_HELPER_VERSION } from '../../constants.js';
|
|
6
|
+
import { buildProjectConfig } from '../../projectConfig/buildProjectConfig.js';
|
|
7
|
+
import { executeCommands } from '../../templater/executor.js';
|
|
8
|
+
import { mapProjectConfigToTemplateData } from '../../templater/mappers/mapProjectConfigToTemplateModel.js';
|
|
9
|
+
import { planProject } from '../../templater/planner.js';
|
|
10
|
+
import { MANAGED_TEMPLATES } from '../../templates/constants.js';
|
|
11
|
+
import { collectManagedFiles, discoverVersionDirs, LAST_TEMPLATE_VERSION, TEMPLATES_DIR, } from '../../templates/templates.js';
|
|
12
|
+
import { executeMigrations } from '../executor.js';
|
|
13
|
+
import { planMigrationExecution } from '../planner.js';
|
|
14
|
+
const testBuildProjectConfigOptions = {
|
|
15
|
+
category: 'games-and-fun',
|
|
16
|
+
framework: 'preact',
|
|
17
|
+
lastTemplateVersion: LAST_TEMPLATE_VERSION,
|
|
18
|
+
cliCommands: CLI_COMMANDS_MAP,
|
|
19
|
+
managedTemplates: MANAGED_TEMPLATES,
|
|
20
|
+
templatesDir: TEMPLATES_DIR,
|
|
21
|
+
name: 'test',
|
|
22
|
+
slots: ['EXTENSION_SLOT_MAIN_GAME_FUN', 'EXTENSION_SLOT_BACKGROUND'],
|
|
23
|
+
extHelperVersion: EXT_HELPER_VERSION,
|
|
24
|
+
language: 'ts',
|
|
25
|
+
packageManager: 'npm',
|
|
26
|
+
};
|
|
27
|
+
const compareManagedFiles = (targetProjectDir, referenceProjectDir, templateVersion) => {
|
|
28
|
+
const managedFiles = collectManagedFiles(TEMPLATES_DIR, MANAGED_TEMPLATES, templateVersion);
|
|
29
|
+
const diffFileRelPaths = [];
|
|
30
|
+
for (const managedFile of managedFiles) {
|
|
31
|
+
const targetFileContent = readFileSync(join(targetProjectDir, managedFile.relPath), {
|
|
32
|
+
encoding: 'utf-8',
|
|
33
|
+
});
|
|
34
|
+
const referenceFileContent = readFileSync(join(referenceProjectDir, managedFile.relPath), {
|
|
35
|
+
encoding: 'utf-8',
|
|
36
|
+
});
|
|
37
|
+
console.log('===>');
|
|
38
|
+
console.log('targetFileContent', targetFileContent);
|
|
39
|
+
console.log('referenceFileContent', referenceFileContent);
|
|
40
|
+
if (targetFileContent !== referenceFileContent) {
|
|
41
|
+
diffFileRelPaths.push(managedFile.relPath);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return diffFileRelPaths;
|
|
45
|
+
};
|
|
46
|
+
describe('migrations', () => {
|
|
47
|
+
const versionDirs = discoverVersionDirs(TEMPLATES_DIR, LAST_TEMPLATE_VERSION, 'asc');
|
|
48
|
+
for (const versionDir of versionDirs) {
|
|
49
|
+
if (versionDir.version === LAST_TEMPLATE_VERSION) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
const fromVersion = versionDir.version;
|
|
53
|
+
const toVersion = versionDir.version + 1;
|
|
54
|
+
it(`runs migrations from v${fromVersion} to v${toVersion}`, async () => {
|
|
55
|
+
const targetProjectDir = mkdtempSync(join(tmpdir(), 'sce-test-target-project-dir'));
|
|
56
|
+
const referenceProjectDir = mkdtempSync(join(tmpdir(), 'sce-test-reference-project-dir'));
|
|
57
|
+
try {
|
|
58
|
+
const targetProjectConfig = buildProjectConfig({
|
|
59
|
+
...testBuildProjectConfigOptions,
|
|
60
|
+
lastTemplateVersion: fromVersion,
|
|
61
|
+
});
|
|
62
|
+
const targetTemplateData = mapProjectConfigToTemplateData(targetProjectConfig);
|
|
63
|
+
const targetCommands = planProject(targetProjectDir, fromVersion, targetTemplateData);
|
|
64
|
+
executeCommands(targetCommands);
|
|
65
|
+
const referenceProjectConfig = buildProjectConfig({
|
|
66
|
+
...testBuildProjectConfigOptions,
|
|
67
|
+
lastTemplateVersion: toVersion,
|
|
68
|
+
});
|
|
69
|
+
const referenceTemplateData = mapProjectConfigToTemplateData({
|
|
70
|
+
...referenceProjectConfig,
|
|
71
|
+
lastTemplateVersion: toVersion,
|
|
72
|
+
});
|
|
73
|
+
const referenceCommands = planProject(referenceProjectDir, toVersion, referenceTemplateData);
|
|
74
|
+
executeCommands(referenceCommands);
|
|
75
|
+
const executionPlan = planMigrationExecution(targetProjectConfig, toVersion);
|
|
76
|
+
await executeMigrations({
|
|
77
|
+
projectDir: targetProjectDir,
|
|
78
|
+
executionPlan,
|
|
79
|
+
isDryRun: false,
|
|
80
|
+
});
|
|
81
|
+
const result = compareManagedFiles(targetProjectDir, referenceProjectDir, toVersion);
|
|
82
|
+
expect(result).toEqual([]);
|
|
83
|
+
const idempotentExecutionPlan = planMigrationExecution(targetProjectConfig, toVersion);
|
|
84
|
+
const idempotentResult = await executeMigrations({
|
|
85
|
+
projectDir: targetProjectDir,
|
|
86
|
+
executionPlan: idempotentExecutionPlan,
|
|
87
|
+
isDryRun: false,
|
|
88
|
+
});
|
|
89
|
+
expect(idempotentResult).toEqual([]);
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
rmSync(targetProjectDir, { recursive: true, force: true });
|
|
93
|
+
rmSync(referenceProjectDir, { recursive: true, force: true });
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { copyFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { AGENTS_MD_REL_PATH, } from '../../../../constants.js';
|
|
4
|
+
export const up = (ctx) => {
|
|
5
|
+
const targetAgentsMdFile = join(ctx.projectDir, AGENTS_MD_REL_PATH);
|
|
6
|
+
const generatedAgentsMdFile = join(ctx.generatedProjectDir, AGENTS_MD_REL_PATH);
|
|
7
|
+
copyFileSync(generatedAgentsMdFile, targetAgentsMdFile);
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
filePath: targetAgentsMdFile,
|
|
11
|
+
relFilePath: AGENTS_MD_REL_PATH,
|
|
12
|
+
},
|
|
13
|
+
];
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { copyFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { PROJECT_CONFIG_REL_PATH } from '../../../../constants.js';
|
|
4
|
+
export const up = (ctx) => {
|
|
5
|
+
const targetProjectConfigPath = join(ctx.projectDir, PROJECT_CONFIG_REL_PATH);
|
|
6
|
+
const generatedProjectConfigPath = join(ctx.generatedProjectDir, PROJECT_CONFIG_REL_PATH);
|
|
7
|
+
copyFileSync(generatedProjectConfigPath, targetProjectConfigPath);
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
filePath: targetProjectConfigPath,
|
|
11
|
+
relFilePath: PROJECT_CONFIG_REL_PATH,
|
|
12
|
+
},
|
|
13
|
+
];
|
|
14
|
+
};
|
package/dist/src/migrator/migrations/v2/vite_config_ts/001_turn_off_minify_and_assets_inline.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { IndentationText, NewLineKind, Node, Project, SyntaxKind } from 'ts-morph';
|
|
4
|
+
import { VITE_CONFIG_REL_PATH_BY_LANGUAGE } from '../../../../constants.js';
|
|
5
|
+
const resolveConfigObject = (sourceText, fileName) => {
|
|
6
|
+
const project = new Project({
|
|
7
|
+
manipulationSettings: {
|
|
8
|
+
indentationText: IndentationText.TwoSpaces,
|
|
9
|
+
newLineKind: NewLineKind.LineFeed,
|
|
10
|
+
},
|
|
11
|
+
useInMemoryFileSystem: true,
|
|
12
|
+
});
|
|
13
|
+
const sourceFile = project.createSourceFile(fileName, sourceText, { overwrite: true });
|
|
14
|
+
const exportAssignment = sourceFile.getExportAssignment(() => true);
|
|
15
|
+
if (!exportAssignment || exportAssignment.isExportEquals()) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const expression = exportAssignment.getExpression();
|
|
19
|
+
if (!expression) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (Node.isObjectLiteralExpression(expression)) {
|
|
23
|
+
return { sourceFile, configObject: expression };
|
|
24
|
+
}
|
|
25
|
+
if (!Node.isCallExpression(expression)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const firstArg = expression.getArguments()[0];
|
|
29
|
+
if (!firstArg || !Node.isObjectLiteralExpression(firstArg)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return { sourceFile, configObject: firstArg };
|
|
33
|
+
};
|
|
34
|
+
const withTurnedOffMinifyAndAssetsInline = (viteConfigContent, fileName) => {
|
|
35
|
+
const resolved = resolveConfigObject(viteConfigContent, fileName);
|
|
36
|
+
if (!resolved) {
|
|
37
|
+
return viteConfigContent;
|
|
38
|
+
}
|
|
39
|
+
const { configObject, sourceFile } = resolved;
|
|
40
|
+
const buildProperty = configObject.getProperty('build');
|
|
41
|
+
if (!buildProperty || !Node.isPropertyAssignment(buildProperty)) {
|
|
42
|
+
return viteConfigContent;
|
|
43
|
+
}
|
|
44
|
+
const buildObject = buildProperty.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);
|
|
45
|
+
if (!buildObject) {
|
|
46
|
+
return viteConfigContent;
|
|
47
|
+
}
|
|
48
|
+
const minifyProperty = buildObject.getProperty('minify');
|
|
49
|
+
const assetsInlineLimitProperty = buildObject.getProperty('assetsInlineLimit');
|
|
50
|
+
let isPresetMinify = false;
|
|
51
|
+
let isPresentAssetsInlineLimit = false;
|
|
52
|
+
if (minifyProperty && Node.isPropertyAssignment(minifyProperty)) {
|
|
53
|
+
minifyProperty.setInitializer('false');
|
|
54
|
+
isPresetMinify = true;
|
|
55
|
+
}
|
|
56
|
+
if (assetsInlineLimitProperty && Node.isPropertyAssignment(assetsInlineLimitProperty)) {
|
|
57
|
+
assetsInlineLimitProperty.setInitializer('0');
|
|
58
|
+
isPresentAssetsInlineLimit = true;
|
|
59
|
+
}
|
|
60
|
+
const properties = buildObject.getProperties();
|
|
61
|
+
const outDirProperty = properties.find((property) => Node.isPropertyAssignment(property) && property.getName() === 'outDir');
|
|
62
|
+
const rollupProperty = properties.find((property) => Node.isPropertyAssignment(property) && property.getName() === 'rollupOptions');
|
|
63
|
+
const outDirIndex = outDirProperty ? properties.indexOf(outDirProperty) : -1;
|
|
64
|
+
const rollupIndex = rollupProperty ? properties.indexOf(rollupProperty) : -1;
|
|
65
|
+
let currInsertIndex = rollupIndex >= 0
|
|
66
|
+
? rollupIndex
|
|
67
|
+
: outDirIndex >= 0
|
|
68
|
+
? outDirIndex + 1
|
|
69
|
+
: properties.length;
|
|
70
|
+
if (!isPresetMinify) {
|
|
71
|
+
buildObject.insertPropertyAssignment(currInsertIndex, {
|
|
72
|
+
name: 'minify',
|
|
73
|
+
initializer: 'false',
|
|
74
|
+
});
|
|
75
|
+
currInsertIndex += 1;
|
|
76
|
+
}
|
|
77
|
+
if (!isPresentAssetsInlineLimit) {
|
|
78
|
+
buildObject.insertPropertyAssignment(currInsertIndex, {
|
|
79
|
+
name: 'assetsInlineLimit',
|
|
80
|
+
initializer: '0',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
sourceFile.formatText({
|
|
84
|
+
convertTabsToSpaces: true,
|
|
85
|
+
indentSize: 2,
|
|
86
|
+
});
|
|
87
|
+
return sourceFile.getFullText();
|
|
88
|
+
};
|
|
89
|
+
export const up = (ctx) => {
|
|
90
|
+
const viteConfigRelPath = VITE_CONFIG_REL_PATH_BY_LANGUAGE[ctx.targetProjectConfig.language];
|
|
91
|
+
const targetViteConfigPath = join(ctx.projectDir, viteConfigRelPath);
|
|
92
|
+
const generatedViteConfigPath = join(ctx.generatedProjectDir, viteConfigRelPath);
|
|
93
|
+
if (!existsSync(targetViteConfigPath)) {
|
|
94
|
+
mkdirSync(dirname(targetViteConfigPath), { recursive: true });
|
|
95
|
+
copyFileSync(generatedViteConfigPath, targetViteConfigPath);
|
|
96
|
+
return [
|
|
97
|
+
{
|
|
98
|
+
filePath: targetViteConfigPath,
|
|
99
|
+
relFilePath: viteConfigRelPath,
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
const targetViteConfigContent = readFileSync(targetViteConfigPath, 'utf8');
|
|
104
|
+
const mergedViteConfigContent = withTurnedOffMinifyAndAssetsInline(targetViteConfigContent, viteConfigRelPath);
|
|
105
|
+
if (targetViteConfigContent === mergedViteConfigContent) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
writeFileSync(targetViteConfigPath, mergedViteConfigContent, {
|
|
109
|
+
encoding: 'utf8',
|
|
110
|
+
flag: 'w',
|
|
111
|
+
});
|
|
112
|
+
return [
|
|
113
|
+
{
|
|
114
|
+
filePath: targetViteConfigPath,
|
|
115
|
+
relFilePath: viteConfigRelPath,
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
};
|