@form8ion/git 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -123,7 +123,7 @@ $ npm test
123
123
 
124
124
  [license-link]: LICENSE
125
125
 
126
- [license-badge]: https://img.shields.io/github/license/form8ion/git.svg
126
+ [license-badge]: https://img.shields.io/github/license/form8ion/git.svg?logo=opensourceinitiative
127
127
 
128
128
  [npm-link]: https://www.npmjs.com/package/@form8ion/git
129
129
 
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import simpleGit from 'simple-git';
2
2
  import { info } from '@travi/cli-messages';
3
- import { write, read } from '@form8ion/ignore-file';
3
+ import { write, exists, read } from '@form8ion/ignore-file';
4
4
  import '@form8ion/core';
5
5
  import { promises } from 'node:fs';
6
6
 
@@ -8,8 +8,12 @@ function writeGitIgnore({projectRoot, ignores}) {
8
8
  return write({projectRoot, name: 'git', ignores});
9
9
  }
10
10
 
11
- function scaffoldIgnore ({projectRoot, files = [], directories = []}) {
12
- return writeGitIgnore({projectRoot, ignores: [...directories, ...files]});
11
+ function scaffoldIgnore ({projectRoot}) {
12
+ return writeGitIgnore({projectRoot, ignores: []});
13
+ }
14
+
15
+ function gitignoreExists({projectRoot} = {}) {
16
+ return exists({projectRoot, name: 'git'});
13
17
  }
14
18
 
15
19
  function readGitIgnore({projectRoot}) {
@@ -17,7 +21,11 @@ function readGitIgnore({projectRoot}) {
17
21
  }
18
22
 
19
23
  async function appendToIgnoreFile({projectRoot, ignores}) {
20
- const existingIgnores = await readGitIgnore({projectRoot});
24
+ let existingIgnores = [];
25
+
26
+ if (await gitignoreExists({projectRoot})) {
27
+ existingIgnores = await readGitIgnore({projectRoot});
28
+ }
21
29
 
22
30
  await writeGitIgnore({projectRoot, ignores: [...existingIgnores, ...ignores]});
23
31
  }
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/ignore/writer.js","../src/ignore/scaffolder.js","../src/ignore/reader.js","../src/ignore/appender.js","../src/ignore/lifter.js","../src/scaffolder.js","../src/tester.js","../src/attributes/scaffolder.js","../src/lifter.js"],"sourcesContent":["import {write} from '@form8ion/ignore-file';\n\nexport default function writeGitIgnore({projectRoot, ignores}) {\n return write({projectRoot, name: 'git', ignores});\n}\n","import write from './writer.js';\n\nexport default function ({projectRoot, files = [], directories = []}) {\n return write({projectRoot, ignores: [...directories, ...files]});\n}\n","import {read} from '@form8ion/ignore-file';\n\nexport default function readGitIgnore({projectRoot}) {\n return read({projectRoot, name: 'git'});\n}\n","import readGitIgnore from './reader.js';\nimport writeGitIgnore from './writer.js';\n\nexport default async function appendToIgnoreFile({projectRoot, ignores}) {\n const existingIgnores = await readGitIgnore({projectRoot});\n\n await writeGitIgnore({projectRoot, ignores: [...existingIgnores, ...ignores]});\n}\n","import {info} from '@travi/cli-messages';\n\nimport appendIgnores from './appender.js';\n\nexport default async function ({projectRoot, results: {vcsIgnore}}) {\n if (vcsIgnore) {\n info('Updating files and directories to be ignored from version control', {level: 'secondary'});\n\n const {directories = [], files = []} = vcsIgnore;\n\n await appendIgnores({projectRoot, ignores: [...directories, ...files]});\n }\n\n return {};\n}\n","import simpleGit from 'simple-git';\nimport {info} from '@travi/cli-messages';\n\nimport {scaffold as scaffoldIgnore} from './ignore/index.js';\n\nexport default async function ({projectRoot}) {\n info('Initializing Git Repository');\n\n const git = simpleGit({baseDir: projectRoot});\n\n await Promise.all([\n scaffoldIgnore({projectRoot}),\n git.init()\n ]);\n\n return {};\n}\n","import simpleGit from 'simple-git';\n\nexport default function ({projectRoot}) {\n const git = simpleGit({baseDir: projectRoot});\n\n return git.checkIsRepo('root');\n}\n","import {promises as fs} from 'node:fs';\n\nexport default function ({projectRoot}) {\n return fs.writeFile(`${projectRoot}/.gitattributes`, '* text=auto');\n}\n","import {scaffold as scaffoldAttributes} from './attributes/index.js';\nimport {lift as liftIgnore} from './ignore/index.js';\n\nexport default async function ({projectRoot, results}) {\n await Promise.all([\n scaffoldAttributes({projectRoot}),\n liftIgnore({projectRoot, results})\n ]);\n\n return {};\n}\n"],"names":["write","appendIgnores","fs"],"mappings":";;;;;;AAEe,SAAS,cAAc,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE;AAC/D,EAAE,OAAO,KAAK,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACnD;;ACFe,uBAAQ,EAAE,CAAC,WAAW,EAAE,KAAK,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,CAAC,EAAE;AACtE,EAAE,OAAOA,cAAK,CAAC,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC,GAAG,WAAW,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;AAClE;;ACFe,SAAS,aAAa,CAAC,CAAC,WAAW,CAAC,EAAE;AACrD,EAAE,OAAO,IAAI,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACzC;;ACDe,eAAe,kBAAkB,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE;AACzE,EAAE,MAAM,eAAe,GAAG,MAAM,aAAa,CAAC,CAAC,WAAW,CAAC,CAAC;;AAE5D,EAAE,MAAM,cAAc,CAAC,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC,GAAG,eAAe,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;AAChF;;ACHe,yBAAc,EAAE,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE;AACpE,EAAE,IAAI,SAAS,EAAE;AACjB,IAAI,IAAI,CAAC,mEAAmE,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;;AAEnG,IAAI,MAAM,CAAC,WAAW,GAAG,EAAE,EAAE,KAAK,GAAG,EAAE,CAAC,GAAG,SAAS;;AAEpD,IAAI,MAAMC,kBAAa,CAAC,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC,GAAG,WAAW,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;AAC3E;;AAEA,EAAE,OAAO,EAAE;AACX;;ACTe,yBAAc,EAAE,CAAC,WAAW,CAAC,EAAE;AAC9C,EAAE,IAAI,CAAC,6BAA6B,CAAC;;AAErC,EAAE,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;;AAE/C,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC;AACpB,IAAI,cAAc,CAAC,CAAC,WAAW,CAAC,CAAC;AACjC,IAAI,GAAG,CAAC,IAAI;AACZ,GAAG,CAAC;;AAEJ,EAAE,OAAO,EAAE;AACX;;ACde,eAAQ,EAAE,CAAC,WAAW,CAAC,EAAE;AACxC,EAAE,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;;AAE/C,EAAE,OAAO,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC;AAChC;;ACJe,2BAAQ,EAAE,CAAC,WAAW,CAAC,EAAE;AACxC,EAAE,OAAOC,QAAE,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC;AACrE;;ACDe,qBAAc,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE;AACvD,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC;AACpB,IAAI,kBAAkB,CAAC,CAAC,WAAW,CAAC,CAAC;AACrC,IAAI,UAAU,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC;AACrC,GAAG,CAAC;;AAEJ,EAAE,OAAO,EAAE;AACX;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/ignore/writer.js","../src/ignore/scaffolder.js","../src/ignore/existence-checker.js","../src/ignore/reader.js","../src/ignore/appender.js","../src/ignore/lifter.js","../src/scaffolder.js","../src/tester.js","../src/attributes/scaffolder.js","../src/lifter.js"],"sourcesContent":["import {write} from '@form8ion/ignore-file';\n\nexport default function writeGitIgnore({projectRoot, ignores}) {\n return write({projectRoot, name: 'git', ignores});\n}\n","import write from './writer.js';\n\nexport default function ({projectRoot}) {\n return write({projectRoot, ignores: []});\n}\n","import {exists} from '@form8ion/ignore-file';\n\nexport default function gitignoreExists({projectRoot} = {}) {\n return exists({projectRoot, name: 'git'});\n}\n","import {read} from '@form8ion/ignore-file';\n\nexport default function readGitIgnore({projectRoot}) {\n return read({projectRoot, name: 'git'});\n}\n","import gitignoreExists from './existence-checker.js';\nimport readGitIgnore from './reader.js';\nimport writeGitIgnore from './writer.js';\n\nexport default async function appendToIgnoreFile({projectRoot, ignores}) {\n let existingIgnores = [];\n\n if (await gitignoreExists({projectRoot})) {\n existingIgnores = await readGitIgnore({projectRoot});\n }\n\n await writeGitIgnore({projectRoot, ignores: [...existingIgnores, ...ignores]});\n}\n","import {info} from '@travi/cli-messages';\n\nimport appendIgnores from './appender.js';\n\nexport default async function ({projectRoot, results: {vcsIgnore}}) {\n if (vcsIgnore) {\n info('Updating files and directories to be ignored from version control', {level: 'secondary'});\n\n const {directories = [], files = []} = vcsIgnore;\n\n await appendIgnores({projectRoot, ignores: [...directories, ...files]});\n }\n\n return {};\n}\n","import simpleGit from 'simple-git';\nimport {info} from '@travi/cli-messages';\n\nimport {scaffold as scaffoldIgnore} from './ignore/index.js';\n\nexport default async function ({projectRoot}) {\n info('Initializing Git Repository');\n\n const git = simpleGit({baseDir: projectRoot});\n\n await Promise.all([\n scaffoldIgnore({projectRoot}),\n git.init()\n ]);\n\n return {};\n}\n","import simpleGit from 'simple-git';\n\nexport default function ({projectRoot}) {\n const git = simpleGit({baseDir: projectRoot});\n\n return git.checkIsRepo('root');\n}\n","import {promises as fs} from 'node:fs';\n\nexport default function ({projectRoot}) {\n return fs.writeFile(`${projectRoot}/.gitattributes`, '* text=auto');\n}\n","import {scaffold as scaffoldAttributes} from './attributes/index.js';\nimport {lift as liftIgnore} from './ignore/index.js';\n\nexport default async function ({projectRoot, results}) {\n await Promise.all([\n sca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form8ion plugin for managing projects versioned with git",
4
4
  "license": "MIT",
5
- "version": "2.1.0",
5
+ "version": "2.2.0",
6
6
  "type": "module",
7
7
  "engines": {
8
8
  "node": "^18.19.0 || ^20.9.0 || >=22.11.0"
@@ -46,13 +46,14 @@
46
46
  },
47
47
  "files": [
48
48
  "example.js",
49
- "lib/"
49
+ "lib/",
50
+ "src/"
50
51
  ],
51
52
  "publishConfig": {
52
53
  "access": "public",
53
54
  "provenance": true
54
55
  },
55
- "packageManager": "npm@11.0.0",
56
+ "packageManager": "npm@11.12.1+sha512.cdca14b85d647b3192028d02aadbe82d75f79a446aceea9874be98e6d768f20ebd3555770a48d0e9906106007877bbc690f715e9372f2e2dc644a3c3157fb14c",
56
57
  "dependencies": {
57
58
  "@form8ion/core": "^4.3.0",
58
59
  "@form8ion/ignore-file": "^1.0.0",
@@ -60,31 +61,31 @@
60
61
  "simple-git": "^3.25.0"
61
62
  },
62
63
  "devDependencies": {
63
- "@cucumber/cucumber": "11.2.0",
64
- "@form8ion/commitlint-config": "2.0.3",
65
- "@form8ion/eslint-config": "7.0.12",
64
+ "@cucumber/cucumber": "11.3.0",
65
+ "@form8ion/commitlint-config": "2.0.11",
66
+ "@form8ion/eslint-config": "7.0.14",
66
67
  "@form8ion/eslint-config-cucumber": "1.4.1",
67
- "@form8ion/remark-lint-preset": "6.0.6",
68
- "@travi/any": "3.1.2",
69
- "c8": "10.1.3",
70
- "chai": "5.1.2",
71
- "cross-env": "7.0.3",
68
+ "@form8ion/remark-lint-preset": "6.0.7",
69
+ "@travi/any": "3.3.0",
70
+ "c8": "11.0.0",
71
+ "chai": "6.2.2",
72
+ "cross-env": "10.1.0",
72
73
  "cz-conventional-changelog": "3.3.0",
73
74
  "gherkin-lint": "4.2.4",
74
75
  "husky": "9.1.7",
75
- "jest-when": "3.7.0",
76
- "lockfile-lint": "4.14.0",
77
- "ls-engines": "0.9.3",
78
- "mock-fs": "5.4.1",
79
- "npm-run-all2": "7.0.2",
80
- "publint": "0.3.2",
76
+ "lockfile-lint": "5.0.0",
77
+ "ls-engines": "0.9.4",
78
+ "mock-fs": "5.5.0",
79
+ "npm-run-all2": "8.0.4",
80
+ "publint": "0.3.18",
81
81
  "remark-cli": "12.0.1",
82
82
  "remark-toc": "9.0.0",
83
83
  "remark-usage": "11.0.1",
84
- "rimraf": "6.0.1",
85
- "rollup": "4.32.1",
84
+ "rimraf": "6.1.3",
85
+ "rollup": "4.60.1",
86
86
  "rollup-plugin-auto-external": "2.0.0",
87
87
  "testdouble": "3.20.2",
88
- "vitest": "3.0.5"
88
+ "vitest": "4.1.4",
89
+ "vitest-when": "0.10.0"
89
90
  }
90
91
  }
@@ -0,0 +1 @@
1
+ export {default as scaffold} from './scaffolder.js';
@@ -0,0 +1,5 @@
1
+ import {promises as fs} from 'node:fs';
2
+
3
+ export default function ({projectRoot}) {
4
+ return fs.writeFile(`${projectRoot}/.gitattributes`, '* text=auto');
5
+ }
@@ -0,0 +1,18 @@
1
+ import {promises as fs} from 'node:fs';
2
+
3
+ import {describe, expect, it, vi} from 'vitest';
4
+ import any from '@travi/any';
5
+
6
+ import scaffoldAttributes from './scaffolder.js';
7
+
8
+ vi.mock('node:fs');
9
+
10
+ describe('attributes scaffolder', () => {
11
+ it('should create the attributes file', async () => {
12
+ const projectRoot = any.string();
13
+
14
+ await scaffoldAttributes({projectRoot});
15
+
16
+ expect(fs.writeFile).toHaveBeenCalledWith(`${projectRoot}/.gitattributes`, '* text=auto');
17
+ });
18
+ });
@@ -0,0 +1,13 @@
1
+ import gitignoreExists from './existence-checker.js';
2
+ import readGitIgnore from './reader.js';
3
+ import writeGitIgnore from './writer.js';
4
+
5
+ export default async function appendToIgnoreFile({projectRoot, ignores}) {
6
+ let existingIgnores = [];
7
+
8
+ if (await gitignoreExists({projectRoot})) {
9
+ existingIgnores = await readGitIgnore({projectRoot});
10
+ }
11
+
12
+ await writeGitIgnore({projectRoot, ignores: [...existingIgnores, ...ignores]});
13
+ }
@@ -0,0 +1,36 @@
1
+ import {describe, it, vi, expect} from 'vitest';
2
+ // eslint-disable-next-line import/no-unresolved
3
+ import {when} from 'vitest-when';
4
+ import any from '@travi/any';
5
+
6
+ import gitignoreExists from './existence-checker.js';
7
+ import read from './reader.js';
8
+ import write from './writer.js';
9
+ import appendToIgnoreFile from './appender.js';
10
+
11
+ vi.mock('./existence-checker.js');
12
+ vi.mock('./reader.js');
13
+ vi.mock('./writer.js');
14
+
15
+ describe('gitignore appender', () => {
16
+ const projectRoot = any.string();
17
+ const ignores = any.listOf(any.string);
18
+
19
+ it('should add the provided ignores to the existing gitignore', async () => {
20
+ const existingIgnores = any.listOf(any.string);
21
+ when(gitignoreExists).calledWith({projectRoot}).thenResolve(true);
22
+ when(read).calledWith({projectRoot}).thenResolve(existingIgnores);
23
+
24
+ await appendToIgnoreFile({projectRoot, ignores});
25
+
26
+ expect(write).toHaveBeenCalledWith({projectRoot, ignores: [...existingIgnores, ...ignores]});
27
+ });
28
+
29
+ it('should write only the provided ignores when the ignore file does not yet exist', async () => {
30
+ when(gitignoreExists).calledWith({projectRoot}).thenResolve(false);
31
+
32
+ await appendToIgnoreFile({projectRoot, ignores});
33
+
34
+ expect(write).toHaveBeenCalledWith({projectRoot, ignores});
35
+ });
36
+ });
@@ -0,0 +1,5 @@
1
+ import {exists} from '@form8ion/ignore-file';
2
+
3
+ export default function gitignoreExists({projectRoot} = {}) {
4
+ return exists({projectRoot, name: 'git'});
5
+ }
@@ -0,0 +1,20 @@
1
+ import {exists} from '@form8ion/ignore-file';
2
+
3
+ import {it, describe, vi, expect} from 'vitest';
4
+ import any from '@travi/any';
5
+ // eslint-disable-next-line import/no-unresolved
6
+ import {when} from 'vitest-when';
7
+
8
+ import gitignoreExists from './existence-checker.js';
9
+
10
+ vi.mock('@form8ion/ignore-file');
11
+
12
+ describe('gitignore existence checker', () => {
13
+ it('should check for existence of the gitignore', async () => {
14
+ const projectRoot = any.string();
15
+ const fileExists = any.boolean();
16
+ when(exists).calledWith({projectRoot, name: 'git'}).thenResolve(fileExists);
17
+
18
+ expect(await gitignoreExists({projectRoot})).toBe(fileExists);
19
+ });
20
+ });
@@ -0,0 +1,3 @@
1
+ export {default as scaffold} from './scaffolder.js';
2
+ export {default as test} from './tester.js';
3
+ export {default as lift} from './lifter.js';
@@ -0,0 +1,15 @@
1
+ import {info} from '@travi/cli-messages';
2
+
3
+ import appendIgnores from './appender.js';
4
+
5
+ export default async function ({projectRoot, results: {vcsIgnore}}) {
6
+ if (vcsIgnore) {
7
+ info('Updating files and directories to be ignored from version control', {level: 'secondary'});
8
+
9
+ const {directories = [], files = []} = vcsIgnore;
10
+
11
+ await appendIgnores({projectRoot, ignores: [...directories, ...files]});
12
+ }
13
+
14
+ return {};
15
+ }
@@ -0,0 +1,41 @@
1
+ import {describe, expect, it, vi} from 'vitest';
2
+ import any from '@travi/any';
3
+
4
+ import appendToIgnores from './appender.js';
5
+ import liftGitIgnore from './lifter.js';
6
+
7
+ vi.mock('./appender.js');
8
+
9
+ describe('gitignore lifter', () => {
10
+ const projectRoot = any.string();
11
+ const ignoredDirectories = any.listOf(any.word);
12
+ const ignoredFiles = any.listOf(any.word);
13
+
14
+ it('should append the provided ignores to the gitignore file', async () => {
15
+ expect(
16
+ await liftGitIgnore({projectRoot, results: {vcsIgnore: {directories: ignoredDirectories, files: ignoredFiles}}})
17
+ ).toEqual({});
18
+
19
+ expect(appendToIgnores).toHaveBeenCalledWith({projectRoot, ignores: [...ignoredDirectories, ...ignoredFiles]});
20
+ });
21
+
22
+ it('should append provided directories to ignore', async () => {
23
+ expect(await liftGitIgnore({projectRoot, results: {vcsIgnore: {directories: ignoredDirectories}}}))
24
+ .toEqual({});
25
+
26
+ expect(appendToIgnores).toHaveBeenCalledWith({projectRoot, ignores: ignoredDirectories});
27
+ });
28
+
29
+ it('should append provided directories to ignore', async () => {
30
+ expect(await liftGitIgnore({projectRoot, results: {vcsIgnore: {files: ignoredFiles}}}))
31
+ .toEqual({});
32
+
33
+ expect(appendToIgnores).toHaveBeenCalledWith({projectRoot, ignores: ignoredFiles});
34
+ });
35
+
36
+ it('should not update the ignore file if no additional ignores are provided', async () => {
37
+ expect(await liftGitIgnore({projectRoot, results: {}})).toEqual({});
38
+
39
+ expect(appendToIgnores).not.toHaveBeenCalledWith({projectRoot});
40
+ });
41
+ });
@@ -0,0 +1,5 @@
1
+ import {read} from '@form8ion/ignore-file';
2
+
3
+ export default function readGitIgnore({projectRoot}) {
4
+ return read({projectRoot, name: 'git'});
5
+ }
@@ -0,0 +1,20 @@
1
+ import {read} from '@form8ion/ignore-file';
2
+
3
+ import {it, describe, vi, expect} from 'vitest';
4
+ import any from '@travi/any';
5
+ // eslint-disable-next-line import/no-unresolved
6
+ import {when} from 'vitest-when';
7
+
8
+ import readGitIgnore from './reader.js';
9
+
10
+ vi.mock('@form8ion/ignore-file');
11
+
12
+ describe('gitignore reader', () => {
13
+ it('should read the contents of the .gitignore file', async () => {
14
+ const projectRoot = any.string();
15
+ const existingIgnores = any.listOf(any.word);
16
+ when(read).calledWith({projectRoot, name: 'git'}).thenResolve(existingIgnores);
17
+
18
+ expect(await readGitIgnore({projectRoot})).toEqual(existingIgnores);
19
+ });
20
+ });
@@ -0,0 +1,5 @@
1
+ import write from './writer.js';
2
+
3
+ export default function ({projectRoot}) {
4
+ return write({projectRoot, ignores: []});
5
+ }
@@ -0,0 +1,17 @@
1
+ import {describe, expect, it, vi} from 'vitest';
2
+ import any from '@travi/any';
3
+
4
+ import writeGitIgnore from './writer.js';
5
+ import scaffold from './scaffolder.js';
6
+
7
+ vi.mock('./writer.js');
8
+
9
+ describe('ignore scaffolder', () => {
10
+ const projectRoot = any.string();
11
+
12
+ it('should write the directories and files', async () => {
13
+ await scaffold({projectRoot});
14
+
15
+ expect(writeGitIgnore).toHaveBeenCalledWith({projectRoot, ignores: []});
16
+ });
17
+ });
@@ -0,0 +1,5 @@
1
+ import {fileExists} from '@form8ion/core';
2
+
3
+ export default function ({projectRoot}) {
4
+ return fileExists(`${projectRoot}/.gitignore`);
5
+ }
@@ -0,0 +1,30 @@
1
+ import {fileExists} from '@form8ion/core';
2
+
3
+ import {describe, it, expect, vi, afterEach} from 'vitest';
4
+ import any from '@travi/any';
5
+ // eslint-disable-next-line import/no-unresolved
6
+ import {when} from 'vitest-when';
7
+
8
+ import gitignoreExists from './tester.js';
9
+
10
+ vi.mock('@form8ion/core');
11
+
12
+ describe('gitignore tester', () => {
13
+ const projectRoot = any.string();
14
+
15
+ afterEach(() => {
16
+ vi.clearAllMocks();
17
+ });
18
+
19
+ it('should return `true` if a `.gitignore` file exists', async () => {
20
+ when(fileExists).calledWith(`${projectRoot}/.gitignore`).thenResolve(true);
21
+
22
+ expect(await gitignoreExists({projectRoot})).toBe(true);
23
+ });
24
+
25
+ it('should return `false` if a `.gitignore` file does not exist', async () => {
26
+ when(fileExists).calledWith(`${projectRoot}/.gitignore`).thenResolve(false);
27
+
28
+ expect(await gitignoreExists({projectRoot})).toBe(false);
29
+ });
30
+ });
@@ -0,0 +1,5 @@
1
+ import {write} from '@form8ion/ignore-file';
2
+
3
+ export default function writeGitIgnore({projectRoot, ignores}) {
4
+ return write({projectRoot, name: 'git', ignores});
5
+ }
@@ -0,0 +1,19 @@
1
+ import {write} from '@form8ion/ignore-file';
2
+
3
+ import {describe, it, vi, expect} from 'vitest';
4
+ import any from '@travi/any';
5
+
6
+ import writeGitIgnore from './writer.js';
7
+
8
+ vi.mock('@form8ion/ignore-file');
9
+
10
+ describe('gitignore writer', () => {
11
+ it('should write the provided ignores to the .gitignore file', async () => {
12
+ const projectRoot = any.string();
13
+ const ignores = any.listOf(any.string);
14
+
15
+ await writeGitIgnore({projectRoot, ignores});
16
+
17
+ expect(write).toHaveBeenCalledWith({projectRoot, name: 'git', ignores});
18
+ });
19
+ });
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export {default as scaffold} from './scaffolder.js';
2
+ export {default as test} from './tester.js';
3
+ export {default as lift} from './lifter.js';
package/src/lifter.js ADDED
@@ -0,0 +1,11 @@
1
+ import {scaffold as scaffoldAttributes} from './attributes/index.js';
2
+ import {lift as liftIgnore} from './ignore/index.js';
3
+
4
+ export default async function ({projectRoot, results}) {
5
+ await Promise.all([
6
+ scaffoldAttributes({projectRoot}),
7
+ liftIgnore({projectRoot, results})
8
+ ]);
9
+
10
+ return {};
11
+ }
@@ -0,0 +1,22 @@
1
+ import any from '@travi/any';
2
+ import {describe, expect, it, vi} from 'vitest';
3
+
4
+ import {scaffold as scaffoldAttributes} from './attributes/index.js';
5
+ import {lift as liftIgnore} from './ignore/index.js';
6
+ import lift from './lifter.js';
7
+
8
+ vi.mock('./attributes/index.js');
9
+ vi.mock('./ignore/index.js');
10
+
11
+ describe('git lifter', () => {
12
+ it('should define the attributes file', async () => {
13
+ const projectRoot = any.string();
14
+ const results = any.simpleObject();
15
+
16
+ const result = await lift({projectRoot, results});
17
+
18
+ expect(result).toEqual({});
19
+ expect(scaffoldAttributes).toHaveBeenCalledWith({projectRoot});
20
+ expect(liftIgnore).toHaveBeenCalledWith({projectRoot, results});
21
+ });
22
+ });
@@ -0,0 +1,17 @@
1
+ import simpleGit from 'simple-git';
2
+ import {info} from '@travi/cli-messages';
3
+
4
+ import {scaffold as scaffoldIgnore} from './ignore/index.js';
5
+
6
+ export default async function ({projectRoot}) {
7
+ info('Initializing Git Repository');
8
+
9
+ const git = simpleGit({baseDir: projectRoot});
10
+
11
+ await Promise.all([
12
+ scaffoldIgnore({projectRoot}),
13
+ git.init()
14
+ ]);
15
+
16
+ return {};
17
+ }
@@ -0,0 +1,27 @@
1
+ import * as simpleGit from 'simple-git';
2
+
3
+ import any from '@travi/any';
4
+ import {describe, expect, it, vi} from 'vitest';
5
+ // eslint-disable-next-line import/no-unresolved
6
+ import {when} from 'vitest-when';
7
+
8
+ import {scaffold as scaffoldIgnore} from './ignore/index.js';
9
+ import scaffold from './scaffolder.js';
10
+
11
+ vi.mock('touch');
12
+ vi.mock('simple-git');
13
+ vi.mock('./ignore/index.js');
14
+
15
+ describe('scaffold', () => {
16
+ it('should initialize the repo', async () => {
17
+ const projectRoot = any.string();
18
+ const init = vi.fn();
19
+ when(simpleGit.simpleGit).calledWith({baseDir: projectRoot}).thenReturn({init});
20
+
21
+ const results = await scaffold({projectRoot});
22
+
23
+ expect(results).toEqual({});
24
+ expect(init).toHaveBeenCalled();
25
+ expect(scaffoldIgnore).toHaveBeenCalledWith({projectRoot});
26
+ });
27
+ });
package/src/tester.js ADDED
@@ -0,0 +1,7 @@
1
+ import simpleGit from 'simple-git';
2
+
3
+ export default function ({projectRoot}) {
4
+ const git = simpleGit({baseDir: projectRoot});
5
+
6
+ return git.checkIsRepo('root');
7
+ }
@@ -0,0 +1,35 @@
1
+ import * as simpleGit from 'simple-git';
2
+
3
+ import any from '@travi/any';
4
+ import {beforeEach, describe, it, expect, vi} from 'vitest';
5
+ // eslint-disable-next-line import/no-unresolved
6
+ import {when} from 'vitest-when';
7
+
8
+ import gitIsPresent from './tester.js';
9
+
10
+ vi.mock('simple-git');
11
+
12
+ describe('git predicate', () => {
13
+ let checkIsRepo;
14
+ const projectRoot = any.string();
15
+
16
+ beforeEach(() => {
17
+ checkIsRepo = vi.fn();
18
+
19
+ when(simpleGit.simpleGit)
20
+ .calledWith({baseDir: projectRoot})
21
+ .thenReturn({checkIsRepo});
22
+ });
23
+
24
+ it('should return `true` if a `.gitignore` file exists', async () => {
25
+ when(checkIsRepo).calledWith('root').thenResolve(true);
26
+
27
+ expect(await gitIsPresent({projectRoot})).toBe(true);
28
+ });
29
+
30
+ it('should return `false` if a `.gitignore` file does not exist', async () => {
31
+ when(checkIsRepo).calledWith('root').thenResolve(false);
32
+
33
+ expect(await gitIsPresent({projectRoot})).toBe(false);
34
+ });
35
+ });