aberlaas-init 2.10.0 → 2.13.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/lib/helper.js +32 -25
- package/lib/layouts/__tests__/libdocs.js +222 -0
- package/lib/layouts/__tests__/module.js +130 -0
- package/lib/layouts/__tests__/monorepo.js +226 -0
- package/lib/{monorepo.js → layouts/libdocs.js} +39 -78
- package/lib/{module.js → layouts/module.js} +18 -21
- package/lib/layouts/monorepo.js +236 -0
- package/lib/main.js +37 -6
- package/package.json +6 -5
- package/templates/_yarnrc.yml +1 -0
- package/templates/scripts/__libdocs/local/build +5 -0
- package/templates/scripts/__libdocs/local/build-prod +5 -0
- package/templates/scripts/__libdocs/local/ci +5 -0
- package/templates/scripts/__libdocs/local/cms +4 -0
- package/templates/scripts/__libdocs/local/compress +5 -0
- package/templates/scripts/__libdocs/local/lint +5 -0
- package/templates/scripts/__libdocs/local/lint-fix +5 -0
- package/templates/scripts/__libdocs/local/release +5 -0
- package/templates/scripts/__libdocs/local/serve +5 -0
- package/templates/scripts/__libdocs/local/test +5 -0
- package/templates/scripts/__libdocs/local/test-watch +6 -0
- package/templates/scripts/__libdocs/meta/build +4 -0
- package/templates/scripts/__libdocs/meta/build-prod +4 -0
- package/templates/scripts/__libdocs/meta/ci +4 -0
- package/templates/scripts/__libdocs/meta/cms +4 -0
- package/templates/scripts/__libdocs/meta/compress +4 -0
- package/templates/scripts/__libdocs/meta/lint +4 -0
- package/templates/scripts/__libdocs/meta/lint-fix +4 -0
- package/templates/scripts/__libdocs/meta/serve +4 -0
- package/templates/scripts/__libdocs/meta/test +4 -0
- package/templates/scripts/__libdocs/meta/test-watch +4 -0
- package/templates/scripts/__module/hooks/pre-commit +11 -0
- package/templates/scripts/__module/release +4 -0
- package/templates/scripts/__monorepo/hooks/pre-commit +11 -0
- package/templates/scripts/__monorepo/local/build +5 -0
- package/templates/scripts/__monorepo/local/build-prod +5 -0
- package/templates/scripts/__monorepo/local/ci +5 -0
- package/templates/scripts/__monorepo/local/cms +5 -0
- package/templates/scripts/__monorepo/local/compress +5 -0
- package/templates/scripts/__monorepo/local/lint +5 -0
- package/templates/scripts/__monorepo/local/lint-fix +5 -0
- package/templates/scripts/__monorepo/local/release +5 -0
- package/templates/scripts/__monorepo/local/serve +5 -0
- package/templates/scripts/__monorepo/local/test +5 -0
- package/templates/scripts/__monorepo/local/test-watch +6 -0
- package/templates/scripts/__monorepo/meta/build +4 -0
- package/templates/scripts/__monorepo/meta/build-prod +4 -0
- package/templates/scripts/__monorepo/meta/ci +4 -0
- package/templates/scripts/__monorepo/meta/cms +4 -0
- package/templates/scripts/__monorepo/meta/compress +4 -0
- package/templates/scripts/__monorepo/meta/lint +4 -0
- package/templates/scripts/__monorepo/meta/lint-fix +4 -0
- package/templates/scripts/__monorepo/meta/release +5 -0
- package/templates/scripts/__monorepo/meta/serve +4 -0
- package/templates/scripts/__monorepo/meta/test +4 -0
- package/templates/scripts/__monorepo/meta/test-watch +4 -0
- package/templates/scripts/docs/build +0 -4
- package/templates/scripts/docs/build-prod +0 -4
- package/templates/scripts/docs/cms +0 -4
- package/templates/scripts/docs/serve +0 -4
- /package/templates/scripts/{hooks → __libdocs/hooks}/pre-commit +0 -0
- /package/templates/scripts/{lib → __libdocs/meta}/release +0 -0
- /package/templates/scripts/{ci → __module/ci} +0 -0
- /package/templates/scripts/{compress → __module/compress} +0 -0
- /package/templates/scripts/{lint → __module/lint} +0 -0
- /package/templates/scripts/{lint-fix → __module/lint-fix} +0 -0
- /package/templates/scripts/{lib → __module}/test +0 -0
- /package/templates/scripts/{lib → __module}/test-watch +0 -0
package/lib/helper.js
CHANGED
|
@@ -3,13 +3,15 @@ import Gilmore from 'gilmore';
|
|
|
3
3
|
import {
|
|
4
4
|
absolute,
|
|
5
5
|
copy,
|
|
6
|
+
env,
|
|
6
7
|
error as firostError,
|
|
8
|
+
glob,
|
|
7
9
|
isFile,
|
|
8
10
|
move,
|
|
9
11
|
read,
|
|
10
12
|
write,
|
|
11
13
|
} from 'firost';
|
|
12
|
-
import { _ } from 'golgoth';
|
|
14
|
+
import { _, pMap } from 'golgoth';
|
|
13
15
|
import helper from 'aberlaas-helper';
|
|
14
16
|
import { nodeVersion, yarnVersion } from 'aberlaas-versions';
|
|
15
17
|
|
|
@@ -34,6 +36,15 @@ export default {
|
|
|
34
36
|
return (await repo.githubRepoOwner()) || '__placeholder__';
|
|
35
37
|
},
|
|
36
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Return the version of aberlaas used on the CLI
|
|
41
|
+
* This should have been set by the top-level entrypoint
|
|
42
|
+
* @returns {string} Version number
|
|
43
|
+
**/
|
|
44
|
+
getAberlaasVersion() {
|
|
45
|
+
return env('ABERLAAS_VERSION');
|
|
46
|
+
},
|
|
47
|
+
|
|
37
48
|
/**
|
|
38
49
|
* Copy a config template to the host
|
|
39
50
|
* @param {string} source Path to source file, relative to ./templates folder
|
|
@@ -109,28 +120,23 @@ export default {
|
|
|
109
120
|
},
|
|
110
121
|
|
|
111
122
|
/**
|
|
112
|
-
* Add
|
|
123
|
+
* Add script files
|
|
124
|
+
* @param {string} layoutPrefixPath Path to the subfolder in
|
|
125
|
+
* ./templates/scripts that hold the script files to copy
|
|
113
126
|
*/
|
|
114
|
-
async addScripts() {
|
|
115
|
-
|
|
116
|
-
await
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
await
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// Lib
|
|
128
|
-
await this.copyTemplateToHost('scripts/lib/release', 'scripts/lib/release');
|
|
129
|
-
await this.copyTemplateToHost('scripts/lib/test', 'scripts/lib/test');
|
|
130
|
-
await this.copyTemplateToHost(
|
|
131
|
-
'scripts/lib/test-watch',
|
|
132
|
-
'scripts/lib/test-watch',
|
|
133
|
-
);
|
|
127
|
+
async addScripts(layoutPrefixPath) {
|
|
128
|
+
const templateFolder = absolute('../templates/scripts/', layoutPrefixPath);
|
|
129
|
+
const templateScripts = await glob('**/*', {
|
|
130
|
+
directories: false,
|
|
131
|
+
context: 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
|
+
});
|
|
134
140
|
},
|
|
135
141
|
|
|
136
142
|
/**
|
|
@@ -179,12 +185,13 @@ export default {
|
|
|
179
185
|
|
|
180
186
|
/**
|
|
181
187
|
* Add default files required to have the minimum lib module
|
|
188
|
+
* @param {string} libPrefixPath Path to the lib files, ./lib by default
|
|
182
189
|
*/
|
|
183
|
-
async addLibFiles() {
|
|
184
|
-
await this.copyTemplateToHost('lib/main.js',
|
|
190
|
+
async addLibFiles(libPrefixPath = 'lib') {
|
|
191
|
+
await this.copyTemplateToHost('lib/main.js', `${libPrefixPath}/main.js`);
|
|
185
192
|
await this.copyTemplateToHost(
|
|
186
193
|
'lib/__tests__/main.js',
|
|
187
|
-
|
|
194
|
+
`${libPrefixPath}/__tests__/main.js`,
|
|
188
195
|
);
|
|
189
196
|
},
|
|
190
197
|
__getRepo() {
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { exists, glob, readJson, remove, tmpDirectory } from 'firost';
|
|
2
|
+
import helper from 'aberlaas-helper';
|
|
3
|
+
import {
|
|
4
|
+
lernaVersion,
|
|
5
|
+
nodeVersion,
|
|
6
|
+
norskaThemeDocsVersion,
|
|
7
|
+
norskaVersion,
|
|
8
|
+
yarnVersion,
|
|
9
|
+
} from 'aberlaas-versions';
|
|
10
|
+
import current from '../libdocs.js';
|
|
11
|
+
|
|
12
|
+
describe('init > libdocs', () => {
|
|
13
|
+
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'),
|
|
18
|
+
);
|
|
19
|
+
|
|
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');
|
|
23
|
+
});
|
|
24
|
+
afterEach(async () => {
|
|
25
|
+
await remove(helper.hostRoot());
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// WORKSPACES
|
|
29
|
+
describe('createRootWorkspace', () => {
|
|
30
|
+
it.each([
|
|
31
|
+
[
|
|
32
|
+
'should have correct metadata',
|
|
33
|
+
{
|
|
34
|
+
name: 'my-project-root',
|
|
35
|
+
author: 'my-name',
|
|
36
|
+
description: 'my-project root workspace',
|
|
37
|
+
repository: 'my-name/my-project',
|
|
38
|
+
homepage: 'https://projects.pixelastic.com/my-project',
|
|
39
|
+
license: 'MIT',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
'should have root specific data',
|
|
44
|
+
{
|
|
45
|
+
private: true,
|
|
46
|
+
workspaces: ['docs', 'lib'],
|
|
47
|
+
type: 'module',
|
|
48
|
+
packageManager: `yarn@${yarnVersion}`,
|
|
49
|
+
dependencies: {},
|
|
50
|
+
devDependencies: {
|
|
51
|
+
aberlaas: '1.2.3',
|
|
52
|
+
lerna: lernaVersion,
|
|
53
|
+
},
|
|
54
|
+
scripts: {
|
|
55
|
+
build: './scripts/meta/build',
|
|
56
|
+
release: './scripts/meta/release',
|
|
57
|
+
lint: './scripts/meta/lint',
|
|
58
|
+
learn: 'lerna',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
])('%s', async (_title, expected) => {
|
|
63
|
+
await current.createRootWorkspace();
|
|
64
|
+
|
|
65
|
+
const actual = await readJson(helper.hostPath('package.json'));
|
|
66
|
+
|
|
67
|
+
expect(actual).toMatchObject(expected);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('createDocsWorkspace', () => {
|
|
71
|
+
it.each([
|
|
72
|
+
[
|
|
73
|
+
'should have correct metadata',
|
|
74
|
+
{
|
|
75
|
+
name: 'my-project-docs',
|
|
76
|
+
version: '0.0.1',
|
|
77
|
+
author: 'my-name',
|
|
78
|
+
description: 'my-project docs',
|
|
79
|
+
repository: 'my-name/my-project',
|
|
80
|
+
homepage: 'https://projects.pixelastic.com/my-project',
|
|
81
|
+
license: 'MIT',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
'should have docs specific data',
|
|
86
|
+
{
|
|
87
|
+
private: true,
|
|
88
|
+
devDependencies: {},
|
|
89
|
+
dependencies: {
|
|
90
|
+
norska: norskaVersion,
|
|
91
|
+
'norska-theme-docs': norskaThemeDocsVersion,
|
|
92
|
+
},
|
|
93
|
+
scripts: {
|
|
94
|
+
build: '../scripts/local/build',
|
|
95
|
+
release: '../scripts/local/release',
|
|
96
|
+
lint: '../scripts/local/lint',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
])('%s', async (_title, expected) => {
|
|
101
|
+
await current.createDocsWorkspace();
|
|
102
|
+
|
|
103
|
+
const actual = await readJson(helper.hostPath('docs/package.json'));
|
|
104
|
+
|
|
105
|
+
expect(actual).toMatchObject(expected);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
describe('createLibWorkspace', () => {
|
|
109
|
+
it.each([
|
|
110
|
+
[
|
|
111
|
+
'should have correct metadata',
|
|
112
|
+
{
|
|
113
|
+
name: 'my-project',
|
|
114
|
+
version: '0.0.1',
|
|
115
|
+
author: 'my-name',
|
|
116
|
+
description: '',
|
|
117
|
+
keywords: [],
|
|
118
|
+
repository: 'my-name/my-project',
|
|
119
|
+
homepage: 'https://projects.pixelastic.com/my-project',
|
|
120
|
+
license: 'MIT',
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
'should have lib specific data',
|
|
125
|
+
{
|
|
126
|
+
private: false,
|
|
127
|
+
type: 'module',
|
|
128
|
+
sideEffects: false,
|
|
129
|
+
engines: {
|
|
130
|
+
node: `>=${nodeVersion}`,
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
files: ['*.js'],
|
|
134
|
+
exports: { '.': './main.js' },
|
|
135
|
+
// Some tools have trouble parsing the .exports field, so we keep the
|
|
136
|
+
// .main field for backward compatibility
|
|
137
|
+
main: './main.js',
|
|
138
|
+
|
|
139
|
+
devDependencies: {},
|
|
140
|
+
dependencies: {},
|
|
141
|
+
|
|
142
|
+
scripts: {
|
|
143
|
+
build: '../scripts/local/build',
|
|
144
|
+
release: '../scripts/local/release',
|
|
145
|
+
lint: '../scripts/local/lint',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
])('%s', async (_title, expected) => {
|
|
150
|
+
await current.createLibWorkspace();
|
|
151
|
+
|
|
152
|
+
const actual = await readJson(helper.hostPath('lib/package.json'));
|
|
153
|
+
|
|
154
|
+
expect(actual).toMatchObject(expected);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('addLicenseFiles', () => {
|
|
159
|
+
it('creates license file in root and ./lib', async () => {
|
|
160
|
+
await current.addLicenseFiles();
|
|
161
|
+
|
|
162
|
+
expect(await exists(helper.hostPath('LICENSE'))).toBe(true);
|
|
163
|
+
expect(await exists(helper.hostPath('lib/LICENSE'))).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe('run', () => {
|
|
168
|
+
it('should build a libdocs structure', async () => {
|
|
169
|
+
await current.run();
|
|
170
|
+
|
|
171
|
+
const actual = await glob('**/*', {
|
|
172
|
+
context: helper.hostPath(),
|
|
173
|
+
absolutePaths: false,
|
|
174
|
+
directories: false,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
expect(actual).toEqual([
|
|
178
|
+
'.circleci/config.yml',
|
|
179
|
+
'.gitattributes',
|
|
180
|
+
'.github/renovate.json',
|
|
181
|
+
'.gitignore',
|
|
182
|
+
'.yarnrc.yml',
|
|
183
|
+
'docs/package.json',
|
|
184
|
+
'eslint.config.js',
|
|
185
|
+
'lerna.json',
|
|
186
|
+
'lib/__tests__/main.js',
|
|
187
|
+
'lib/LICENSE',
|
|
188
|
+
'lib/main.js',
|
|
189
|
+
'lib/package.json',
|
|
190
|
+
'LICENSE',
|
|
191
|
+
'lintstaged.config.js',
|
|
192
|
+
'package.json',
|
|
193
|
+
'prettier.config.js',
|
|
194
|
+
'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',
|
|
217
|
+
'stylelint.config.js',
|
|
218
|
+
'vite.config.js',
|
|
219
|
+
]);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { glob, readJson, remove, tmpDirectory } from 'firost';
|
|
2
|
+
import helper from 'aberlaas-helper';
|
|
3
|
+
import { nodeVersion, yarnVersion } from 'aberlaas-versions';
|
|
4
|
+
import current from '../module.js';
|
|
5
|
+
|
|
6
|
+
describe('init > module', () => {
|
|
7
|
+
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'),
|
|
12
|
+
);
|
|
13
|
+
|
|
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');
|
|
17
|
+
});
|
|
18
|
+
afterEach(async () => {
|
|
19
|
+
await remove(helper.hostRoot());
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('createPackageJson', () => {
|
|
23
|
+
it.each([
|
|
24
|
+
[
|
|
25
|
+
'should have correct metadata',
|
|
26
|
+
{
|
|
27
|
+
name: 'my-project',
|
|
28
|
+
version: '0.0.1',
|
|
29
|
+
author: 'my-name',
|
|
30
|
+
description: '',
|
|
31
|
+
keywords: [],
|
|
32
|
+
repository: 'my-name/my-project',
|
|
33
|
+
homepage: 'https://github.com/my-name/my-project',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
'should have correct license',
|
|
38
|
+
{
|
|
39
|
+
license: 'MIT',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
'should have ESM information',
|
|
44
|
+
{
|
|
45
|
+
type: 'module',
|
|
46
|
+
sideEffects: false,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
'should have language and yarn version',
|
|
51
|
+
{
|
|
52
|
+
engines: {
|
|
53
|
+
node: `>=${nodeVersion}`,
|
|
54
|
+
},
|
|
55
|
+
packageManager: `yarn@${yarnVersion}`,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
'should export the right files',
|
|
60
|
+
{
|
|
61
|
+
files: ['lib/*.js'],
|
|
62
|
+
exports: { '.': './lib/main.js' },
|
|
63
|
+
main: './lib/main.js',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
'should have the right dependencies',
|
|
68
|
+
{
|
|
69
|
+
devDependencies: {
|
|
70
|
+
aberlaas: '1.2.3',
|
|
71
|
+
},
|
|
72
|
+
dependencies: {},
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
'should have scripts',
|
|
77
|
+
{
|
|
78
|
+
scripts: {
|
|
79
|
+
release: './scripts/release',
|
|
80
|
+
test: './scripts/test',
|
|
81
|
+
lint: './scripts/lint',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
])('%s', async (_title, expected) => {
|
|
86
|
+
await current.createPackageJson();
|
|
87
|
+
|
|
88
|
+
const actual = await readJson(helper.hostPath('package.json'));
|
|
89
|
+
|
|
90
|
+
expect(actual).toMatchObject(expected);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('run', () => {
|
|
95
|
+
it('should build a module structure', async () => {
|
|
96
|
+
await current.run();
|
|
97
|
+
|
|
98
|
+
const actual = await glob('**/*', {
|
|
99
|
+
context: helper.hostPath(),
|
|
100
|
+
absolutePaths: false,
|
|
101
|
+
directories: false,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(actual).toEqual([
|
|
105
|
+
'.circleci/config.yml',
|
|
106
|
+
'.gitattributes',
|
|
107
|
+
'.github/renovate.json',
|
|
108
|
+
'.gitignore',
|
|
109
|
+
'.yarnrc.yml',
|
|
110
|
+
'eslint.config.js',
|
|
111
|
+
'lib/__tests__/main.js',
|
|
112
|
+
'lib/main.js',
|
|
113
|
+
'LICENSE',
|
|
114
|
+
'lintstaged.config.js',
|
|
115
|
+
'package.json',
|
|
116
|
+
'prettier.config.js',
|
|
117
|
+
'scripts/ci',
|
|
118
|
+
'scripts/compress',
|
|
119
|
+
'scripts/hooks/pre-commit',
|
|
120
|
+
'scripts/lint',
|
|
121
|
+
'scripts/lint-fix',
|
|
122
|
+
'scripts/release',
|
|
123
|
+
'scripts/test',
|
|
124
|
+
'scripts/test-watch',
|
|
125
|
+
'stylelint.config.js',
|
|
126
|
+
'vite.config.js',
|
|
127
|
+
]);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { exists, glob, readJson, remove, tmpDirectory } from 'firost';
|
|
2
|
+
import helper from 'aberlaas-helper';
|
|
3
|
+
import {
|
|
4
|
+
lernaVersion,
|
|
5
|
+
nodeVersion,
|
|
6
|
+
norskaThemeDocsVersion,
|
|
7
|
+
norskaVersion,
|
|
8
|
+
yarnVersion,
|
|
9
|
+
} from 'aberlaas-versions';
|
|
10
|
+
import current from '../monorepo.js';
|
|
11
|
+
|
|
12
|
+
describe('init > monorepo', () => {
|
|
13
|
+
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/monorepo'),
|
|
18
|
+
);
|
|
19
|
+
|
|
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');
|
|
23
|
+
});
|
|
24
|
+
afterEach(async () => {
|
|
25
|
+
await remove(helper.hostRoot());
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// WORKSPACES
|
|
29
|
+
describe('createRootWorkspace', () => {
|
|
30
|
+
it.each([
|
|
31
|
+
[
|
|
32
|
+
'should have correct metadata',
|
|
33
|
+
{
|
|
34
|
+
name: 'my-project-monorepo',
|
|
35
|
+
author: 'my-name',
|
|
36
|
+
description: 'my-project monorepo',
|
|
37
|
+
repository: 'my-name/my-project',
|
|
38
|
+
homepage: 'https://projects.pixelastic.com/my-project',
|
|
39
|
+
license: 'MIT',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
'should have root specific data',
|
|
44
|
+
{
|
|
45
|
+
private: true,
|
|
46
|
+
workspaces: ['modules/*'],
|
|
47
|
+
type: 'module',
|
|
48
|
+
packageManager: `yarn@${yarnVersion}`,
|
|
49
|
+
dependencies: {},
|
|
50
|
+
devDependencies: {
|
|
51
|
+
aberlaas: '1.2.3',
|
|
52
|
+
lerna: lernaVersion,
|
|
53
|
+
},
|
|
54
|
+
scripts: {
|
|
55
|
+
build: './scripts/meta/build',
|
|
56
|
+
release: './scripts/meta/release',
|
|
57
|
+
lint: './scripts/meta/lint',
|
|
58
|
+
learn: 'lerna',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
])('%s', async (_title, expected) => {
|
|
63
|
+
await current.createRootWorkspace();
|
|
64
|
+
|
|
65
|
+
const actual = await readJson(helper.hostPath('package.json'));
|
|
66
|
+
|
|
67
|
+
expect(actual).toMatchObject(expected);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('createDocsWorkspace', () => {
|
|
71
|
+
it.each([
|
|
72
|
+
[
|
|
73
|
+
'should have correct metadata',
|
|
74
|
+
{
|
|
75
|
+
name: 'my-project-docs',
|
|
76
|
+
version: '0.0.1',
|
|
77
|
+
author: 'my-name',
|
|
78
|
+
description: 'my-project docs',
|
|
79
|
+
repository: 'my-name/my-project',
|
|
80
|
+
homepage: 'https://projects.pixelastic.com/my-project',
|
|
81
|
+
license: 'MIT',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
'should have docs specific data',
|
|
86
|
+
{
|
|
87
|
+
private: true,
|
|
88
|
+
devDependencies: {},
|
|
89
|
+
dependencies: {
|
|
90
|
+
norska: norskaVersion,
|
|
91
|
+
'norska-theme-docs': norskaThemeDocsVersion,
|
|
92
|
+
},
|
|
93
|
+
scripts: {
|
|
94
|
+
build: '../../scripts/local/build',
|
|
95
|
+
release: '../../scripts/local/release',
|
|
96
|
+
lint: '../../scripts/local/lint',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
])('%s', async (_title, expected) => {
|
|
101
|
+
await current.createDocsWorkspace();
|
|
102
|
+
|
|
103
|
+
const actual = await readJson(
|
|
104
|
+
helper.hostPath('modules/docs/package.json'),
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
expect(actual).toMatchObject(expected);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
describe('createLibWorkspace', () => {
|
|
111
|
+
it.each([
|
|
112
|
+
[
|
|
113
|
+
'should have correct metadata',
|
|
114
|
+
{
|
|
115
|
+
name: 'my-project',
|
|
116
|
+
version: '0.0.1',
|
|
117
|
+
author: 'my-name',
|
|
118
|
+
description: '',
|
|
119
|
+
keywords: [],
|
|
120
|
+
repository: 'my-name/my-project',
|
|
121
|
+
homepage: 'https://projects.pixelastic.com/my-project',
|
|
122
|
+
license: 'MIT',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
[
|
|
126
|
+
'should have lib specific data',
|
|
127
|
+
{
|
|
128
|
+
private: false,
|
|
129
|
+
type: 'module',
|
|
130
|
+
sideEffects: false,
|
|
131
|
+
engines: {
|
|
132
|
+
node: `>=${nodeVersion}`,
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
files: ['*.js'],
|
|
136
|
+
exports: { '.': './main.js' },
|
|
137
|
+
// Some tools have trouble parsing the .exports field, so we keep the
|
|
138
|
+
// .main field for backward compatibility
|
|
139
|
+
main: './main.js',
|
|
140
|
+
|
|
141
|
+
devDependencies: {},
|
|
142
|
+
dependencies: {},
|
|
143
|
+
|
|
144
|
+
scripts: {
|
|
145
|
+
build: '../../scripts/local/build',
|
|
146
|
+
release: '../../scripts/local/release',
|
|
147
|
+
lint: '../../scripts/local/lint',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
])('%s', async (_title, expected) => {
|
|
152
|
+
await current.createLibWorkspace();
|
|
153
|
+
|
|
154
|
+
const actual = await readJson(
|
|
155
|
+
helper.hostPath('modules/lib/package.json'),
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
expect(actual).toMatchObject(expected);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('addLicenseFiles', () => {
|
|
163
|
+
it('creates license file in root and ./lib', async () => {
|
|
164
|
+
await current.addLicenseFiles();
|
|
165
|
+
|
|
166
|
+
expect(await exists(helper.hostPath('LICENSE'))).toBe(true);
|
|
167
|
+
expect(await exists(helper.hostPath('modules/lib/LICENSE'))).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('run', () => {
|
|
172
|
+
it('should build a monorepo structure', async () => {
|
|
173
|
+
await current.run();
|
|
174
|
+
|
|
175
|
+
const actual = await glob('**/*', {
|
|
176
|
+
context: helper.hostPath(),
|
|
177
|
+
absolutePaths: false,
|
|
178
|
+
directories: false,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
expect(actual).toEqual([
|
|
182
|
+
'.circleci/config.yml',
|
|
183
|
+
'.gitattributes',
|
|
184
|
+
'.github/renovate.json',
|
|
185
|
+
'.gitignore',
|
|
186
|
+
'.yarnrc.yml',
|
|
187
|
+
'eslint.config.js',
|
|
188
|
+
'lerna.json',
|
|
189
|
+
'LICENSE',
|
|
190
|
+
'lintstaged.config.js',
|
|
191
|
+
'modules/docs/package.json',
|
|
192
|
+
'modules/lib/__tests__/main.js',
|
|
193
|
+
'modules/lib/LICENSE',
|
|
194
|
+
'modules/lib/main.js',
|
|
195
|
+
'modules/lib/package.json',
|
|
196
|
+
'package.json',
|
|
197
|
+
'prettier.config.js',
|
|
198
|
+
'scripts/hooks/pre-commit',
|
|
199
|
+
'scripts/local/build',
|
|
200
|
+
'scripts/local/build-prod',
|
|
201
|
+
'scripts/local/ci',
|
|
202
|
+
'scripts/local/cms',
|
|
203
|
+
'scripts/local/compress',
|
|
204
|
+
'scripts/local/lint',
|
|
205
|
+
'scripts/local/lint-fix',
|
|
206
|
+
'scripts/local/release',
|
|
207
|
+
'scripts/local/serve',
|
|
208
|
+
'scripts/local/test',
|
|
209
|
+
'scripts/local/test-watch',
|
|
210
|
+
'scripts/meta/build',
|
|
211
|
+
'scripts/meta/build-prod',
|
|
212
|
+
'scripts/meta/ci',
|
|
213
|
+
'scripts/meta/cms',
|
|
214
|
+
'scripts/meta/compress',
|
|
215
|
+
'scripts/meta/lint',
|
|
216
|
+
'scripts/meta/lint-fix',
|
|
217
|
+
'scripts/meta/release',
|
|
218
|
+
'scripts/meta/serve',
|
|
219
|
+
'scripts/meta/test',
|
|
220
|
+
'scripts/meta/test-watch',
|
|
221
|
+
'stylelint.config.js',
|
|
222
|
+
'vite.config.js',
|
|
223
|
+
]);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|