aberlaas-init 2.18.1 → 2.20.1

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.
Files changed (79) hide show
  1. package/lib/helper.js +150 -119
  2. package/lib/layouts/__tests__/libdocs.js +55 -58
  3. package/lib/layouts/__tests__/module.js +22 -20
  4. package/lib/layouts/__tests__/monorepo.js +54 -62
  5. package/lib/layouts/libdocs.js +73 -68
  6. package/lib/layouts/module.js +33 -22
  7. package/lib/layouts/monorepo.js +75 -74
  8. package/lib/main.js +59 -43
  9. package/package.json +19 -21
  10. package/templates/_README.template.md +5 -0
  11. package/templates/_editorconfig +8 -0
  12. package/templates/_gitignore +11 -19
  13. package/templates/scripts/build +4 -0
  14. package/templates/scripts/build-prod +4 -0
  15. package/templates/scripts/ci +4 -0
  16. package/templates/scripts/cms +4 -0
  17. package/templates/scripts/compress +4 -0
  18. package/templates/scripts/{__module/hooks → hooks}/pre-commit +1 -1
  19. package/templates/scripts/lint +4 -0
  20. package/templates/scripts/lint-fix +4 -0
  21. package/templates/scripts/release +4 -0
  22. package/templates/scripts/serve +4 -0
  23. package/templates/scripts/test +4 -0
  24. package/templates/scripts/test-watch +4 -0
  25. package/templates/_gitattributes +0 -4
  26. package/templates/lerna.json +0 -6
  27. package/templates/scripts/__libdocs/hooks/pre-commit +0 -11
  28. package/templates/scripts/__libdocs/local/build +0 -5
  29. package/templates/scripts/__libdocs/local/build-prod +0 -5
  30. package/templates/scripts/__libdocs/local/ci +0 -5
  31. package/templates/scripts/__libdocs/local/cms +0 -4
  32. package/templates/scripts/__libdocs/local/compress +0 -5
  33. package/templates/scripts/__libdocs/local/lint +0 -5
  34. package/templates/scripts/__libdocs/local/lint-fix +0 -5
  35. package/templates/scripts/__libdocs/local/release +0 -5
  36. package/templates/scripts/__libdocs/local/serve +0 -5
  37. package/templates/scripts/__libdocs/local/test +0 -5
  38. package/templates/scripts/__libdocs/local/test-watch +0 -6
  39. package/templates/scripts/__libdocs/meta/build +0 -4
  40. package/templates/scripts/__libdocs/meta/build-prod +0 -4
  41. package/templates/scripts/__libdocs/meta/ci +0 -4
  42. package/templates/scripts/__libdocs/meta/cms +0 -4
  43. package/templates/scripts/__libdocs/meta/compress +0 -4
  44. package/templates/scripts/__libdocs/meta/lint +0 -4
  45. package/templates/scripts/__libdocs/meta/lint-fix +0 -4
  46. package/templates/scripts/__libdocs/meta/release +0 -5
  47. package/templates/scripts/__libdocs/meta/serve +0 -4
  48. package/templates/scripts/__libdocs/meta/test +0 -4
  49. package/templates/scripts/__libdocs/meta/test-watch +0 -4
  50. package/templates/scripts/__module/ci +0 -6
  51. package/templates/scripts/__module/compress +0 -4
  52. package/templates/scripts/__module/lint +0 -4
  53. package/templates/scripts/__module/lint-fix +0 -4
  54. package/templates/scripts/__module/release +0 -4
  55. package/templates/scripts/__module/test +0 -5
  56. package/templates/scripts/__module/test-watch +0 -5
  57. package/templates/scripts/__monorepo/hooks/pre-commit +0 -11
  58. package/templates/scripts/__monorepo/local/build +0 -5
  59. package/templates/scripts/__monorepo/local/build-prod +0 -5
  60. package/templates/scripts/__monorepo/local/ci +0 -5
  61. package/templates/scripts/__monorepo/local/cms +0 -5
  62. package/templates/scripts/__monorepo/local/compress +0 -5
  63. package/templates/scripts/__monorepo/local/lint +0 -5
  64. package/templates/scripts/__monorepo/local/lint-fix +0 -5
  65. package/templates/scripts/__monorepo/local/release +0 -5
  66. package/templates/scripts/__monorepo/local/serve +0 -5
  67. package/templates/scripts/__monorepo/local/test +0 -5
  68. package/templates/scripts/__monorepo/local/test-watch +0 -6
  69. package/templates/scripts/__monorepo/meta/build +0 -4
  70. package/templates/scripts/__monorepo/meta/build-prod +0 -4
  71. package/templates/scripts/__monorepo/meta/ci +0 -4
  72. package/templates/scripts/__monorepo/meta/cms +0 -4
  73. package/templates/scripts/__monorepo/meta/compress +0 -4
  74. package/templates/scripts/__monorepo/meta/lint +0 -4
  75. package/templates/scripts/__monorepo/meta/lint-fix +0 -4
  76. package/templates/scripts/__monorepo/meta/release +0 -5
  77. package/templates/scripts/__monorepo/meta/serve +0 -4
  78. package/templates/scripts/__monorepo/meta/test +0 -4
  79. package/templates/scripts/__monorepo/meta/test-watch +0 -4
