@cherepanov.pavel/shareable-config 2.0.4 → 2.0.6

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 CHANGED
@@ -1,15 +1,19 @@
1
- node_modules
2
- .idea
1
+ /node_modules/
2
+ /.idea/
3
3
  *.local
4
4
 
5
5
  # vue
6
- dist
6
+ /dist/
7
7
 
8
8
  # nuxt
9
- .output
10
- .nuxt
9
+ /.output/
10
+ /.nuxt/
11
11
 
12
12
  # quasar
13
- dist
14
- .quasar
15
- quasar.config.*.temporary.compiled*
13
+ /dist/
14
+ /.quasar/
15
+ quasar.config.*.temporary.compiled*
16
+
17
+ # astro
18
+ /dist/
19
+ /.astro/
package/.gitignore-get.js CHANGED
@@ -24,14 +24,13 @@ async function getGitignoreFileData(framework) {
24
24
 
25
25
  const [
26
26
  commonData,
27
- ] = srcFileData.split(/^#\s*\w+/mu);
27
+ ...sections
28
+ ] = srcFileData.split(/^# /mu);
28
29
 
29
30
  if (!framework) {
30
- return commonData.trim();
31
+ return commonData;
31
32
  }
32
33
 
33
- const sections = srcFileData.split(/^#\s*/mu)
34
- .slice(1);
35
34
  const matchedSection = sections.find((section) => {
36
35
  const [
37
36
  header,
@@ -39,7 +38,6 @@ async function getGitignoreFileData(framework) {
39
38
  return (
40
39
  header
41
40
  .trim()
42
- .toLowerCase()
43
41
  ) === framework;
44
42
  });
45
43
 
@@ -48,14 +46,19 @@ async function getGitignoreFileData(framework) {
48
46
  header,
49
47
  ...body
50
48
  ] = matchedSection.split("\n");
51
- return `${commonData.trim()}\n\n# ${header}\n${
52
- body
53
- .join("\n")
54
- .trim()
55
- }`.trim();
49
+ return (
50
+ // eslint-disable-next-line prefer-template
51
+ `${commonData.trim()}\n\n`
52
+ + `# ${header.trim()}\n`
53
+ + (
54
+ body
55
+ .join("\n")
56
+ .trim()
57
+ )
58
+ );
56
59
  }
57
- // Если не найдено — только общий контент
58
- return commonData.trim();
60
+ // Если не найдено, только общий контент
61
+ return commonData;
59
62
  }
60
63
 
61
64
  try {
package/README.md CHANGED
@@ -19,7 +19,7 @@ As you'll see further down in this README, the project is flexible and supports
19
19
  1. **Open the target project.**
20
20
  2. **Install the package:**
21
21
  ```sh
22
- npm i @cherepanov.pavel/shareable-config
22
+ npm i @cherepanov.pavel/shareable-config -D
23
23
  ```
24
24
 
25
25
  3. **Copy the config files:**
package/env.json5.set.js CHANGED
@@ -4,21 +4,19 @@ import {
4
4
  askFramework, askOptionsApi, askTypescript,
5
5
  } from "./modules/shared/utils/communication.js";
6
6
  import {
7
- getEnvs, setEnvs, envFileSrc,
7
+ getEnvs, setEnvs,
8
8
  } from "./modules/shared/utils/env.js";
9
- import {
10
- eslintFiles,
11
- } from "./modules/shared/utils/lint.js";
12
9
 
13
- let envs = {};
14
- try {
15
- envs = await getEnvs();
16
- } catch (err) {}
10
+ const envs = await (
11
+ getEnvs()
12
+ .catch(() => {
13
+ return {
14
+ };
15
+ })
16
+ );
17
17
 
18
18
  envs.isRepositoryUseTypescript = await askTypescript();
19
19
  envs.repositoryFramework = await askFramework();
20
20
  envs.isRepositoryUseOptionsApi = await askOptionsApi();
21
21
 
22
22
  await setEnvs(envs);
23
-
24
- await eslintFiles(envFileSrc);
@@ -0,0 +1,6 @@
1
+ export const supportedFrameworks = {
2
+ vue: "vue",
3
+ nuxt: "nuxt",
4
+ quasar: "quasar",
5
+ astro: "astro",
6
+ };
@@ -1,57 +1,45 @@
1
- import readline from "readline";
1
+ import {
2
+ cancel, isCancel, confirm, select,
3
+ } from "@clack/prompts";
4
+ import {
5
+ supportedFrameworks,
6
+ } from "../constants/index.js";
2
7
 
3
8
  export async function askTypescript() {
4
- return new Promise((resolve) => {
5
- const rl = readline.createInterface({
6
- input: process.stdin,
7
- output: process.stdout,
8
- });
9
- rl.question(
10
- "Do you use TypeScript? (Enter — no, any characters + Enter — yes):",
11
- (answer) => {
12
- rl.close();
13
- resolve(Boolean(
14
- answer,
15
- ));
16
- },
17
- );
18
- });
9
+ return unwrapPrompt(confirm({
10
+ message: "Do you use TypeScript?",
11
+ initialValue: true,
12
+ }));
19
13
  }
20
14
 
21
15
  export async function askFramework() {
22
- return new Promise((resolve) => {
23
- const rl = readline.createInterface({
24
- input: process.stdin,
25
- output: process.stdout,
26
- });
27
- rl.question(
28
- "Which framework do you use? (vue/nuxt/quasar, press Enter to copy only the framework-less): ",
29
- (answer) => {
30
- rl.close();
31
- resolve(
32
- answer
33
- .trim()
34
- .toLowerCase(),
35
- );
36
- },
37
- );
38
- });
16
+ return unwrapPrompt(select({
17
+ message: "Which framework do you use?",
18
+ options: (
19
+ Object.values(supportedFrameworks)
20
+ .map((value) => {
21
+ return {
22
+ value,
23
+ };
24
+ })
25
+ ),
26
+ }));
39
27
  }
40
28
 
41
29
  export async function askOptionsApi() {
42
- return new Promise((resolve) => {
43
- const rl = readline.createInterface({
44
- input: process.stdin,
45
- output: process.stdout,
46
- });
47
- rl.question(
48
- "Do you use the Vue options API? (Enter — no, any characters + Enter — yes):",
49
- (answer) => {
50
- rl.close();
51
- resolve(Boolean(
52
- answer,
53
- ));
54
- },
55
- );
56
- });
30
+ return unwrapPrompt(confirm({
31
+ message: "Do you use the Vue options API?",
32
+ initialValue: false,
33
+ }));
34
+ }
35
+
36
+ async function unwrapPrompt(maybeCancelPromise) {
37
+ const result = await maybeCancelPromise;
38
+
39
+ if (isCancel(result)) {
40
+ cancel("✖ Operation cancelled");
41
+ process.exit(0);
42
+ }
43
+
44
+ return result;
57
45
  }
@@ -17,7 +17,8 @@ export async function copyFile({
17
17
  } catch {
18
18
  await outputFile(destFile, `${getHeader("#")}${srcFileData}`);
19
19
  console.info(`${fileLabel} пересоздан`);
20
- return {};
20
+ return {
21
+ };
21
22
  }
22
23
 
23
24
  // Если файл есть — разбираем оба файла
@@ -28,7 +29,8 @@ export async function copyFile({
28
29
  if (!match) {
29
30
  await outputFile(destFile, `${getHeader("#")}${srcFileData}`);
30
31
  console.info(`${fileLabel} пересоздан`);
31
- return {};
32
+ return {
33
+ };
32
34
  }
33
35
 
34
36
  return {
@@ -6,8 +6,11 @@ import JSON5 from "json5";
6
6
  import {
7
7
  outputFile,
8
8
  } from "fs-extra";
9
+ import {
10
+ eslintFiles,
11
+ } from "./lint.js";
9
12
 
10
- export const envFileSrc = path.join(process.cwd(), "frontend-configs.env.json5");
13
+ const envFileSrc = path.join(process.cwd(), "frontend-configs.env.json5");
11
14
 
12
15
  export async function getEnvs() {
13
16
  const srcFileData = await readFile(envFileSrc, "utf8");
@@ -17,4 +20,5 @@ export async function getEnvs() {
17
20
 
18
21
  export async function setEnvs(envObj) {
19
22
  await outputFile(envFileSrc, JSON5.stringify(envObj, null, 2));
23
+ await eslintFiles(envFileSrc);
20
24
  }
@@ -9,7 +9,7 @@ const pkg = JSON.parse(await readFile(pkgJsonFileUrl, "utf8"));
9
9
  export function getHeader(comment = "//") {
10
10
  const lines = [
11
11
  "This file is generated with",
12
- `${pkg.repository?.url || ""}`,
12
+ String(pkg.repository?.url || ""),
13
13
  `Version: ${pkg.version || ""}`,
14
14
  "File may contain override sections, see project README for more details",
15
15
  ];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cherepanov.pavel/shareable-config",
3
3
  "description": "setup for new repositories",
4
- "version": "2.0.4",
4
+ "version": "2.0.6",
5
5
  "type": "module",
6
6
  "devEngines": {
7
7
  "packageManager": {
@@ -55,6 +55,7 @@
55
55
  "lint:css:fix": "npm run lint:css -- --fix"
56
56
  },
57
57
  "dependencies": {
58
+ "@clack/prompts": "^1.8.1",
58
59
  "@eslint/compat": "2.1.0",
59
60
  "@stylistic/eslint-plugin": "5.10.0",
60
61
  "@stylistic/stylelint-plugin": "5.2.1",