@powerlines/core 0.0.8
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/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/index.cjs +65 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.mjs +22 -0
- package/dist/lib/config.cjs +90 -0
- package/dist/lib/config.cjs.map +1 -0
- package/dist/lib/config.d.cts +40 -0
- package/dist/lib/config.d.cts.map +1 -0
- package/dist/lib/config.d.mts +40 -0
- package/dist/lib/config.d.mts.map +1 -0
- package/dist/lib/config.mjs +86 -0
- package/dist/lib/config.mjs.map +1 -0
- package/dist/lib/constants/environments.cjs +17 -0
- package/dist/lib/constants/environments.cjs.map +1 -0
- package/dist/lib/constants/environments.d.cts +10 -0
- package/dist/lib/constants/environments.d.cts.map +1 -0
- package/dist/lib/constants/environments.d.mts +10 -0
- package/dist/lib/constants/environments.d.mts.map +1 -0
- package/dist/lib/constants/environments.mjs +11 -0
- package/dist/lib/constants/environments.mjs.map +1 -0
- package/dist/lib/constants/index.cjs +11 -0
- package/dist/lib/constants/index.d.cts +3 -0
- package/dist/lib/constants/index.d.mts +3 -0
- package/dist/lib/constants/index.mjs +4 -0
- package/dist/lib/constants/meta.cjs +9 -0
- package/dist/lib/constants/meta.cjs.map +1 -0
- package/dist/lib/constants/meta.d.cts +6 -0
- package/dist/lib/constants/meta.d.cts.map +1 -0
- package/dist/lib/constants/meta.d.mts +6 -0
- package/dist/lib/constants/meta.d.mts.map +1 -0
- package/dist/lib/constants/meta.mjs +7 -0
- package/dist/lib/constants/meta.mjs.map +1 -0
- package/dist/lib/entry.cjs +127 -0
- package/dist/lib/entry.cjs.map +1 -0
- package/dist/lib/entry.d.cts +47 -0
- package/dist/lib/entry.d.cts.map +1 -0
- package/dist/lib/entry.d.mts +48 -0
- package/dist/lib/entry.d.mts.map +1 -0
- package/dist/lib/entry.mjs +120 -0
- package/dist/lib/entry.mjs.map +1 -0
- package/dist/lib/index.cjs +50 -0
- package/dist/lib/index.d.cts +14 -0
- package/dist/lib/index.d.mts +16 -0
- package/dist/lib/index.mjs +17 -0
- package/dist/lib/logger.cjs +59 -0
- package/dist/lib/logger.cjs.map +1 -0
- package/dist/lib/logger.d.cts +23 -0
- package/dist/lib/logger.d.cts.map +1 -0
- package/dist/lib/logger.d.mts +24 -0
- package/dist/lib/logger.d.mts.map +1 -0
- package/dist/lib/logger.mjs +56 -0
- package/dist/lib/logger.mjs.map +1 -0
- package/dist/lib/unplugin/helpers.cjs +30 -0
- package/dist/lib/unplugin/helpers.cjs.map +1 -0
- package/dist/lib/unplugin/helpers.d.cts +24 -0
- package/dist/lib/unplugin/helpers.d.cts.map +1 -0
- package/dist/lib/unplugin/helpers.d.mts +24 -0
- package/dist/lib/unplugin/helpers.d.mts.map +1 -0
- package/dist/lib/unplugin/helpers.mjs +28 -0
- package/dist/lib/unplugin/helpers.mjs.map +1 -0
- package/dist/lib/unplugin/index.cjs +9 -0
- package/dist/lib/unplugin/index.d.cts +4 -0
- package/dist/lib/unplugin/index.d.mts +4 -0
- package/dist/lib/unplugin/index.mjs +5 -0
- package/dist/lib/unplugin/module-resolution.cjs +67 -0
- package/dist/lib/unplugin/module-resolution.cjs.map +1 -0
- package/dist/lib/unplugin/module-resolution.d.cts +21 -0
- package/dist/lib/unplugin/module-resolution.d.cts.map +1 -0
- package/dist/lib/unplugin/module-resolution.d.mts +21 -0
- package/dist/lib/unplugin/module-resolution.d.mts.map +1 -0
- package/dist/lib/unplugin/module-resolution.mjs +66 -0
- package/dist/lib/unplugin/module-resolution.mjs.map +1 -0
- package/dist/lib/unplugin/plugin.cjs +105 -0
- package/dist/lib/unplugin/plugin.cjs.map +1 -0
- package/dist/lib/unplugin/plugin.d.cts +22 -0
- package/dist/lib/unplugin/plugin.d.cts.map +1 -0
- package/dist/lib/unplugin/plugin.d.mts +22 -0
- package/dist/lib/unplugin/plugin.d.mts.map +1 -0
- package/dist/lib/unplugin/plugin.mjs +103 -0
- package/dist/lib/unplugin/plugin.mjs.map +1 -0
- package/dist/lib/utilities/file-header.cjs +24 -0
- package/dist/lib/utilities/file-header.cjs.map +1 -0
- package/dist/lib/utilities/file-header.d.cts +13 -0
- package/dist/lib/utilities/file-header.d.cts.map +1 -0
- package/dist/lib/utilities/file-header.d.mts +13 -0
- package/dist/lib/utilities/file-header.d.mts.map +1 -0
- package/dist/lib/utilities/file-header.mjs +22 -0
- package/dist/lib/utilities/file-header.mjs.map +1 -0
- package/dist/lib/utilities/format.cjs +49 -0
- package/dist/lib/utilities/format.cjs.map +1 -0
- package/dist/lib/utilities/format.d.cts +25 -0
- package/dist/lib/utilities/format.d.cts.map +1 -0
- package/dist/lib/utilities/format.d.mts +25 -0
- package/dist/lib/utilities/format.d.mts.map +1 -0
- package/dist/lib/utilities/format.mjs +47 -0
- package/dist/lib/utilities/format.mjs.map +1 -0
- package/dist/lib/utilities/index.cjs +15 -0
- package/dist/lib/utilities/index.d.cts +6 -0
- package/dist/lib/utilities/index.d.mts +6 -0
- package/dist/lib/utilities/index.mjs +7 -0
- package/dist/lib/utilities/source-file.cjs +50 -0
- package/dist/lib/utilities/source-file.cjs.map +1 -0
- package/dist/lib/utilities/source-file.d.cts +31 -0
- package/dist/lib/utilities/source-file.d.cts.map +1 -0
- package/dist/lib/utilities/source-file.d.mts +31 -0
- package/dist/lib/utilities/source-file.d.mts.map +1 -0
- package/dist/lib/utilities/source-file.mjs +46 -0
- package/dist/lib/utilities/source-file.mjs.map +1 -0
- package/dist/lib/utilities/source-map.cjs +57 -0
- package/dist/lib/utilities/source-map.cjs.map +1 -0
- package/dist/lib/utilities/source-map.d.cts +17 -0
- package/dist/lib/utilities/source-map.d.cts.map +1 -0
- package/dist/lib/utilities/source-map.d.mts +17 -0
- package/dist/lib/utilities/source-map.d.mts.map +1 -0
- package/dist/lib/utilities/source-map.mjs +55 -0
- package/dist/lib/utilities/source-map.mjs.map +1 -0
- package/dist/lib/utilities/write-file.cjs +29 -0
- package/dist/lib/utilities/write-file.cjs.map +1 -0
- package/dist/lib/utilities/write-file.d.cts +16 -0
- package/dist/lib/utilities/write-file.d.cts.map +1 -0
- package/dist/lib/utilities/write-file.d.mts +16 -0
- package/dist/lib/utilities/write-file.d.mts.map +1 -0
- package/dist/lib/utilities/write-file.mjs +28 -0
- package/dist/lib/utilities/write-file.mjs.map +1 -0
- package/dist/plugin-base.cjs +73 -0
- package/dist/plugin-base.cjs.map +1 -0
- package/dist/plugin-base.d.cts +27 -0
- package/dist/plugin-base.d.cts.map +1 -0
- package/dist/plugin-base.d.mts +27 -0
- package/dist/plugin-base.d.mts.map +1 -0
- package/dist/plugin-base.mjs +70 -0
- package/dist/plugin-base.mjs.map +1 -0
- package/dist/plugin-utils/build-helpers.cjs +36 -0
- package/dist/plugin-utils/build-helpers.cjs.map +1 -0
- package/dist/plugin-utils/build-helpers.d.cts +19 -0
- package/dist/plugin-utils/build-helpers.d.cts.map +1 -0
- package/dist/plugin-utils/build-helpers.d.mts +19 -0
- package/dist/plugin-utils/build-helpers.d.mts.map +1 -0
- package/dist/plugin-utils/build-helpers.mjs +35 -0
- package/dist/plugin-utils/build-helpers.mjs.map +1 -0
- package/dist/plugin-utils/context-helpers.cjs +50 -0
- package/dist/plugin-utils/context-helpers.cjs.map +1 -0
- package/dist/plugin-utils/context-helpers.d.cts +21 -0
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -0
- package/dist/plugin-utils/context-helpers.d.mts +21 -0
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -0
- package/dist/plugin-utils/context-helpers.mjs +48 -0
- package/dist/plugin-utils/context-helpers.mjs.map +1 -0
- package/dist/plugin-utils/extend.cjs +25 -0
- package/dist/plugin-utils/extend.cjs.map +1 -0
- package/dist/plugin-utils/extend.d.cts +20 -0
- package/dist/plugin-utils/extend.d.cts.map +1 -0
- package/dist/plugin-utils/extend.d.mts +20 -0
- package/dist/plugin-utils/extend.d.mts.map +1 -0
- package/dist/plugin-utils/extend.mjs +24 -0
- package/dist/plugin-utils/extend.mjs.map +1 -0
- package/dist/plugin-utils/format-package-json.cjs +20 -0
- package/dist/plugin-utils/format-package-json.cjs.map +1 -0
- package/dist/plugin-utils/format-package-json.d.cts +13 -0
- package/dist/plugin-utils/format-package-json.d.cts.map +1 -0
- package/dist/plugin-utils/format-package-json.d.mts +13 -0
- package/dist/plugin-utils/format-package-json.d.mts.map +1 -0
- package/dist/plugin-utils/format-package-json.mjs +19 -0
- package/dist/plugin-utils/format-package-json.mjs.map +1 -0
- package/dist/plugin-utils/get-config-path.cjs +50 -0
- package/dist/plugin-utils/get-config-path.cjs.map +1 -0
- package/dist/plugin-utils/get-config-path.d.cts +15 -0
- package/dist/plugin-utils/get-config-path.d.cts.map +1 -0
- package/dist/plugin-utils/get-config-path.d.mts +15 -0
- package/dist/plugin-utils/get-config-path.d.mts.map +1 -0
- package/dist/plugin-utils/get-config-path.mjs +49 -0
- package/dist/plugin-utils/get-config-path.mjs.map +1 -0
- package/dist/plugin-utils/helpers.cjs +185 -0
- package/dist/plugin-utils/helpers.cjs.map +1 -0
- package/dist/plugin-utils/helpers.d.cts +144 -0
- package/dist/plugin-utils/helpers.d.cts.map +1 -0
- package/dist/plugin-utils/helpers.d.mts +144 -0
- package/dist/plugin-utils/helpers.d.mts.map +1 -0
- package/dist/plugin-utils/helpers.mjs +170 -0
- package/dist/plugin-utils/helpers.mjs.map +1 -0
- package/dist/plugin-utils/index.cjs +35 -0
- package/dist/plugin-utils/index.d.cts +10 -0
- package/dist/plugin-utils/index.d.mts +10 -0
- package/dist/plugin-utils/index.mjs +11 -0
- package/dist/plugin-utils/merge.cjs +60 -0
- package/dist/plugin-utils/merge.cjs.map +1 -0
- package/dist/plugin-utils/merge.d.cts +35 -0
- package/dist/plugin-utils/merge.d.cts.map +1 -0
- package/dist/plugin-utils/merge.d.mts +35 -0
- package/dist/plugin-utils/merge.d.mts.map +1 -0
- package/dist/plugin-utils/merge.mjs +57 -0
- package/dist/plugin-utils/merge.mjs.map +1 -0
- package/dist/plugin-utils/modules.cjs +17 -0
- package/dist/plugin-utils/modules.cjs.map +1 -0
- package/dist/plugin-utils/modules.d.cts +15 -0
- package/dist/plugin-utils/modules.d.cts.map +1 -0
- package/dist/plugin-utils/modules.d.mts +15 -0
- package/dist/plugin-utils/modules.d.mts.map +1 -0
- package/dist/plugin-utils/modules.mjs +16 -0
- package/dist/plugin-utils/modules.mjs.map +1 -0
- package/dist/plugin-utils/paths.cjs +38 -0
- package/dist/plugin-utils/paths.cjs.map +1 -0
- package/dist/plugin-utils/paths.d.cts +34 -0
- package/dist/plugin-utils/paths.d.cts.map +1 -0
- package/dist/plugin-utils/paths.d.mts +34 -0
- package/dist/plugin-utils/paths.d.mts.map +1 -0
- package/dist/plugin-utils/paths.mjs +37 -0
- package/dist/plugin-utils/paths.mjs.map +1 -0
- package/dist/types/_internal.cjs +0 -0
- package/dist/types/_internal.d.cts +107 -0
- package/dist/types/_internal.d.cts.map +1 -0
- package/dist/types/_internal.d.mts +107 -0
- package/dist/types/_internal.d.mts.map +1 -0
- package/dist/types/_internal.mjs +1 -0
- package/dist/types/api.cjs +0 -0
- package/dist/types/api.d.cts +104 -0
- package/dist/types/api.d.cts.map +1 -0
- package/dist/types/api.d.mts +104 -0
- package/dist/types/api.d.mts.map +1 -0
- package/dist/types/api.mjs +1 -0
- package/dist/types/commands.cjs +17 -0
- package/dist/types/commands.cjs.map +1 -0
- package/dist/types/commands.d.cts +13 -0
- package/dist/types/commands.d.cts.map +1 -0
- package/dist/types/commands.d.mts +13 -0
- package/dist/types/commands.d.mts.map +1 -0
- package/dist/types/commands.mjs +16 -0
- package/dist/types/commands.mjs.map +1 -0
- package/dist/types/config.cjs +0 -0
- package/dist/types/config.d.cts +617 -0
- package/dist/types/config.d.cts.map +1 -0
- package/dist/types/config.d.mts +617 -0
- package/dist/types/config.d.mts.map +1 -0
- package/dist/types/config.mjs +1 -0
- package/dist/types/context.cjs +0 -0
- package/dist/types/context.d.cts +564 -0
- package/dist/types/context.d.cts.map +1 -0
- package/dist/types/context.d.mts +564 -0
- package/dist/types/context.d.mts.map +1 -0
- package/dist/types/context.mjs +1 -0
- package/dist/types/fs.cjs +11 -0
- package/dist/types/fs.cjs.map +1 -0
- package/dist/types/fs.d.cts +502 -0
- package/dist/types/fs.d.cts.map +1 -0
- package/dist/types/fs.d.mts +502 -0
- package/dist/types/fs.d.mts.map +1 -0
- package/dist/types/fs.mjs +8 -0
- package/dist/types/fs.mjs.map +1 -0
- package/dist/types/hooks.cjs +13 -0
- package/dist/types/hooks.cjs.map +1 -0
- package/dist/types/hooks.d.cts +117 -0
- package/dist/types/hooks.d.cts.map +1 -0
- package/dist/types/hooks.d.mts +117 -0
- package/dist/types/hooks.d.mts.map +1 -0
- package/dist/types/hooks.mjs +12 -0
- package/dist/types/hooks.mjs.map +1 -0
- package/dist/types/index.cjs +16 -0
- package/dist/types/index.d.cts +10 -0
- package/dist/types/index.d.mts +10 -0
- package/dist/types/index.mjs +7 -0
- package/dist/types/plugin.cjs +35 -0
- package/dist/types/plugin.cjs.map +1 -0
- package/dist/types/plugin.d.cts +218 -0
- package/dist/types/plugin.d.cts.map +1 -0
- package/dist/types/plugin.d.mts +218 -0
- package/dist/types/plugin.d.mts.map +1 -0
- package/dist/types/plugin.mjs +33 -0
- package/dist/types/plugin.mjs.map +1 -0
- package/dist/types/tsconfig.cjs +0 -0
- package/dist/types/tsconfig.d.cts +77 -0
- package/dist/types/tsconfig.d.cts.map +1 -0
- package/dist/types/tsconfig.d.mts +77 -0
- package/dist/types/tsconfig.d.mts.map +1 -0
- package/dist/types/tsconfig.mjs +1 -0
- package/dist/types/unplugin.cjs +24 -0
- package/dist/types/unplugin.cjs.map +1 -0
- package/dist/types/unplugin.d.cts +41 -0
- package/dist/types/unplugin.d.cts.map +1 -0
- package/dist/types/unplugin.d.mts +41 -0
- package/dist/types/unplugin.d.mts.map +1 -0
- package/dist/types/unplugin.mjs +22 -0
- package/dist/types/unplugin.mjs.map +1 -0
- package/package.json +238 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __stryke_path_append = require("@stryke/path/append");
|
|
3
|
+
let __stryke_fs_list_files = require("@stryke/fs/list-files");
|
|
4
|
+
let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
|
|
5
|
+
let prettier = require("prettier");
|
|
6
|
+
|
|
7
|
+
//#region src/lib/utilities/format.ts
|
|
8
|
+
/**
|
|
9
|
+
* Formats code using Prettier based on the file path.
|
|
10
|
+
*
|
|
11
|
+
* @param context - The Powerlines context.
|
|
12
|
+
* @param path - The file path to use for resolving Prettier configuration.
|
|
13
|
+
* @param data - The code string to format.
|
|
14
|
+
* @param force - Whether to force formatting even for output/build paths.
|
|
15
|
+
* @returns A promise that resolves to the formatted code string.
|
|
16
|
+
*/
|
|
17
|
+
async function format(context, path, data, force = false) {
|
|
18
|
+
if (!force && ((0, __stryke_path_is_parent_path.isParentPath)(path, (0, __stryke_path_append.appendPath)(context.config.output.outputPath, context.workspaceConfig.workspaceRoot)) || (0, __stryke_path_is_parent_path.isParentPath)(path, (0, __stryke_path_append.appendPath)(context.config.output.buildPath, context.workspaceConfig.workspaceRoot)))) return data;
|
|
19
|
+
let code = data;
|
|
20
|
+
const resolvedConfig = await (0, prettier.resolveConfig)(path);
|
|
21
|
+
if (resolvedConfig) code = await (0, prettier.format)(data, {
|
|
22
|
+
absolutePath: path,
|
|
23
|
+
...resolvedConfig
|
|
24
|
+
});
|
|
25
|
+
return code;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Formats all files in a folder using Prettier based on their file paths.
|
|
29
|
+
*
|
|
30
|
+
* @param context - The Powerlines context.
|
|
31
|
+
* @param path - The folder path containing files to format.
|
|
32
|
+
* @returns A promise that resolves when all files have been formatted.
|
|
33
|
+
*/
|
|
34
|
+
async function formatFolder(context, path) {
|
|
35
|
+
if (!(0, __stryke_path_is_parent_path.isParentPath)(path, (0, __stryke_path_append.appendPath)(context.config.output.outputPath, context.workspaceConfig.workspaceRoot)) && !(0, __stryke_path_is_parent_path.isParentPath)(path, (0, __stryke_path_append.appendPath)(context.config.output.buildPath, context.workspaceConfig.workspaceRoot))) await Promise.allSettled((await (0, __stryke_fs_list_files.listFiles)(path)).map(async (file) => {
|
|
36
|
+
if (!(0, __stryke_path_is_parent_path.isParentPath)(file, (0, __stryke_path_append.appendPath)(context.config.output.outputPath, context.workspaceConfig.workspaceRoot)) && !(0, __stryke_path_is_parent_path.isParentPath)(file, (0, __stryke_path_append.appendPath)(context.config.output.buildPath, context.workspaceConfig.workspaceRoot))) {
|
|
37
|
+
const data = await context.fs.read(file);
|
|
38
|
+
if (data) {
|
|
39
|
+
const formatted = await format(context, file, data);
|
|
40
|
+
return context.fs.write(file, formatted);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.format = format;
|
|
48
|
+
exports.formatFolder = formatFolder;
|
|
49
|
+
//# sourceMappingURL=format.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.cjs","names":[],"sources":["../../../src/lib/utilities/format.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { listFiles } from \"@stryke/fs/list-files\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { format as prettier, resolveConfig } from \"prettier\";\nimport { Context } from \"../../types/context\";\n\n/**\n * Formats code using Prettier based on the file path.\n *\n * @param context - The Powerlines context.\n * @param path - The file path to use for resolving Prettier configuration.\n * @param data - The code string to format.\n * @param force - Whether to force formatting even for output/build paths.\n * @returns A promise that resolves to the formatted code string.\n */\nexport async function format(\n context: Context,\n path: string,\n data: string,\n force = false\n): Promise<string> {\n if (\n !force &&\n (isParentPath(\n path,\n appendPath(\n context.config.output.outputPath,\n context.workspaceConfig.workspaceRoot\n )\n ) ||\n isParentPath(\n path,\n appendPath(\n context.config.output.buildPath,\n context.workspaceConfig.workspaceRoot\n )\n ))\n ) {\n return data;\n }\n\n let code = data;\n const resolvedConfig = await resolveConfig(path);\n if (resolvedConfig) {\n code = await prettier(data, {\n absolutePath: path,\n ...resolvedConfig\n });\n }\n\n return code;\n}\n\n/**\n * Formats all files in a folder using Prettier based on their file paths.\n *\n * @param context - The Powerlines context.\n * @param path - The folder path containing files to format.\n * @returns A promise that resolves when all files have been formatted.\n */\nexport async function formatFolder(context: Context, path: string) {\n if (\n !isParentPath(\n path,\n appendPath(\n context.config.output.outputPath,\n context.workspaceConfig.workspaceRoot\n )\n ) &&\n !isParentPath(\n path,\n appendPath(\n context.config.output.buildPath,\n context.workspaceConfig.workspaceRoot\n )\n )\n ) {\n await Promise.allSettled(\n (await listFiles(path)).map(async file => {\n if (\n !isParentPath(\n file,\n appendPath(\n context.config.output.outputPath,\n context.workspaceConfig.workspaceRoot\n )\n ) &&\n !isParentPath(\n file,\n appendPath(\n context.config.output.buildPath,\n context.workspaceConfig.workspaceRoot\n )\n )\n ) {\n const data = await context.fs.read(file);\n if (data) {\n const formatted = await format(context, file, data);\n\n return context.fs.write(file, formatted);\n }\n }\n })\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiCA,eAAsB,OACpB,SACA,MACA,MACA,QAAQ,OACS;AACjB,KACE,CAAC,yDAEC,2CAEE,QAAQ,OAAO,OAAO,YACtB,QAAQ,gBAAgB,cACzB,CACF,mDAEG,2CAEE,QAAQ,OAAO,OAAO,WACtB,QAAQ,gBAAgB,cACzB,CACF,EAEH,QAAO;CAGT,IAAI,OAAO;CACX,MAAM,iBAAiB,kCAAoB,KAAK;AAChD,KAAI,eACF,QAAO,2BAAe,MAAM;EAC1B,cAAc;EACd,GAAG;EACJ,CAAC;AAGJ,QAAO;;;;;;;;;AAUT,eAAsB,aAAa,SAAkB,MAAc;AACjE,KACE,gDACE,2CAEE,QAAQ,OAAO,OAAO,YACtB,QAAQ,gBAAgB,cACzB,CACF,IACD,gDACE,2CAEE,QAAQ,OAAO,OAAO,WACtB,QAAQ,gBAAgB,cACzB,CACF,CAED,OAAM,QAAQ,YACX,4CAAgB,KAAK,EAAE,IAAI,OAAM,SAAQ;AACxC,MACE,gDACE,2CAEE,QAAQ,OAAO,OAAO,YACtB,QAAQ,gBAAgB,cACzB,CACF,IACD,gDACE,2CAEE,QAAQ,OAAO,OAAO,WACtB,QAAQ,gBAAgB,cACzB,CACF,EACD;GACA,MAAM,OAAO,MAAM,QAAQ,GAAG,KAAK,KAAK;AACxC,OAAI,MAAM;IACR,MAAM,YAAY,MAAM,OAAO,SAAS,MAAM,KAAK;AAEnD,WAAO,QAAQ,GAAG,MAAM,MAAM,UAAU;;;GAG5C,CACH"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Context } from "../../types/context.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/utilities/format.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Formats code using Prettier based on the file path.
|
|
7
|
+
*
|
|
8
|
+
* @param context - The Powerlines context.
|
|
9
|
+
* @param path - The file path to use for resolving Prettier configuration.
|
|
10
|
+
* @param data - The code string to format.
|
|
11
|
+
* @param force - Whether to force formatting even for output/build paths.
|
|
12
|
+
* @returns A promise that resolves to the formatted code string.
|
|
13
|
+
*/
|
|
14
|
+
declare function format(context: Context, path: string, data: string, force?: boolean): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Formats all files in a folder using Prettier based on their file paths.
|
|
17
|
+
*
|
|
18
|
+
* @param context - The Powerlines context.
|
|
19
|
+
* @param path - The folder path containing files to format.
|
|
20
|
+
* @returns A promise that resolves when all files have been formatted.
|
|
21
|
+
*/
|
|
22
|
+
declare function formatFolder(context: Context, path: string): Promise<void>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { format, formatFolder };
|
|
25
|
+
//# sourceMappingURL=format.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.cts","names":[],"sources":["../../../src/lib/utilities/format.ts"],"sourcesContent":[],"mappings":";;;;;;AAiCA;AA6CA;;;;;;iBA7CsB,MAAA,UACX,uDAIR;;;;;;;;iBAwCmB,YAAA,UAAsB,wBAAqB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Context } from "../../types/context.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/utilities/format.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Formats code using Prettier based on the file path.
|
|
7
|
+
*
|
|
8
|
+
* @param context - The Powerlines context.
|
|
9
|
+
* @param path - The file path to use for resolving Prettier configuration.
|
|
10
|
+
* @param data - The code string to format.
|
|
11
|
+
* @param force - Whether to force formatting even for output/build paths.
|
|
12
|
+
* @returns A promise that resolves to the formatted code string.
|
|
13
|
+
*/
|
|
14
|
+
declare function format(context: Context, path: string, data: string, force?: boolean): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Formats all files in a folder using Prettier based on their file paths.
|
|
17
|
+
*
|
|
18
|
+
* @param context - The Powerlines context.
|
|
19
|
+
* @param path - The folder path containing files to format.
|
|
20
|
+
* @returns A promise that resolves when all files have been formatted.
|
|
21
|
+
*/
|
|
22
|
+
declare function formatFolder(context: Context, path: string): Promise<void>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { format, formatFolder };
|
|
25
|
+
//# sourceMappingURL=format.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.mts","names":[],"sources":["../../../src/lib/utilities/format.ts"],"sourcesContent":[],"mappings":";;;;;;AAiCA;AA6CA;;;;;;iBA7CsB,MAAA,UACX,uDAIR;;;;;;;;iBAwCmB,YAAA,UAAsB,wBAAqB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { appendPath } from "@stryke/path/append";
|
|
2
|
+
import { listFiles } from "@stryke/fs/list-files";
|
|
3
|
+
import { isParentPath } from "@stryke/path/is-parent-path";
|
|
4
|
+
import { format as format$1, resolveConfig } from "prettier";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/utilities/format.ts
|
|
7
|
+
/**
|
|
8
|
+
* Formats code using Prettier based on the file path.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The Powerlines context.
|
|
11
|
+
* @param path - The file path to use for resolving Prettier configuration.
|
|
12
|
+
* @param data - The code string to format.
|
|
13
|
+
* @param force - Whether to force formatting even for output/build paths.
|
|
14
|
+
* @returns A promise that resolves to the formatted code string.
|
|
15
|
+
*/
|
|
16
|
+
async function format(context, path, data, force = false) {
|
|
17
|
+
if (!force && (isParentPath(path, appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot)) || isParentPath(path, appendPath(context.config.output.buildPath, context.workspaceConfig.workspaceRoot)))) return data;
|
|
18
|
+
let code = data;
|
|
19
|
+
const resolvedConfig = await resolveConfig(path);
|
|
20
|
+
if (resolvedConfig) code = await format$1(data, {
|
|
21
|
+
absolutePath: path,
|
|
22
|
+
...resolvedConfig
|
|
23
|
+
});
|
|
24
|
+
return code;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Formats all files in a folder using Prettier based on their file paths.
|
|
28
|
+
*
|
|
29
|
+
* @param context - The Powerlines context.
|
|
30
|
+
* @param path - The folder path containing files to format.
|
|
31
|
+
* @returns A promise that resolves when all files have been formatted.
|
|
32
|
+
*/
|
|
33
|
+
async function formatFolder(context, path) {
|
|
34
|
+
if (!isParentPath(path, appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot)) && !isParentPath(path, appendPath(context.config.output.buildPath, context.workspaceConfig.workspaceRoot))) await Promise.allSettled((await listFiles(path)).map(async (file) => {
|
|
35
|
+
if (!isParentPath(file, appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot)) && !isParentPath(file, appendPath(context.config.output.buildPath, context.workspaceConfig.workspaceRoot))) {
|
|
36
|
+
const data = await context.fs.read(file);
|
|
37
|
+
if (data) {
|
|
38
|
+
const formatted = await format(context, file, data);
|
|
39
|
+
return context.fs.write(file, formatted);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { format, formatFolder };
|
|
47
|
+
//# sourceMappingURL=format.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.mjs","names":["prettier"],"sources":["../../../src/lib/utilities/format.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { listFiles } from \"@stryke/fs/list-files\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { format as prettier, resolveConfig } from \"prettier\";\nimport { Context } from \"../../types/context\";\n\n/**\n * Formats code using Prettier based on the file path.\n *\n * @param context - The Powerlines context.\n * @param path - The file path to use for resolving Prettier configuration.\n * @param data - The code string to format.\n * @param force - Whether to force formatting even for output/build paths.\n * @returns A promise that resolves to the formatted code string.\n */\nexport async function format(\n context: Context,\n path: string,\n data: string,\n force = false\n): Promise<string> {\n if (\n !force &&\n (isParentPath(\n path,\n appendPath(\n context.config.output.outputPath,\n context.workspaceConfig.workspaceRoot\n )\n ) ||\n isParentPath(\n path,\n appendPath(\n context.config.output.buildPath,\n context.workspaceConfig.workspaceRoot\n )\n ))\n ) {\n return data;\n }\n\n let code = data;\n const resolvedConfig = await resolveConfig(path);\n if (resolvedConfig) {\n code = await prettier(data, {\n absolutePath: path,\n ...resolvedConfig\n });\n }\n\n return code;\n}\n\n/**\n * Formats all files in a folder using Prettier based on their file paths.\n *\n * @param context - The Powerlines context.\n * @param path - The folder path containing files to format.\n * @returns A promise that resolves when all files have been formatted.\n */\nexport async function formatFolder(context: Context, path: string) {\n if (\n !isParentPath(\n path,\n appendPath(\n context.config.output.outputPath,\n context.workspaceConfig.workspaceRoot\n )\n ) &&\n !isParentPath(\n path,\n appendPath(\n context.config.output.buildPath,\n context.workspaceConfig.workspaceRoot\n )\n )\n ) {\n await Promise.allSettled(\n (await listFiles(path)).map(async file => {\n if (\n !isParentPath(\n file,\n appendPath(\n context.config.output.outputPath,\n context.workspaceConfig.workspaceRoot\n )\n ) &&\n !isParentPath(\n file,\n appendPath(\n context.config.output.buildPath,\n context.workspaceConfig.workspaceRoot\n )\n )\n ) {\n const data = await context.fs.read(file);\n if (data) {\n const formatted = await format(context, file, data);\n\n return context.fs.write(file, formatted);\n }\n }\n })\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiCA,eAAsB,OACpB,SACA,MACA,MACA,QAAQ,OACS;AACjB,KACE,CAAC,UACA,aACC,MACA,WACE,QAAQ,OAAO,OAAO,YACtB,QAAQ,gBAAgB,cACzB,CACF,IACC,aACE,MACA,WACE,QAAQ,OAAO,OAAO,WACtB,QAAQ,gBAAgB,cACzB,CACF,EAEH,QAAO;CAGT,IAAI,OAAO;CACX,MAAM,iBAAiB,MAAM,cAAc,KAAK;AAChD,KAAI,eACF,QAAO,MAAMA,SAAS,MAAM;EAC1B,cAAc;EACd,GAAG;EACJ,CAAC;AAGJ,QAAO;;;;;;;;;AAUT,eAAsB,aAAa,SAAkB,MAAc;AACjE,KACE,CAAC,aACC,MACA,WACE,QAAQ,OAAO,OAAO,YACtB,QAAQ,gBAAgB,cACzB,CACF,IACD,CAAC,aACC,MACA,WACE,QAAQ,OAAO,OAAO,WACtB,QAAQ,gBAAgB,cACzB,CACF,CAED,OAAM,QAAQ,YACX,MAAM,UAAU,KAAK,EAAE,IAAI,OAAM,SAAQ;AACxC,MACE,CAAC,aACC,MACA,WACE,QAAQ,OAAO,OAAO,YACtB,QAAQ,gBAAgB,cACzB,CACF,IACD,CAAC,aACC,MACA,WACE,QAAQ,OAAO,OAAO,WACtB,QAAQ,gBAAgB,cACzB,CACF,EACD;GACA,MAAM,OAAO,MAAM,QAAQ,GAAG,KAAK,KAAK;AACxC,OAAI,MAAM;IACR,MAAM,YAAY,MAAM,OAAO,SAAS,MAAM,KAAK;AAEnD,WAAO,QAAQ,GAAG,MAAM,MAAM,UAAU;;;GAG5C,CACH"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const require_lib_utilities_source_file = require('./source-file.cjs');
|
|
2
|
+
const require_lib_utilities_file_header = require('./file-header.cjs');
|
|
3
|
+
const require_lib_utilities_format = require('./format.cjs');
|
|
4
|
+
const require_lib_utilities_source_map = require('./source-map.cjs');
|
|
5
|
+
const require_lib_utilities_write_file = require('./write-file.cjs');
|
|
6
|
+
|
|
7
|
+
exports.format = require_lib_utilities_format.format;
|
|
8
|
+
exports.formatFolder = require_lib_utilities_format.formatFolder;
|
|
9
|
+
exports.generateSourceMap = require_lib_utilities_source_map.generateSourceMap;
|
|
10
|
+
exports.getBaseFileHeader = require_lib_utilities_file_header.getBaseFileHeader;
|
|
11
|
+
exports.getFileHeader = require_lib_utilities_file_header.getFileHeader;
|
|
12
|
+
exports.getMagicString = require_lib_utilities_source_file.getMagicString;
|
|
13
|
+
exports.getSourceFile = require_lib_utilities_source_file.getSourceFile;
|
|
14
|
+
exports.getString = require_lib_utilities_source_file.getString;
|
|
15
|
+
exports.writeFile = require_lib_utilities_write_file.writeFile;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FileHeaderOptions, __ΩFileHeaderOptions, getBaseFileHeader, getFileHeader } from "./file-header.cjs";
|
|
2
|
+
import { format, formatFolder } from "./format.cjs";
|
|
3
|
+
import { getMagicString, getSourceFile, getString } from "./source-file.cjs";
|
|
4
|
+
import { generateSourceMap } from "./source-map.cjs";
|
|
5
|
+
import { writeFile } from "./write-file.cjs";
|
|
6
|
+
export { FileHeaderOptions, __ΩFileHeaderOptions, format, formatFolder, generateSourceMap, getBaseFileHeader, getFileHeader, getMagicString, getSourceFile, getString, writeFile };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FileHeaderOptions, __ΩFileHeaderOptions, getBaseFileHeader, getFileHeader } from "./file-header.mjs";
|
|
2
|
+
import { format, formatFolder } from "./format.mjs";
|
|
3
|
+
import { getMagicString, getSourceFile, getString } from "./source-file.mjs";
|
|
4
|
+
import { generateSourceMap } from "./source-map.mjs";
|
|
5
|
+
import { writeFile } from "./write-file.mjs";
|
|
6
|
+
export { FileHeaderOptions, __ΩFileHeaderOptions, format, formatFolder, generateSourceMap, getBaseFileHeader, getFileHeader, getMagicString, getSourceFile, getString, writeFile };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getMagicString, getSourceFile, getString } from "./source-file.mjs";
|
|
2
|
+
import { getBaseFileHeader, getFileHeader } from "./file-header.mjs";
|
|
3
|
+
import { format, formatFolder } from "./format.mjs";
|
|
4
|
+
import { generateSourceMap } from "./source-map.mjs";
|
|
5
|
+
import { writeFile } from "./write-file.mjs";
|
|
6
|
+
|
|
7
|
+
export { format, formatFolder, generateSourceMap, getBaseFileHeader, getFileHeader, getMagicString, getSourceFile, getString, writeFile };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
3
|
+
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
4
|
+
let __stryke_fs_read_file = require("@stryke/fs/read-file");
|
|
5
|
+
let magic_string = require("magic-string");
|
|
6
|
+
magic_string = require_rolldown_runtime.__toESM(magic_string);
|
|
7
|
+
|
|
8
|
+
//#region src/lib/utilities/source-file.ts
|
|
9
|
+
/**
|
|
10
|
+
* Get the string from the source.
|
|
11
|
+
*
|
|
12
|
+
* @param code - The source string or magic string.
|
|
13
|
+
* @returns The source string.
|
|
14
|
+
*/
|
|
15
|
+
function getString(code) {
|
|
16
|
+
if (!code) return "";
|
|
17
|
+
if ((0, __stryke_type_checks_is_string.isString)(code)) return code;
|
|
18
|
+
if ((0, __stryke_type_checks_is_set_object.isSetObject)(code) && "code" in code) return code.code;
|
|
19
|
+
return code.toString();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the magic string.
|
|
23
|
+
*
|
|
24
|
+
* @param code - The source string or magic string.
|
|
25
|
+
* @returns The magic string.
|
|
26
|
+
*/
|
|
27
|
+
function getMagicString(code) {
|
|
28
|
+
if ((0, __stryke_type_checks_is_string.isString)(code)) return new magic_string.default(code);
|
|
29
|
+
return code;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the source file.
|
|
33
|
+
*
|
|
34
|
+
* @param code - The source code.
|
|
35
|
+
* @param id - The name of the file.
|
|
36
|
+
* @returns The source file.
|
|
37
|
+
*/
|
|
38
|
+
function getSourceFile(code, id) {
|
|
39
|
+
return {
|
|
40
|
+
id,
|
|
41
|
+
code: getMagicString(code ?? (0, __stryke_fs_read_file.readFileIfExistingSync)(id)),
|
|
42
|
+
env: []
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.getMagicString = getMagicString;
|
|
48
|
+
exports.getSourceFile = getSourceFile;
|
|
49
|
+
exports.getString = getString;
|
|
50
|
+
//# sourceMappingURL=source-file.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-file.cjs","names":["MagicString"],"sources":["../../../src/lib/utilities/source-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { readFileIfExistingSync } from \"@stryke/fs/read-file\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport MagicString from \"magic-string\";\nimport { TransformResult } from \"unplugin\";\nimport { SourceFile } from \"../../types/context\";\n\n/**\n * Get the string from the source.\n *\n * @param code - The source string or magic string.\n * @returns The source string.\n */\nexport function getString(\n code: string | MagicString | TransformResult\n): string {\n if (!code) {\n return \"\";\n }\n\n if (isString(code)) {\n return code;\n }\n\n if (isSetObject(code) && \"code\" in code) {\n return code.code;\n }\n\n return code.toString();\n}\n\n/**\n * Get the magic string.\n *\n * @param code - The source string or magic string.\n * @returns The magic string.\n */\nexport function getMagicString(code: string | MagicString): MagicString {\n if (isString(code)) {\n return new MagicString(code);\n }\n\n return code;\n}\n\n/**\n * Get the source file.\n *\n * @param code - The source code.\n * @param id - The name of the file.\n * @returns The source file.\n */\nexport function getSourceFile(\n code: string | MagicString,\n id: string\n): SourceFile {\n const content = code ?? readFileIfExistingSync(id);\n\n return {\n id,\n code: getMagicString(content),\n env: []\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAgB,UACd,MACQ;AACR,KAAI,CAAC,KACH,QAAO;AAGT,kDAAa,KAAK,CAChB,QAAO;AAGT,yDAAgB,KAAK,IAAI,UAAU,KACjC,QAAO,KAAK;AAGd,QAAO,KAAK,UAAU;;;;;;;;AASxB,SAAgB,eAAe,MAAyC;AACtE,kDAAa,KAAK,CAChB,QAAO,IAAIA,qBAAY,KAAK;AAG9B,QAAO;;;;;;;;;AAUT,SAAgB,cACd,MACA,IACY;AAGZ,QAAO;EACL;EACA,MAAM,eAJQ,0DAA+B,GAAG,CAInB;EAC7B,KAAK,EAAE;EACR"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SourceFile } from "../../types/context.cjs";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
import { TransformResult } from "unplugin";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/utilities/source-file.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get the string from the source.
|
|
9
|
+
*
|
|
10
|
+
* @param code - The source string or magic string.
|
|
11
|
+
* @returns The source string.
|
|
12
|
+
*/
|
|
13
|
+
declare function getString(code: string | MagicString | TransformResult): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get the magic string.
|
|
16
|
+
*
|
|
17
|
+
* @param code - The source string or magic string.
|
|
18
|
+
* @returns The magic string.
|
|
19
|
+
*/
|
|
20
|
+
declare function getMagicString(code: string | MagicString): MagicString;
|
|
21
|
+
/**
|
|
22
|
+
* Get the source file.
|
|
23
|
+
*
|
|
24
|
+
* @param code - The source code.
|
|
25
|
+
* @param id - The name of the file.
|
|
26
|
+
* @returns The source file.
|
|
27
|
+
*/
|
|
28
|
+
declare function getSourceFile(code: string | MagicString, id: string): SourceFile;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { getMagicString, getSourceFile, getString };
|
|
31
|
+
//# sourceMappingURL=source-file.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-file.d.cts","names":[],"sources":["../../../src/lib/utilities/source-file.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA+BA;AAwBA;AAeA;;iBAvCgB,SAAA,gBACC,cAAc;;;;;;;iBAuBf,cAAA,gBAA8B,cAAc;;;;;;;;iBAe5C,aAAA,gBACC,0BAEd"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SourceFile } from "../../types/context.mjs";
|
|
2
|
+
import { TransformResult } from "unplugin";
|
|
3
|
+
import MagicString from "magic-string";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/utilities/source-file.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get the string from the source.
|
|
9
|
+
*
|
|
10
|
+
* @param code - The source string or magic string.
|
|
11
|
+
* @returns The source string.
|
|
12
|
+
*/
|
|
13
|
+
declare function getString(code: string | MagicString | TransformResult): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get the magic string.
|
|
16
|
+
*
|
|
17
|
+
* @param code - The source string or magic string.
|
|
18
|
+
* @returns The magic string.
|
|
19
|
+
*/
|
|
20
|
+
declare function getMagicString(code: string | MagicString): MagicString;
|
|
21
|
+
/**
|
|
22
|
+
* Get the source file.
|
|
23
|
+
*
|
|
24
|
+
* @param code - The source code.
|
|
25
|
+
* @param id - The name of the file.
|
|
26
|
+
* @returns The source file.
|
|
27
|
+
*/
|
|
28
|
+
declare function getSourceFile(code: string | MagicString, id: string): SourceFile;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { getMagicString, getSourceFile, getString };
|
|
31
|
+
//# sourceMappingURL=source-file.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-file.d.mts","names":[],"sources":["../../../src/lib/utilities/source-file.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA+BA;AAwBA;AAeA;;iBAvCgB,SAAA,gBACC,cAAc;;;;;;;iBAuBf,cAAA,gBAA8B,cAAc;;;;;;;;iBAe5C,aAAA,gBACC,0BAEd"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
2
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
3
|
+
import { readFileIfExistingSync } from "@stryke/fs/read-file";
|
|
4
|
+
import MagicString from "magic-string";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/utilities/source-file.ts
|
|
7
|
+
/**
|
|
8
|
+
* Get the string from the source.
|
|
9
|
+
*
|
|
10
|
+
* @param code - The source string or magic string.
|
|
11
|
+
* @returns The source string.
|
|
12
|
+
*/
|
|
13
|
+
function getString(code) {
|
|
14
|
+
if (!code) return "";
|
|
15
|
+
if (isString(code)) return code;
|
|
16
|
+
if (isSetObject(code) && "code" in code) return code.code;
|
|
17
|
+
return code.toString();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get the magic string.
|
|
21
|
+
*
|
|
22
|
+
* @param code - The source string or magic string.
|
|
23
|
+
* @returns The magic string.
|
|
24
|
+
*/
|
|
25
|
+
function getMagicString(code) {
|
|
26
|
+
if (isString(code)) return new MagicString(code);
|
|
27
|
+
return code;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the source file.
|
|
31
|
+
*
|
|
32
|
+
* @param code - The source code.
|
|
33
|
+
* @param id - The name of the file.
|
|
34
|
+
* @returns The source file.
|
|
35
|
+
*/
|
|
36
|
+
function getSourceFile(code, id) {
|
|
37
|
+
return {
|
|
38
|
+
id,
|
|
39
|
+
code: getMagicString(code ?? readFileIfExistingSync(id)),
|
|
40
|
+
env: []
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { getMagicString, getSourceFile, getString };
|
|
46
|
+
//# sourceMappingURL=source-file.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-file.mjs","names":[],"sources":["../../../src/lib/utilities/source-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { readFileIfExistingSync } from \"@stryke/fs/read-file\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport MagicString from \"magic-string\";\nimport { TransformResult } from \"unplugin\";\nimport { SourceFile } from \"../../types/context\";\n\n/**\n * Get the string from the source.\n *\n * @param code - The source string or magic string.\n * @returns The source string.\n */\nexport function getString(\n code: string | MagicString | TransformResult\n): string {\n if (!code) {\n return \"\";\n }\n\n if (isString(code)) {\n return code;\n }\n\n if (isSetObject(code) && \"code\" in code) {\n return code.code;\n }\n\n return code.toString();\n}\n\n/**\n * Get the magic string.\n *\n * @param code - The source string or magic string.\n * @returns The magic string.\n */\nexport function getMagicString(code: string | MagicString): MagicString {\n if (isString(code)) {\n return new MagicString(code);\n }\n\n return code;\n}\n\n/**\n * Get the source file.\n *\n * @param code - The source code.\n * @param id - The name of the file.\n * @returns The source file.\n */\nexport function getSourceFile(\n code: string | MagicString,\n id: string\n): SourceFile {\n const content = code ?? readFileIfExistingSync(id);\n\n return {\n id,\n code: getMagicString(content),\n env: []\n };\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,SAAgB,UACd,MACQ;AACR,KAAI,CAAC,KACH,QAAO;AAGT,KAAI,SAAS,KAAK,CAChB,QAAO;AAGT,KAAI,YAAY,KAAK,IAAI,UAAU,KACjC,QAAO,KAAK;AAGd,QAAO,KAAK,UAAU;;;;;;;;AASxB,SAAgB,eAAe,MAAyC;AACtE,KAAI,SAAS,KAAK,CAChB,QAAO,IAAI,YAAY,KAAK;AAG9B,QAAO;;;;;;;;;AAUT,SAAgB,cACd,MACA,IACY;AAGZ,QAAO;EACL;EACA,MAAM,eAJQ,QAAQ,uBAAuB,GAAG,CAInB;EAC7B,KAAK,EAAE;EACR"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let diff_match_patch = require("diff-match-patch");
|
|
3
|
+
diff_match_patch = require_rolldown_runtime.__toESM(diff_match_patch);
|
|
4
|
+
|
|
5
|
+
//#region src/lib/utilities/source-map.ts
|
|
6
|
+
const dmp = new diff_match_patch.default();
|
|
7
|
+
/**
|
|
8
|
+
* Generate code with source map.
|
|
9
|
+
*
|
|
10
|
+
* @param code - The source code.
|
|
11
|
+
* @param id - The file name.
|
|
12
|
+
* @param transpiled - The transpiled code.
|
|
13
|
+
* @returns The compiler result.
|
|
14
|
+
*/
|
|
15
|
+
function generateSourceMap(code, id, transpiled) {
|
|
16
|
+
if (!transpiled) return;
|
|
17
|
+
const diff = dmp.diff_main(code.toString(), transpiled);
|
|
18
|
+
dmp.diff_cleanupSemantic(diff);
|
|
19
|
+
let offset = 0;
|
|
20
|
+
for (let index = 0; index < diff.length; index++) if (diff[index]) {
|
|
21
|
+
const [type, text] = diff[index];
|
|
22
|
+
const textLength = text.length;
|
|
23
|
+
switch (type) {
|
|
24
|
+
case 0:
|
|
25
|
+
offset += textLength;
|
|
26
|
+
break;
|
|
27
|
+
case 1:
|
|
28
|
+
code.prependLeft(offset, text);
|
|
29
|
+
break;
|
|
30
|
+
case -1: {
|
|
31
|
+
const next = diff.at(index + 1);
|
|
32
|
+
if (next && next[0] === 1) {
|
|
33
|
+
const replaceText = next[1];
|
|
34
|
+
const firstNonWhitespaceIndexOfText = text.search(/\S/);
|
|
35
|
+
const offsetStart = offset + Math.max(firstNonWhitespaceIndexOfText, 0);
|
|
36
|
+
code.update(offsetStart, offset + textLength, replaceText);
|
|
37
|
+
index += 1;
|
|
38
|
+
} else code.remove(offset, offset + textLength);
|
|
39
|
+
offset += textLength;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!code.hasChanged()) return;
|
|
45
|
+
return {
|
|
46
|
+
code: code.toString(),
|
|
47
|
+
map: code.generateMap({
|
|
48
|
+
source: id,
|
|
49
|
+
file: `${id}.map`,
|
|
50
|
+
includeContent: true
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.generateSourceMap = generateSourceMap;
|
|
57
|
+
//# sourceMappingURL=source-map.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-map.cjs","names":["Diff"],"sources":["../../../src/lib/utilities/source-map.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport Diff from \"diff-match-patch\";\nimport type MagicString from \"magic-string\";\nimport type { TransformResult } from \"../../types/context\";\n\nconst dmp = new Diff();\n\n/**\n * Generate code with source map.\n *\n * @param code - The source code.\n * @param id - The file name.\n * @param transpiled - The transpiled code.\n * @returns The compiler result.\n */\nexport function generateSourceMap(\n code: MagicString,\n id: string,\n transpiled?: string\n): TransformResult | undefined {\n if (!transpiled) {\n return;\n }\n\n const diff = dmp.diff_main(code.toString(), transpiled);\n dmp.diff_cleanupSemantic(diff);\n\n let offset = 0;\n\n for (let index = 0; index < diff.length; index++) {\n if (diff[index]) {\n const [type, text] = diff[index]!;\n const textLength = text.length;\n\n switch (type) {\n case 0: {\n offset += textLength;\n break;\n }\n case 1: {\n code.prependLeft(offset, text);\n break;\n }\n case -1: {\n const next = diff.at(index + 1);\n\n if (next && next[0] === 1) {\n const replaceText = next[1];\n\n const firstNonWhitespaceIndexOfText = text.search(/\\S/);\n const offsetStart =\n offset + Math.max(firstNonWhitespaceIndexOfText, 0);\n\n code.update(offsetStart, offset + textLength, replaceText);\n index += 1;\n } else {\n code.remove(offset, offset + textLength);\n }\n\n offset += textLength;\n\n break;\n }\n }\n }\n }\n\n if (!code.hasChanged()) {\n return;\n }\n\n return {\n code: code.toString(),\n map: code.generateMap({\n source: id,\n file: `${id}.map`,\n includeContent: true\n })\n };\n}\n"],"mappings":";;;;;AAsBA,MAAM,MAAM,IAAIA,0BAAM;;;;;;;;;AAUtB,SAAgB,kBACd,MACA,IACA,YAC6B;AAC7B,KAAI,CAAC,WACH;CAGF,MAAM,OAAO,IAAI,UAAU,KAAK,UAAU,EAAE,WAAW;AACvD,KAAI,qBAAqB,KAAK;CAE9B,IAAI,SAAS;AAEb,MAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,QACvC,KAAI,KAAK,QAAQ;EACf,MAAM,CAAC,MAAM,QAAQ,KAAK;EAC1B,MAAM,aAAa,KAAK;AAExB,UAAQ,MAAR;GACE,KAAK;AACH,cAAU;AACV;GAEF,KAAK;AACH,SAAK,YAAY,QAAQ,KAAK;AAC9B;GAEF,KAAK,IAAI;IACP,MAAM,OAAO,KAAK,GAAG,QAAQ,EAAE;AAE/B,QAAI,QAAQ,KAAK,OAAO,GAAG;KACzB,MAAM,cAAc,KAAK;KAEzB,MAAM,gCAAgC,KAAK,OAAO,KAAK;KACvD,MAAM,cACJ,SAAS,KAAK,IAAI,+BAA+B,EAAE;AAErD,UAAK,OAAO,aAAa,SAAS,YAAY,YAAY;AAC1D,cAAS;UAET,MAAK,OAAO,QAAQ,SAAS,WAAW;AAG1C,cAAU;AAEV;;;;AAMR,KAAI,CAAC,KAAK,YAAY,CACpB;AAGF,QAAO;EACL,MAAM,KAAK,UAAU;EACrB,KAAK,KAAK,YAAY;GACpB,QAAQ;GACR,MAAM,GAAG,GAAG;GACZ,gBAAgB;GACjB,CAAC;EACH"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TransformResult } from "../../types/context.cjs";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/utilities/source-map.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generate code with source map.
|
|
8
|
+
*
|
|
9
|
+
* @param code - The source code.
|
|
10
|
+
* @param id - The file name.
|
|
11
|
+
* @param transpiled - The transpiled code.
|
|
12
|
+
* @returns The compiler result.
|
|
13
|
+
*/
|
|
14
|
+
declare function generateSourceMap(code: MagicString, id: string, transpiled?: string): TransformResult | undefined;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { generateSourceMap };
|
|
17
|
+
//# sourceMappingURL=source-map.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-map.d.cts","names":[],"sources":["../../../src/lib/utilities/source-map.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgCA;;;;;;iBAAgB,iBAAA,OACR,+CAGL"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TransformResult } from "../../types/context.mjs";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/utilities/source-map.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generate code with source map.
|
|
8
|
+
*
|
|
9
|
+
* @param code - The source code.
|
|
10
|
+
* @param id - The file name.
|
|
11
|
+
* @param transpiled - The transpiled code.
|
|
12
|
+
* @returns The compiler result.
|
|
13
|
+
*/
|
|
14
|
+
declare function generateSourceMap(code: MagicString, id: string, transpiled?: string): TransformResult | undefined;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { generateSourceMap };
|
|
17
|
+
//# sourceMappingURL=source-map.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-map.d.mts","names":[],"sources":["../../../src/lib/utilities/source-map.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgCA;;;;;;iBAAgB,iBAAA,OACR,+CAGL"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import Diff from "diff-match-patch";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/utilities/source-map.ts
|
|
4
|
+
const dmp = new Diff();
|
|
5
|
+
/**
|
|
6
|
+
* Generate code with source map.
|
|
7
|
+
*
|
|
8
|
+
* @param code - The source code.
|
|
9
|
+
* @param id - The file name.
|
|
10
|
+
* @param transpiled - The transpiled code.
|
|
11
|
+
* @returns The compiler result.
|
|
12
|
+
*/
|
|
13
|
+
function generateSourceMap(code, id, transpiled) {
|
|
14
|
+
if (!transpiled) return;
|
|
15
|
+
const diff = dmp.diff_main(code.toString(), transpiled);
|
|
16
|
+
dmp.diff_cleanupSemantic(diff);
|
|
17
|
+
let offset = 0;
|
|
18
|
+
for (let index = 0; index < diff.length; index++) if (diff[index]) {
|
|
19
|
+
const [type, text] = diff[index];
|
|
20
|
+
const textLength = text.length;
|
|
21
|
+
switch (type) {
|
|
22
|
+
case 0:
|
|
23
|
+
offset += textLength;
|
|
24
|
+
break;
|
|
25
|
+
case 1:
|
|
26
|
+
code.prependLeft(offset, text);
|
|
27
|
+
break;
|
|
28
|
+
case -1: {
|
|
29
|
+
const next = diff.at(index + 1);
|
|
30
|
+
if (next && next[0] === 1) {
|
|
31
|
+
const replaceText = next[1];
|
|
32
|
+
const firstNonWhitespaceIndexOfText = text.search(/\S/);
|
|
33
|
+
const offsetStart = offset + Math.max(firstNonWhitespaceIndexOfText, 0);
|
|
34
|
+
code.update(offsetStart, offset + textLength, replaceText);
|
|
35
|
+
index += 1;
|
|
36
|
+
} else code.remove(offset, offset + textLength);
|
|
37
|
+
offset += textLength;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!code.hasChanged()) return;
|
|
43
|
+
return {
|
|
44
|
+
code: code.toString(),
|
|
45
|
+
map: code.generateMap({
|
|
46
|
+
source: id,
|
|
47
|
+
file: `${id}.map`,
|
|
48
|
+
includeContent: true
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { generateSourceMap };
|
|
55
|
+
//# sourceMappingURL=source-map.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-map.mjs","names":[],"sources":["../../../src/lib/utilities/source-map.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport Diff from \"diff-match-patch\";\nimport type MagicString from \"magic-string\";\nimport type { TransformResult } from \"../../types/context\";\n\nconst dmp = new Diff();\n\n/**\n * Generate code with source map.\n *\n * @param code - The source code.\n * @param id - The file name.\n * @param transpiled - The transpiled code.\n * @returns The compiler result.\n */\nexport function generateSourceMap(\n code: MagicString,\n id: string,\n transpiled?: string\n): TransformResult | undefined {\n if (!transpiled) {\n return;\n }\n\n const diff = dmp.diff_main(code.toString(), transpiled);\n dmp.diff_cleanupSemantic(diff);\n\n let offset = 0;\n\n for (let index = 0; index < diff.length; index++) {\n if (diff[index]) {\n const [type, text] = diff[index]!;\n const textLength = text.length;\n\n switch (type) {\n case 0: {\n offset += textLength;\n break;\n }\n case 1: {\n code.prependLeft(offset, text);\n break;\n }\n case -1: {\n const next = diff.at(index + 1);\n\n if (next && next[0] === 1) {\n const replaceText = next[1];\n\n const firstNonWhitespaceIndexOfText = text.search(/\\S/);\n const offsetStart =\n offset + Math.max(firstNonWhitespaceIndexOfText, 0);\n\n code.update(offsetStart, offset + textLength, replaceText);\n index += 1;\n } else {\n code.remove(offset, offset + textLength);\n }\n\n offset += textLength;\n\n break;\n }\n }\n }\n }\n\n if (!code.hasChanged()) {\n return;\n }\n\n return {\n code: code.toString(),\n map: code.generateMap({\n source: id,\n file: `${id}.map`,\n includeContent: true\n })\n };\n}\n"],"mappings":";;;AAsBA,MAAM,MAAM,IAAI,MAAM;;;;;;;;;AAUtB,SAAgB,kBACd,MACA,IACA,YAC6B;AAC7B,KAAI,CAAC,WACH;CAGF,MAAM,OAAO,IAAI,UAAU,KAAK,UAAU,EAAE,WAAW;AACvD,KAAI,qBAAqB,KAAK;CAE9B,IAAI,SAAS;AAEb,MAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,QACvC,KAAI,KAAK,QAAQ;EACf,MAAM,CAAC,MAAM,QAAQ,KAAK;EAC1B,MAAM,aAAa,KAAK;AAExB,UAAQ,MAAR;GACE,KAAK;AACH,cAAU;AACV;GAEF,KAAK;AACH,SAAK,YAAY,QAAQ,KAAK;AAC9B;GAEF,KAAK,IAAI;IACP,MAAM,OAAO,KAAK,GAAG,QAAQ,EAAE;AAE/B,QAAI,QAAQ,KAAK,OAAO,GAAG;KACzB,MAAM,cAAc,KAAK;KAEzB,MAAM,gCAAgC,KAAK,OAAO,KAAK;KACvD,MAAM,cACJ,SAAS,KAAK,IAAI,+BAA+B,EAAE;AAErD,UAAK,OAAO,aAAa,SAAS,YAAY,YAAY;AAC1D,cAAS;UAET,MAAK,OAAO,QAAQ,SAAS,WAAW;AAG1C,cAAU;AAEV;;;;AAMR,KAAI,CAAC,KAAK,YAAY,CACpB;AAGF,QAAO;EACL,MAAM,KAAK,UAAU;EACrB,KAAK,KAAK,YAAY;GACpB,QAAQ;GACR,MAAM,GAAG,GAAG;GACZ,gBAAgB;GACjB,CAAC;EACH"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
|
|
3
|
+
let prettier = require("prettier");
|
|
4
|
+
let __stryke_fs_write_file = require("@stryke/fs/write-file");
|
|
5
|
+
|
|
6
|
+
//#region src/lib/utilities/write-file.ts
|
|
7
|
+
/**
|
|
8
|
+
* Writes and formats a file to the file system
|
|
9
|
+
*
|
|
10
|
+
* @param log - The logging function to use for logging errors
|
|
11
|
+
* @param filepath - The file path to write the file
|
|
12
|
+
* @param content - The content to write to the file
|
|
13
|
+
* @param skipFormat - Should the plugin skip formatting the `content` string with Prettier
|
|
14
|
+
*/
|
|
15
|
+
async function writeFile(log, filepath, content, skipFormat = false) {
|
|
16
|
+
try {
|
|
17
|
+
if (skipFormat) await (0, __stryke_fs_write_file.writeFile)(filepath, content);
|
|
18
|
+
else await (0, __stryke_fs_write_file.writeFile)(filepath, await (0, prettier.format)(content, {
|
|
19
|
+
...await (0, prettier.resolveConfig)(filepath) ?? {},
|
|
20
|
+
filepath
|
|
21
|
+
}) || "");
|
|
22
|
+
} catch (error) {
|
|
23
|
+
log(__storm_software_config_tools_types.LogLevelLabel.ERROR, `Failed to write file ${filepath} to disk \n${error?.message ? error.message : ""}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.writeFile = writeFile;
|
|
29
|
+
//# sourceMappingURL=write-file.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-file.cjs","names":["LogLevelLabel"],"sources":["../../../src/lib/utilities/write-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { writeFile as writeFileBase } from \"@stryke/fs/write-file\";\nimport { format, resolveConfig } from \"prettier\";\nimport type { LogFn } from \"../../types/config\";\n\n/**\n * Writes and formats a file to the file system\n *\n * @param log - The logging function to use for logging errors\n * @param filepath - The file path to write the file\n * @param content - The content to write to the file\n * @param skipFormat - Should the plugin skip formatting the `content` string with Prettier\n */\nexport async function writeFile(\n log: LogFn,\n filepath: string,\n content: string,\n skipFormat = false\n) {\n try {\n if (skipFormat) {\n await writeFileBase(filepath, content);\n } else {\n const config = await resolveConfig(filepath);\n const formatted = await format(content, {\n ...(config ?? {}),\n filepath\n });\n\n await writeFileBase(filepath, formatted || \"\");\n }\n } catch (error) {\n log(\n LogLevelLabel.ERROR,\n `Failed to write file ${filepath} to disk \\n${(error as Error)?.message ? (error as Error).message : \"\"}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,eAAsB,UACpB,KACA,UACA,SACA,aAAa,OACb;AACA,KAAI;AACF,MAAI,WACF,6CAAoB,UAAU,QAAQ;MAQtC,6CAAoB,UALF,2BAAa,SAAS;GACtC,GAFa,kCAAoB,SAAS,IAE5B,EAAE;GAChB;GACD,CAAC,IAEyC,GAAG;UAEzC,OAAO;AACd,MACEA,kDAAc,OACd,wBAAwB,SAAS,aAAc,OAAiB,UAAW,MAAgB,UAAU,KACtG"}
|