package/lib/helper.js CHANGED
@@ -1,30 +1,121 @@
1
1
  import path from 'node:path';
2
- import Gilmore from 'gilmore';
2
+ import { _ } from 'golgoth';
3
3
  import {
4
4
  absolute,
5
+ consoleWarn,
5
6
  copy,
6
- env,
7
7
  firostError,
8
- glob,
9
8
  isFile,
10
9
  move,
11
10
  read,
11
+ readJson,
12
+ remove,
13
+ wrap,
12
14
  write,
13
15
  } from 'firost';
14
- import { _, pMap } from 'golgoth';
15
- import helper from 'aberlaas-helper';
16
+ import { hostGitPath, hostGitRoot } from 'aberlaas-helper';
16
17
  import { nodeVersion, yarnVersion } from 'aberlaas-versions';
18
+ import Gilmore from 'gilmore';
17
19
 
18
- /**
19
- * This hold functions shared for both the monorepo and simple init scenarios
20
- */
21
- export default {
20
+ export const __ = {
22
21
  /**
23
- * Return name of the current project, as the name of the current directory
24
- * @returns {string} Name of the project
22
+ * Add config files to the host. Each config files reference the default
23
+ * aberlaas config for its tool. This pattern allow end-users to use aberlaas
24
+ * default rules and overwrite them as they see fit
25
25
  */
26
- getProjectName() {
27
- return path.basename(helper.hostRoot());
26
+ async addConfigFiles() {
27
+ // Editorconfig
28
+ await __.copyTemplateToHost('_editorconfig', '.editorconfig');
29
+
30
+ // Git
31
+ await __.copyTemplateToHost('_gitignore', '.gitignore');
32
+ await remove(hostGitPath('.gitattributes'));
33
+
34
+ // README template
35
+ await __.copyTemplateToHost('_README.template.md', '.README.template.md');
36
+
37
+ // Yarn
38
+ await __.copyTemplateToHost('_yarnrc.yml', '.yarnrc.yml');
39
+
40
+ // ESLint
41
+ await __.copyTemplateToHost('eslint.config.js');
42
+
43
+ // Lint-staged
44
+ await __.copyTemplateToHost('lintstaged.config.js');
45
+
46
+ // Vite
47
+ await __.copyTemplateToHost('vite.config.js');
48
+
49
+ // Prettier
50
+ await __.copyTemplateToHost('prettier.config.js');
51
+
52
+ // Stylelint
53
+ await __.copyTemplateToHost('stylelint.config.js');
54
+
55
+ // Renovate
56
+ await __.copyTemplateToHost(
57
+ '_github/renovate.json',
58
+ '.github/renovate.json',
59
+ );
60
+
61
+ // CircleCI
62
+ await __.addCircleCIConfigFile();
63
+ },
64
+
65
+ /**
66
+ * Add default files required to have the minimum lib module
67
+ * @param {string} libPrefixPath Path to the lib files, ./lib by default
68
+ */
69
+ async addLibFiles(libPrefixPath = 'lib') {
70
+ await __.copyTemplateToHost('lib/main.js', `${libPrefixPath}/main.js`);
71
+ await __.copyTemplateToHost(
72
+ 'lib/__tests__/main.js',
73
+ `${libPrefixPath}/__tests__/main.js`,
74
+ );
75
+ },
76
+
77
+ /**
78
+ * Add MIT license file
79
+ * @param {string} hostFilepath Path to the LICENSE file, relative to the host
80
+ */
81
+ async addLicenseFile(hostFilepath) {
82
+ // Start by adding a template
83
+ await __.copyTemplateToHost('LICENSE', hostFilepath);
84
+
85
+ // Replace placeholder with real value
86
+ const licensePath = hostGitPath(hostFilepath);
87
+ const author = await __.getProjectAuthor();
88
+ const templateContent = await read(licensePath);
89
+ const actualContent = _.replace(templateContent, '{author}', author);
90
+
91
+ // Write it again
92
+ await write(actualContent, licensePath);
93
+ },
94
+
95
+ /**
96
+ * Add default script files from templates/scripts to the host
97
+ * Excludes documentation-specific scripts (build, build-prod, cms, serve)
98
+ */
99
+ async addDefaultScripts() {
100
+ await __.copyTemplateToHost('scripts/ci');
101
+ await __.copyTemplateToHost('scripts/compress');
102
+ await __.copyTemplateToHost('scripts/lint');
103
+ await __.copyTemplateToHost('scripts/lint-fix');
104
+ await __.copyTemplateToHost('scripts/release');
105
+ await __.copyTemplateToHost('scripts/test');
106
+ await __.copyTemplateToHost('scripts/test-watch');
107
+ await __.copyTemplateToHost('scripts/hooks/pre-commit');
108
+ },
109
+
110
+ /**
111
+ * Add documentation-specific scripts from templates/scripts to the host
112
+ * Only includes: build, build-prod, cms, serve
113
+ */
114
+ async addDocsScripts() {
115
+ await __.copyTemplateToHost('scripts/build');
116
+ await __.copyTemplateToHost('scripts/build-prod');
117
+ await __.copyTemplateToHost('scripts/cms');
118
+ await __.copyTemplateToHost('scripts/serve');
28
119
  },
29
120
 
30
121
  /**
@@ -32,33 +123,48 @@ export default {
32
123
  * @returns {string} Name of the author, or __placeholder__ if undefined
33
124
  */
34
125
  async getProjectAuthor() {
35
- const repo = this.__getRepo();
126
+ const repo = __.getRepo();
36
127
  return (await repo.githubRepoOwner()) || '__placeholder__';
37
128
  },
38
129
 
39
130
  /**
40
- * Return the version of aberlaas used on the CLI
41
- * This should have been set by the top-level entrypoint
131
+ * Return name of the current project, as the name of the current directory
132
+ * @returns {string} Name of the project
133
+ */
134
+ getProjectName() {
135
+ return path.basename(hostGitRoot());
136
+ },
137
+
138
+ /**
139
+ * Return the version of aberlaas installed in the project
140
+ * Reads from the host package.json devDependencies or dependencies
42
141
  * @returns {string} Version number
43
142
  **/
44
- getAberlaasVersion() {
45
- return env('ABERLAAS_VERSION');
143
+ async getAberlaasVersion() {
144
+ const packageJsonPath = hostGitPath('package.json');
145
+ const packageJson = await readJson(packageJsonPath);
146
+ return (
147
+ packageJson?.devDependencies?.aberlaas ||
148
+ packageJson?.dependencies?.aberlaas
149
+ );
46
150
  },
47
151
 
152
+ // === PRIVATE METHODS ===
48
153
  /**
49
154
  * Copy a config template to the host
50
155
  * @param {string} source Path to source file, relative to ./templates folder
51
- * @param {string} destination Path to destination file, relative to the host
156
+ * @param {string} userDestination Path to destination file, relative to the host. Defaults to source if not provided.
52
157
  * @returns {boolean} False if can't copy file, true otherwise
53
158
  */
54
- async copyTemplateToHost(source, destination) {
159
+ async copyTemplateToHost(source, userDestination) {
160
+ const destination = userDestination || source;
55
161
  const absoluteSource = absolute('../templates/', source);
56
- const absoluteDestination = helper.hostPath(destination);
162
+ const absoluteDestination = hostGitPath(destination);
57
163
 
58
164
  // Source file does not exist
59
165
  if (!(await isFile(absoluteSource))) {
60
166
  throw firostError(
61
- 'ERROR_INIT_COPY_FILE',
167
+ 'ABERLAAS_INIT_COPY_FILE_NOT_FOUND',
62
168
  `Unable to locate ${absoluteSource} file`,
63
169
  );
64
170
  }
@@ -71,9 +177,12 @@ export default {
71
177
  return true;
72
178
  }
73
179
 
74
- // Otherwise create a backup
75
- const backupDestination = `${absoluteDestination}.backup`;
180
+ // Otherwise create a backup in ./tmp/backup
181
+ const backupDestination = hostGitPath(`./tmp/backup/${destination}`);
76
182
  await move(absoluteDestination, backupDestination);
183
+ __.consoleWarn(
184
+ `Existing ${destination} backed up in ./tmp/backup/${destination}`,
185
+ );
77
186
  }
78
187
 
79
188
  await copy(absoluteSource, absoluteDestination);
@@ -81,32 +190,14 @@ export default {
81
190
  return true;
82
191
  },
83
192
 
84
- /**
85
- * Add MIT license file
86
- * @param {string} hostFilepath Path to the LICENSE file, relative to the host
87
- */
88
- async addLicenseFile(hostFilepath) {
89
- // Start by adding a template
90
- await this.copyTemplateToHost('LICENSE', hostFilepath);
91
-
92
- // Replace placeholder with real value
93
- const licensePath = helper.hostPath(hostFilepath);
94
- const author = await this.getProjectAuthor();
95
- const templateContent = await read(licensePath);
96
- const actualContent = _.replace(templateContent, '{author}', author);
97
-
98
- // Write it again
99
- await write(actualContent, licensePath);
100
- },
101
-
102
193
  /**
103
194
  * Add CircleCI Config file
104
195
  */
105
196
  async addCircleCIConfigFile() {
106
- const configFilepath = helper.hostPath('./.circleci/config.yml');
197
+ const configFilepath = hostGitPath('./.circleci/config.yml');
107
198
 
108
199
  // Start by adding a template
109
- await this.copyTemplateToHost('_circleci/config.yml', configFilepath);
200
+ await __.copyTemplateToHost('_circleci/config.yml', configFilepath);
110
201
 
111
202
  // Replace placeholder with real value
112
203
  const templateContent = await read(configFilepath);
@@ -118,80 +209,20 @@ export default {
118
209
  // Write it again
119
210
  await write(actualContent, configFilepath);
120
211
  },
121
-
122
- /**
123
- * Add script files
124
- * @param {string} layoutPrefixPath Path to the subfolder in
125
- * ./templates/scripts that hold the script files to copy
126
- */
127
- async addScripts(layoutPrefixPath) {
128
- const templateFolder = absolute('../templates/scripts/', layoutPrefixPath);
129
- const templateScripts = await glob('**/*', {
130
- directories: false,
131
- cwd: templateFolder,
132
- absolutePaths: false,
133
- });
134
-
135
- await pMap(templateScripts, async (templatePath) => {
136
- const sourcePath = `scripts/${layoutPrefixPath}/${templatePath}`;
137
- const destinationPath = `scripts/${templatePath}`;
138
- await this.copyTemplateToHost(sourcePath, destinationPath);
139
- });
140
- },
141
-
142
- /**
143
- * Add config files to the host. Each config files reference the default
144
- * aberlaas config for its tool. This pattern allow end-users to use aberlaas
145
- * default rules and overwrite them as they see fit
146
- */
147
- async addConfigFiles() {
148
- // Git
149
- await this.copyTemplateToHost('./_gitignore', './.gitignore');
150
- await this.copyTemplateToHost('./_gitattributes', './.gitattributes');
151
-
152
- // Yarn
153
- await this.copyTemplateToHost('_yarnrc.yml', '.yarnrc.yml');
154
-
155
- // ESLint
156
- await this.copyTemplateToHost('eslint.config.js', 'eslint.config.js');
157
-
158
- // Lint-staged
159
- await this.copyTemplateToHost(
160
- 'lintstaged.config.js',
161
- 'lintstaged.config.js',
162
- );
163
-
164
- // Vite
165
- await this.copyTemplateToHost('vite.config.js', 'vite.config.js');
166
-
167
- // Prettier
168
- await this.copyTemplateToHost('prettier.config.js', 'prettier.config.js');
169
-
170
- // Stylelint
171
- await this.copyTemplateToHost('stylelint.config.js', 'stylelint.config.js');
172
-
173
- // Renovate
174
- await this.copyTemplateToHost(
175
- '_github/renovate.json',
176
- '.github/renovate.json',
177
- );
178
-
179
- // CircleCI
180
- await this.addCircleCIConfigFile();
181
- },
182
-
183
- /**
184
- * Add default files required to have the minimum lib module
185
- * @param {string} libPrefixPath Path to the lib files, ./lib by default
186
- */
187
- async addLibFiles(libPrefixPath = 'lib') {
188
- await this.copyTemplateToHost('lib/main.js', `${libPrefixPath}/main.js`);
189
- await this.copyTemplateToHost(
190
- 'lib/__tests__/main.js',
191
- `${libPrefixPath}/__tests__/main.js`,
192
- );
193
- },
194
- __getRepo() {
195
- return new Gilmore(helper.hostRoot());
212
+ getRepo() {
213
+ return new Gilmore(hostGitRoot());
196
214
  },
215
+ consoleWarn,
197
216
  };
217
+
218
+ // Named exports of public methods, but wrapped in dynamic method so we can
219
+ // still mock the inner methods in tests
220
+ //
221
+ export const addConfigFiles = wrap(__, 'addConfigFiles');
222
+ export const addDefaultScripts = wrap(__, 'addDefaultScripts');
223
+ export const addDocsScripts = wrap(__, 'addDocsScripts');
224
+ export const addLibFiles = wrap(__, 'addLibFiles');
225
+ export const addLicenseFile = wrap(__, 'addLicenseFile');
226
+ export const getAberlaasVersion = wrap(__, 'getAberlaasVersion');
227
+ export const getProjectAuthor = wrap(__, 'getProjectAuthor');
228
+ export const getProjectName = wrap(__, 'getProjectName');
@@ -1,28 +1,37 @@
1
- import { exists, glob, readJson, remove, tmpDirectory } from 'firost';
2
- import helper from 'aberlaas-helper';
3
1
  import {
4
- lernaVersion,
2
+ exists,
3
+ glob,
4
+ readJson,
5
+ remove,
6
+ tmpDirectory,
7
+ writeJson,
8
+ } from 'firost';
9
+ import { hostGitPath, hostGitRoot, mockHelperPaths } from 'aberlaas-helper';
10
+ import {
5
11
  nodeVersion,
6
12
  norskaThemeDocsVersion,
7
13
  norskaVersion,
8
14
  yarnVersion,
9
15
  } from 'aberlaas-versions';
10
- import current from '../libdocs.js';
16
+ import { __ as initHelper } from '../../helper.js';
17
+ import { __, run } from '../libdocs.js';
11
18
 
12
19
  describe('init > libdocs', () => {
20
+ const testDirectory = tmpDirectory('aberlaas/init/libdocs');
13
21
  beforeEach(async () => {
14
- // We need to make the tmp directory outside of this git repo tree, for all
15
- // git/yarn related command to work so we put it in a /tmp directory
16
- vi.spyOn(helper, 'hostRoot').mockReturnValue(
17
- tmpDirectory('aberlaas/init/libdocs'),
22
+ mockHelperPaths(testDirectory);
23
+
24
+ // Create a package.json with aberlaas in devDependencies
25
+ await writeJson(
26
+ { devDependencies: { aberlaas: '1.2.3' } },
27
+ hostGitPath('package.json'),
18
28
  );
19
29
 
20
- vi.spyOn(current, '__getProjectName').mockReturnValue('my-project');
21
- vi.spyOn(current, '__getProjectAuthor').mockReturnValue('my-name');
22
- vi.spyOn(current, '__getAberlaasVersion').mockReturnValue('1.2.3');
30
+ vi.spyOn(initHelper, 'getProjectName').mockReturnValue('my-project');
31
+ vi.spyOn(initHelper, 'getProjectAuthor').mockReturnValue('my-name');
23
32
  });
24
33
  afterEach(async () => {
25
- await remove(helper.hostRoot());
34
+ await remove(hostGitRoot());
26
35
  });
27
36
 
28
37
  // WORKSPACES
@@ -49,20 +58,18 @@ describe('init > libdocs', () => {
49
58
  dependencies: {},
50
59
  devDependencies: {
51
60
  aberlaas: '1.2.3',
52
- lerna: lernaVersion,
53
61
  },
54
62
  scripts: {
55
- build: './scripts/meta/build',
56
- release: './scripts/meta/release',
57
- lint: './scripts/meta/lint',
58
- learn: 'lerna',
63
+ build: './scripts/build',
64
+ release: './scripts/release',
65
+ lint: './scripts/lint',
59
66
  },
60
67
  },
61
68
  ],
62
69
  ])('%s', async (_title, expected) => {
63
- await current.createRootWorkspace();
70
+ await __.createRootWorkspace();
64
71
 
65
- const actual = await readJson(helper.hostPath('package.json'));
72
+ const actual = await readJson(hostGitPath('package.json'));
66
73
 
67
74
  expect(actual).toMatchObject(expected);
68
75
  });
@@ -91,16 +98,16 @@ describe('init > libdocs', () => {
91
98
  'norska-theme-docs': norskaThemeDocsVersion,
92
99
  },
93
100
  scripts: {
94
- build: '../scripts/local/build',
95
- release: '../scripts/local/release',
96
- lint: '../scripts/local/lint',
101
+ build: 'cd .. && ./scripts/build',
102
+ release: 'cd .. && ./scripts/release',
103
+ lint: 'cd .. && ./scripts/lint',
97
104
  },
98
105
  },
99
106
  ],
100
107
  ])('%s', async (_title, expected) => {
101
- await current.createDocsWorkspace();
108
+ await __.createDocsWorkspace();
102
109
 
103
- const actual = await readJson(helper.hostPath('docs/package.json'));
110
+ const actual = await readJson(hostGitPath('docs/package.json'));
104
111
 
105
112
  expect(actual).toMatchObject(expected);
106
113
  });
@@ -140,16 +147,16 @@ describe('init > libdocs', () => {
140
147
  dependencies: {},
141
148
 
142
149
  scripts: {
143
- build: '../scripts/local/build',
144
- release: '../scripts/local/release',
145
- lint: '../scripts/local/lint',
150
+ build: 'cd .. && ./scripts/build',
151
+ release: 'cd .. && ./scripts/release',
152
+ lint: 'cd .. && ./scripts/lint',
146
153
  },
147
154
  },
148
155
  ],
149
156
  ])('%s', async (_title, expected) => {
150
- await current.createLibWorkspace();
157
+ await __.createLibWorkspace();
151
158
 
152
- const actual = await readJson(helper.hostPath('lib/package.json'));
159
+ const actual = await readJson(hostGitPath('lib/package.json'));
153
160
 
154
161
  expect(actual).toMatchObject(expected);
155
162
  });
@@ -157,32 +164,33 @@ describe('init > libdocs', () => {
157
164
 
158
165
  describe('addLicenseFiles', () => {
159
166
  it('creates license file in root and ./lib', async () => {
160
- await current.addLicenseFiles();
167
+ await __.addLicenseFiles();
161
168
 
162
- expect(await exists(helper.hostPath('LICENSE'))).toBe(true);
163
- expect(await exists(helper.hostPath('lib/LICENSE'))).toBe(true);
169
+ expect(await exists(hostGitPath('LICENSE'))).toBe(true);
170
+ expect(await exists(hostGitPath('lib/LICENSE'))).toBe(true);
164
171
  });
165
172
  });
166
173
 
167
174
  describe('run', () => {
175
+ vi.setConfig({ testTimeout: 10_000 });
168
176
  it('should build a libdocs structure', async () => {
169
- await current.run();
177
+ await run();
170
178
 
171
179
  const actual = await glob('**/*', {
172
- cwd: helper.hostPath(),
180
+ cwd: hostGitPath(),
173
181
  absolutePaths: false,
174
182
  directories: false,
175
183
  });
176
184
 
177
185
  expect(actual).toEqual([
178
186
  '.circleci/config.yml',
179
- '.gitattributes',
187
+ '.editorconfig',
180
188
  '.github/renovate.json',
181
189
  '.gitignore',
190
+ '.README.template.md',
182
191
  '.yarnrc.yml',
183
192
  'docs/package.json',
184
193
  'eslint.config.js',
185
- 'lerna.json',
186
194
  'lib/__tests__/main.js',
187
195
  'lib/LICENSE',
188
196
  'lib/main.js',
@@ -191,29 +199,18 @@ describe('init > libdocs', () => {
191
199
  'lintstaged.config.js',
192
200
  'package.json',
193
201
  'prettier.config.js',
202
+ 'scripts/build',
203
+ 'scripts/build-prod',
204
+ 'scripts/ci',
205
+ 'scripts/cms',
206
+ 'scripts/compress',
194
207
  'scripts/hooks/pre-commit',
195
- 'scripts/local/build',
196
- 'scripts/local/build-prod',
197
- 'scripts/local/ci',
198
- 'scripts/local/cms',
199
- 'scripts/local/compress',
200
- 'scripts/local/lint',
201
- 'scripts/local/lint-fix',
202
- 'scripts/local/release',
203
- 'scripts/local/serve',
204
- 'scripts/local/test',
205
- 'scripts/local/test-watch',
206
- 'scripts/meta/build',
207
- 'scripts/meta/build-prod',
208
- 'scripts/meta/ci',
209
- 'scripts/meta/cms',
210
- 'scripts/meta/compress',
211
- 'scripts/meta/lint',
212
- 'scripts/meta/lint-fix',
213
- 'scripts/meta/release',
214
- 'scripts/meta/serve',
215
- 'scripts/meta/test',
216
- 'scripts/meta/test-watch',
208
+ 'scripts/lint',
209
+ 'scripts/lint-fix',
210
+ 'scripts/release',
211
+ 'scripts/serve',
212
+ 'scripts/test',
213
+ 'scripts/test-watch',
217
214
  'stylelint.config.js',
218
215
  'vite.config.js',
219
216
  ]);
@@ -1,22 +1,25 @@
1
- import { glob, read, readJson, remove, tmpDirectory } from 'firost';
2
- import helper from 'aberlaas-helper';
1
+ import { glob, read, readJson, remove, tmpDirectory, writeJson } from 'firost';
2
+ import { hostGitPath, hostGitRoot, mockHelperPaths } from 'aberlaas-helper';
3
3
  import { nodeVersion, yarnVersion } from 'aberlaas-versions';
4
- import current from '../module.js';
4
+ import { __ as initHelper } from '../../helper.js';
5
+ import { __, run } from '../module.js';
5
6
 
6
7
  describe('init > module', () => {
8
+ const testDirectory = tmpDirectory('aberlaas/init/module');
7
9
  beforeEach(async () => {
8
- // We need to make the tmp directory outside of this git repo tree, for all
9
- // git/yarn related command to work so we put it in a /tmp directory
10
- vi.spyOn(helper, 'hostRoot').mockReturnValue(
11
- tmpDirectory('aberlaas/init/module'),
10
+ mockHelperPaths(testDirectory);
11
+
12
+ // Create a package.json with aberlaas in devDependencies
13
+ await writeJson(
14
+ { devDependencies: { aberlaas: '1.2.3' } },
15
+ hostGitPath('package.json'),
12
16
  );
13
17
 
14
- vi.spyOn(current, '__getProjectName').mockReturnValue('my-project');
15
- vi.spyOn(current, '__getProjectAuthor').mockReturnValue('my-name');
16
- vi.spyOn(current, '__getAberlaasVersion').mockReturnValue('1.2.3');
18
+ vi.spyOn(initHelper, 'getProjectName').mockReturnValue('my-project');
19
+ vi.spyOn(initHelper, 'getProjectAuthor').mockReturnValue('my-name');
17
20
  });
18
21
  afterEach(async () => {
19
- await remove(helper.hostRoot());
22
+ await remove(hostGitRoot());
20
23
  });
21
24
 
22
25
  describe('createPackageJson', () => {
@@ -83,9 +86,9 @@ describe('init > module', () => {
83
86
  },
84
87
  ],
85
88
  ])('%s', async (_title, expected) => {
86
- await current.createPackageJson();
89
+ await __.createPackageJson();
87
90
 
88
- const actual = await readJson(helper.hostPath('package.json'));
91
+ const actual = await readJson(hostGitPath('package.json'));
89
92
 
90
93
  expect(actual).toMatchObject(expected);
91
94
  });
@@ -93,19 +96,20 @@ describe('init > module', () => {
93
96
 
94
97
  describe('run', () => {
95
98
  it('should build a module structure', async () => {
96
- await current.run();
99
+ await run();
97
100
 
98
101
  const actual = await glob('**/*', {
99
- cwd: helper.hostPath(),
102
+ cwd: hostGitPath(),
100
103
  absolutePaths: false,
101
104
  directories: false,
102
105
  });
103
106
 
104
107
  expect(actual).toEqual([
105
108
  '.circleci/config.yml',
106
- '.gitattributes',
109
+ '.editorconfig',
107
110
  '.github/renovate.json',
108
111
  '.gitignore',
112
+ '.README.template.md',
109
113
  '.yarnrc.yml',
110
114
  'eslint.config.js',
111
115
  'lib/__tests__/main.js',
@@ -128,11 +132,9 @@ describe('init > module', () => {
128
132
  });
129
133
 
130
134
  it('should write a correct circleCI file', async () => {
131
- await current.run();
135
+ await run();
132
136
 
133
- const circleciConfig = await read(
134
- helper.hostPath('.circleci/config.yml'),
135
- );
137
+ const circleciConfig = await read(hostGitPath('.circleci/config.yml'));
136
138
 
137
139
  // Should not contain literal template placeholders
138
140
  expect(circleciConfig).not.toContain('{nodeVersion}');