@cherepanov.pavel/shareable-config 2.0.7 → 2.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/.gitignore-get.js +1 -1
- package/.vscode/.code-snippets-get.js +7 -3
- package/.vscode/extensions.json +3 -2
- package/.vscode/extensions.json-get.js +9 -3
- package/.vscode/settings.json-get.js +7 -3
- package/modules/shared/utils/communication.js +13 -8
- package/modules/shared/utils/copy-with-override.js +7 -3
- package/modules/shared/utils/file.js +36 -18
- package/modules/shared/utils/messages.js +7 -0
- package/package.json +1 -1
package/.gitignore-get.js
CHANGED
|
@@ -22,6 +22,10 @@ import {
|
|
|
22
22
|
import {
|
|
23
23
|
eslintFiles,
|
|
24
24
|
} from "../modules/shared/utils/lint.js";
|
|
25
|
+
import {
|
|
26
|
+
getRecreatedMessage,
|
|
27
|
+
getUpdatedWithOverrideMessage,
|
|
28
|
+
} from "../modules/shared/utils/messages.js";
|
|
25
29
|
|
|
26
30
|
const fileNames = [
|
|
27
31
|
"vue.code-snippets",
|
|
@@ -59,11 +63,11 @@ try {
|
|
|
59
63
|
await outputFile(destFile, `${getHeader()}${result}`);
|
|
60
64
|
await eslintFiles(destFile);
|
|
61
65
|
if (isDestFileHaveOverride) {
|
|
62
|
-
console.info(
|
|
66
|
+
console.info(getUpdatedWithOverrideMessage(fileName));
|
|
63
67
|
} else {
|
|
64
|
-
console.info(
|
|
68
|
+
console.info(getRecreatedMessage(fileName));
|
|
65
69
|
}
|
|
66
70
|
});
|
|
67
71
|
} catch (err) {
|
|
68
|
-
console.error(
|
|
72
|
+
console.error(err.message);
|
|
69
73
|
}
|
package/.vscode/extensions.json
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
// typescript
|
|
8
8
|
"yoavbls.pretty-ts-errors",
|
|
9
9
|
"vue.volar",
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// astro
|
|
11
|
+
"astro-build.astro-vscode",
|
|
12
12
|
"savh.json5-kit",
|
|
13
|
+
"ms-azuretools.vscode-containers",
|
|
13
14
|
|
|
14
15
|
"editorconfig.editorconfig",
|
|
15
16
|
"dbaeumer.vscode-eslint",
|
|
@@ -22,6 +22,10 @@ import {
|
|
|
22
22
|
import {
|
|
23
23
|
eslintFiles,
|
|
24
24
|
} from "../modules/shared/utils/lint.js";
|
|
25
|
+
import {
|
|
26
|
+
getRecreatedMessage,
|
|
27
|
+
getUpdatedWithOverrideMessage,
|
|
28
|
+
} from "../modules/shared/utils/messages.js";
|
|
25
29
|
|
|
26
30
|
const fileName = "extensions.json";
|
|
27
31
|
const destFile = path.join(process.cwd(), `.vscode/${fileName}`);
|
|
@@ -29,11 +33,13 @@ const destFile = path.join(process.cwd(), `.vscode/${fileName}`);
|
|
|
29
33
|
try {
|
|
30
34
|
const {
|
|
31
35
|
isRepositoryUseTypescript: isTs,
|
|
36
|
+
repositoryFramework,
|
|
32
37
|
} = await getEnvs();
|
|
33
38
|
const srcFile = path.join(import.meta.dirname, fileName);
|
|
34
39
|
const srcFileData = await getSrcJSONFileData({
|
|
35
40
|
fileData: await readFile(srcFile, "utf8"),
|
|
36
41
|
isTs,
|
|
42
|
+
repositoryFramework,
|
|
37
43
|
});
|
|
38
44
|
let overrideContent;
|
|
39
45
|
try {
|
|
@@ -51,10 +57,10 @@ try {
|
|
|
51
57
|
await outputFile(destFile, `${getHeader()}${result}`);
|
|
52
58
|
await eslintFiles(destFile);
|
|
53
59
|
if (overrideContent) {
|
|
54
|
-
console.info(
|
|
60
|
+
console.info(getUpdatedWithOverrideMessage(fileName));
|
|
55
61
|
} else {
|
|
56
|
-
console.info(
|
|
62
|
+
console.info(getRecreatedMessage(fileName));
|
|
57
63
|
}
|
|
58
64
|
} catch (err) {
|
|
59
|
-
console.error(
|
|
65
|
+
console.error(err.message);
|
|
60
66
|
}
|
|
@@ -22,6 +22,10 @@ import {
|
|
|
22
22
|
import {
|
|
23
23
|
eslintFiles,
|
|
24
24
|
} from "../modules/shared/utils/lint.js";
|
|
25
|
+
import {
|
|
26
|
+
getRecreatedMessage,
|
|
27
|
+
getUpdatedWithOverrideMessage,
|
|
28
|
+
} from "../modules/shared/utils/messages.js";
|
|
25
29
|
|
|
26
30
|
const fileName = "settings.json";
|
|
27
31
|
const destFile = path.join(process.cwd(), `.vscode/${fileName}`);
|
|
@@ -51,10 +55,10 @@ try {
|
|
|
51
55
|
await outputFile(destFile, `${getHeader()}${result}`);
|
|
52
56
|
await eslintFiles(destFile);
|
|
53
57
|
if (overrideContent) {
|
|
54
|
-
console.info(
|
|
58
|
+
console.info(getUpdatedWithOverrideMessage(fileName));
|
|
55
59
|
} else {
|
|
56
|
-
console.info(
|
|
60
|
+
console.info(getRecreatedMessage(fileName));
|
|
57
61
|
}
|
|
58
62
|
} catch (err) {
|
|
59
|
-
console.error(
|
|
63
|
+
console.error(err.message);
|
|
60
64
|
}
|
|
@@ -13,16 +13,21 @@ export async function askTypescript() {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export async function askFramework() {
|
|
16
|
+
const options = (
|
|
17
|
+
Object.values(supportedFrameworks)
|
|
18
|
+
.map((value) => {
|
|
19
|
+
return {
|
|
20
|
+
value,
|
|
21
|
+
};
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
options.push({
|
|
25
|
+
value: "",
|
|
26
|
+
label: "None of the listed ones (copy only the framework-less)",
|
|
27
|
+
});
|
|
16
28
|
return unwrapPrompt(select({
|
|
17
29
|
message: "Which framework do you use?",
|
|
18
|
-
options
|
|
19
|
-
Object.values(supportedFrameworks)
|
|
20
|
-
.map((value) => {
|
|
21
|
-
return {
|
|
22
|
-
value,
|
|
23
|
-
};
|
|
24
|
-
})
|
|
25
|
-
),
|
|
30
|
+
options,
|
|
26
31
|
}));
|
|
27
32
|
}
|
|
28
33
|
|
|
@@ -7,6 +7,10 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
outputFile,
|
|
9
9
|
} from "fs-extra";
|
|
10
|
+
import {
|
|
11
|
+
getRecreatedMessage,
|
|
12
|
+
getUpdatedWithOverrideMessage,
|
|
13
|
+
} from "./messages.js";
|
|
10
14
|
|
|
11
15
|
export async function copyFile({
|
|
12
16
|
destFile, srcFileData, fileLabel,
|
|
@@ -16,7 +20,7 @@ export async function copyFile({
|
|
|
16
20
|
await readFile(destFile, "utf8");
|
|
17
21
|
} catch {
|
|
18
22
|
await outputFile(destFile, `${getHeader("#")}${srcFileData}`);
|
|
19
|
-
console.info(
|
|
23
|
+
console.info(getRecreatedMessage(fileLabel));
|
|
20
24
|
return {
|
|
21
25
|
};
|
|
22
26
|
}
|
|
@@ -28,7 +32,7 @@ export async function copyFile({
|
|
|
28
32
|
const match = destFileData.match(overrideRegex);
|
|
29
33
|
if (!match) {
|
|
30
34
|
await outputFile(destFile, `${getHeader("#")}${srcFileData}`);
|
|
31
|
-
console.info(
|
|
35
|
+
console.info(getRecreatedMessage(fileLabel));
|
|
32
36
|
return {
|
|
33
37
|
};
|
|
34
38
|
}
|
|
@@ -59,7 +63,7 @@ export async function copyWithOverride({
|
|
|
59
63
|
const newContent = `${srcFileData.trimEnd()}\n\n${preserved.trimStart()}`;
|
|
60
64
|
|
|
61
65
|
await outputFile(destFile, `${getHeader("#")}${newContent}`);
|
|
62
|
-
console.info(
|
|
66
|
+
console.info(getUpdatedWithOverrideMessage(fileLabel));
|
|
63
67
|
} catch (err) {
|
|
64
68
|
console.error(`Ошибка копирования ${fileLabel}:`, err.message);
|
|
65
69
|
}
|
|
@@ -1,45 +1,63 @@
|
|
|
1
1
|
import JSON5 from "json5";
|
|
2
|
+
import {
|
|
3
|
+
supportedFrameworks,
|
|
4
|
+
} from "../constants";
|
|
2
5
|
|
|
3
6
|
export async function getSrcJSONFileData({
|
|
4
7
|
fileData,
|
|
5
8
|
isTs = false,
|
|
9
|
+
repositoryFramework = "",
|
|
6
10
|
removeDuplicateKeys = false,
|
|
7
11
|
}) {
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
const frameworks = Object.values(supportedFrameworks);
|
|
13
|
+
const markers = [
|
|
14
|
+
...frameworks,
|
|
15
|
+
"typescript",
|
|
16
|
+
];
|
|
17
|
+
const isFileHaveMarker = markers.some((marker) => {
|
|
18
|
+
return fileData.includes(`// ${marker}`);
|
|
19
|
+
});
|
|
20
|
+
// If there are no typescript and framework comments,
|
|
21
|
+
// there are no unnecessary problems, we return the source file.
|
|
22
|
+
if (!isFileHaveMarker) {
|
|
10
23
|
return fileData;
|
|
11
24
|
}
|
|
12
25
|
|
|
13
26
|
const lines = fileData.split("\n");
|
|
14
|
-
const result = [
|
|
27
|
+
const result = [
|
|
28
|
+
];
|
|
15
29
|
let nextLineIsTypescript = false;
|
|
16
30
|
let nextLineIsTypescriptMultiline = false;
|
|
31
|
+
let nextLineFramework;
|
|
17
32
|
|
|
18
33
|
lines.forEach((line) => {
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
// если несколько следующих строк typescript only
|
|
34
|
+
const isLineWithTsComment = line.includes("// typescript");
|
|
35
|
+
if (isLineWithTsComment) {
|
|
22
36
|
if (line.includes("// typescript multiline")) {
|
|
23
|
-
// проверяем это конец multiline typescript комментария, или начало, и в соответствии
|
|
24
|
-
// с этим ставим флаг
|
|
25
37
|
nextLineIsTypescriptMultiline = !(line.includes("// typescript multiline end"));
|
|
26
38
|
} else {
|
|
27
|
-
nextLineIsTypescript = true;
|
|
39
|
+
nextLineIsTypescript = true;
|
|
28
40
|
}
|
|
29
|
-
// флаги проставлены, с этой строкой больше нечего делать, выходим
|
|
30
41
|
return;
|
|
31
42
|
}
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
44
|
+
const lineFramework = frameworks.find((framework) => {
|
|
45
|
+
return line.includes(`// ${framework}`);
|
|
46
|
+
});
|
|
47
|
+
if (lineFramework) {
|
|
48
|
+
nextLineFramework = lineFramework;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const isTypescriptAllowed = isTs || (!nextLineIsTypescript && !nextLineIsTypescriptMultiline);
|
|
53
|
+
const isFrameworkAllowed = repositoryFramework === nextLineFramework || !nextLineFramework;
|
|
54
|
+
|
|
55
|
+
if (isTypescriptAllowed && isFrameworkAllowed) {
|
|
41
56
|
result.push(line);
|
|
42
57
|
}
|
|
58
|
+
|
|
59
|
+
nextLineIsTypescript = false;
|
|
60
|
+
nextLineFramework = undefined;
|
|
43
61
|
});
|
|
44
62
|
|
|
45
63
|
const stringResult = result.join("\n");
|