aberlaas-init 2.21.1 → 2.22.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.
@@ -0,0 +1,219 @@
1
+ import {
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 {
11
+ nodeVersion,
12
+ norskaThemeDocsVersion,
13
+ norskaVersion,
14
+ yarnVersion,
15
+ } from 'aberlaas-versions';
16
+ import { __ as initHelper } from '../../helper.js';
17
+ import { __, run } from '../libdocs.js';
18
+
19
+ describe('init > libdocs', () => {
20
+ const testDirectory = tmpDirectory('aberlaas/init/libdocs');
21
+ beforeEach(async () => {
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'),
28
+ );
29
+
30
+ vi.spyOn(initHelper, 'getProjectName').mockReturnValue('my-project');
31
+ vi.spyOn(initHelper, 'getProjectAuthor').mockReturnValue('my-name');
32
+ });
33
+ afterEach(async () => {
34
+ await remove(hostGitRoot());
35
+ });
36
+
37
+ // WORKSPACES
38
+ describe('createRootWorkspace', () => {
39
+ it.each([
40
+ [
41
+ 'should have correct metadata',
42
+ {
43
+ name: 'my-project-root',
44
+ author: 'my-name',
45
+ description: 'my-project root workspace',
46
+ repository: 'my-name/my-project',
47
+ homepage: 'https://projects.pixelastic.com/my-project',
48
+ license: 'MIT',
49
+ },
50
+ ],
51
+ [
52
+ 'should have root specific data',
53
+ {
54
+ private: true,
55
+ workspaces: ['docs', 'lib'],
56
+ type: 'module',
57
+ packageManager: `yarn@${yarnVersion}`,
58
+ dependencies: {},
59
+ devDependencies: {
60
+ aberlaas: '1.2.3',
61
+ },
62
+ scripts: {
63
+ build: './scripts/build',
64
+ release: './scripts/release',
65
+ lint: './scripts/lint',
66
+ },
67
+ },
68
+ ],
69
+ ])('%s', async (_title, expected) => {
70
+ await __.createRootWorkspace();
71
+
72
+ const actual = await readJson(hostGitPath('package.json'));
73
+
74
+ expect(actual).toMatchObject(expected);
75
+ });
76
+ });
77
+ describe('createDocsWorkspace', () => {
78
+ it.each([
79
+ [
80
+ 'should have correct metadata',
81
+ {
82
+ name: 'my-project-docs',
83
+ version: '0.0.1',
84
+ author: 'my-name',
85
+ description: 'my-project docs',
86
+ repository: 'my-name/my-project',
87
+ homepage: 'https://projects.pixelastic.com/my-project',
88
+ license: 'MIT',
89
+ },
90
+ ],
91
+ [
92
+ 'should have docs specific data',
93
+ {
94
+ private: true,
95
+ devDependencies: {},
96
+ dependencies: {
97
+ norska: norskaVersion,
98
+ 'norska-theme-docs': norskaThemeDocsVersion,
99
+ },
100
+ scripts: {
101
+ build: 'cd .. && ./scripts/build',
102
+ release: 'cd .. && ./scripts/release',
103
+ lint: 'cd .. && ./scripts/lint',
104
+ },
105
+ },
106
+ ],
107
+ ])('%s', async (_title, expected) => {
108
+ await __.createDocsWorkspace();
109
+
110
+ const actual = await readJson(hostGitPath('docs/package.json'));
111
+
112
+ expect(actual).toMatchObject(expected);
113
+ });
114
+ });
115
+ describe('createLibWorkspace', () => {
116
+ it.each([
117
+ [
118
+ 'should have correct metadata',
119
+ {
120
+ name: 'my-project',
121
+ version: '0.0.1',
122
+ author: 'my-name',
123
+ description: '',
124
+ keywords: [],
125
+ repository: 'my-name/my-project',
126
+ homepage: 'https://projects.pixelastic.com/my-project',
127
+ license: 'MIT',
128
+ },
129
+ ],
130
+ [
131
+ 'should have lib specific data',
132
+ {
133
+ private: false,
134
+ type: 'module',
135
+ sideEffects: false,
136
+ engines: {
137
+ node: `>=${nodeVersion}`,
138
+ },
139
+
140
+ files: ['*.js'],
141
+ exports: { '.': './main.js' },
142
+ // Some tools have trouble parsing the .exports field, so we keep the
143
+ // .main field for backward compatibility
144
+ main: './main.js',
145
+
146
+ devDependencies: {},
147
+ dependencies: {},
148
+
149
+ scripts: {
150
+ build: 'cd .. && ./scripts/build',
151
+ release: 'cd .. && ./scripts/release',
152
+ lint: 'cd .. && ./scripts/lint',
153
+ },
154
+ },
155
+ ],
156
+ ])('%s', async (_title, expected) => {
157
+ await __.createLibWorkspace();
158
+
159
+ const actual = await readJson(hostGitPath('lib/package.json'));
160
+
161
+ expect(actual).toMatchObject(expected);
162
+ });
163
+ });
164
+
165
+ describe('addLicenseFiles', () => {
166
+ it('creates license file in root and ./lib', async () => {
167
+ await __.addLicenseFiles();
168
+
169
+ expect(await exists(hostGitPath('LICENSE'))).toBe(true);
170
+ expect(await exists(hostGitPath('lib/LICENSE'))).toBe(true);
171
+ });
172
+ });
173
+
174
+ describe('run', () => {
175
+ vi.setConfig({ testTimeout: 10_000 });
176
+ it('should build a libdocs structure', async () => {
177
+ await run();
178
+
179
+ const actual = await glob('**/*', {
180
+ cwd: hostGitPath(),
181
+ absolutePaths: false,
182
+ directories: false,
183
+ });
184
+
185
+ expect(actual).toEqual([
186
+ '.circleci/config.yml',
187
+ '.editorconfig',
188
+ '.github/renovate.json',
189
+ '.gitignore',
190
+ '.README.template.md',
191
+ '.yarnrc.yml',
192
+ 'docs/package.json',
193
+ 'eslint.config.js',
194
+ 'lib/__tests__/main.js',
195
+ 'lib/LICENSE',
196
+ 'lib/main.js',
197
+ 'lib/package.json',
198
+ 'LICENSE',
199
+ 'lintstaged.config.js',
200
+ 'package.json',
201
+ 'prettier.config.js',
202
+ 'scripts/build',
203
+ 'scripts/build-prod',
204
+ 'scripts/ci',
205
+ 'scripts/cms',
206
+ 'scripts/compress',
207
+ 'scripts/hooks/pre-commit',
208
+ 'scripts/lint',
209
+ 'scripts/lint-fix',
210
+ 'scripts/release',
211
+ 'scripts/serve',
212
+ 'scripts/test',
213
+ 'scripts/test-watch',
214
+ 'stylelint.config.js',
215
+ 'vite.config.js',
216
+ ]);
217
+ });
218
+ });
219
+ });
@@ -0,0 +1,148 @@
1
+ import { glob, read, readJson, remove, tmpDirectory, writeJson } from 'firost';
2
+ import { hostGitPath, hostGitRoot, mockHelperPaths } from 'aberlaas-helper';
3
+ import { nodeVersion, yarnVersion } from 'aberlaas-versions';
4
+ import { __ as initHelper } from '../../helper.js';
5
+ import { __, run } from '../module.js';
6
+
7
+ describe('init > module', () => {
8
+ const testDirectory = tmpDirectory('aberlaas/init/module');
9
+ beforeEach(async () => {
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'),
16
+ );
17
+
18
+ vi.spyOn(initHelper, 'getProjectName').mockReturnValue('my-project');
19
+ vi.spyOn(initHelper, 'getProjectAuthor').mockReturnValue('my-name');
20
+ });
21
+ afterEach(async () => {
22
+ await remove(hostGitRoot());
23
+ });
24
+
25
+ describe('createPackageJson', () => {
26
+ it.each([
27
+ [
28
+ 'should have correct metadata',
29
+ {
30
+ name: 'my-project',
31
+ version: '0.0.1',
32
+ author: 'my-name',
33
+ description: '',
34
+ keywords: [],
35
+ repository: 'my-name/my-project',
36
+ homepage: 'https://github.com/my-name/my-project',
37
+ },
38
+ ],
39
+ [
40
+ 'should have correct license',
41
+ {
42
+ license: 'MIT',
43
+ },
44
+ ],
45
+ [
46
+ 'should have ESM information',
47
+ {
48
+ type: 'module',
49
+ sideEffects: false,
50
+ },
51
+ ],
52
+ [
53
+ 'should have language and yarn version',
54
+ {
55
+ engines: {
56
+ node: `>=${nodeVersion}`,
57
+ },
58
+ packageManager: `yarn@${yarnVersion}`,
59
+ },
60
+ ],
61
+ [
62
+ 'should export the right files',
63
+ {
64
+ files: ['lib/*.js'],
65
+ exports: { '.': './lib/main.js' },
66
+ main: './lib/main.js',
67
+ },
68
+ ],
69
+ [
70
+ 'should have the right dependencies',
71
+ {
72
+ devDependencies: {
73
+ aberlaas: '1.2.3',
74
+ },
75
+ dependencies: {},
76
+ },
77
+ ],
78
+ [
79
+ 'should have scripts',
80
+ {
81
+ scripts: {
82
+ release: './scripts/release',
83
+ test: './scripts/test',
84
+ lint: './scripts/lint',
85
+ },
86
+ },
87
+ ],
88
+ ])('%s', async (_title, expected) => {
89
+ await __.createPackageJson();
90
+
91
+ const actual = await readJson(hostGitPath('package.json'));
92
+
93
+ expect(actual).toMatchObject(expected);
94
+ });
95
+ });
96
+
97
+ describe('run', () => {
98
+ it('should build a module structure', async () => {
99
+ await run();
100
+
101
+ const actual = await glob('**/*', {
102
+ cwd: hostGitPath(),
103
+ absolutePaths: false,
104
+ directories: false,
105
+ });
106
+
107
+ expect(actual).toEqual([
108
+ '.circleci/config.yml',
109
+ '.editorconfig',
110
+ '.github/renovate.json',
111
+ '.gitignore',
112
+ '.README.template.md',
113
+ '.yarnrc.yml',
114
+ 'eslint.config.js',
115
+ 'lib/__tests__/main.js',
116
+ 'lib/main.js',
117
+ 'LICENSE',
118
+ 'lintstaged.config.js',
119
+ 'package.json',
120
+ 'prettier.config.js',
121
+ 'scripts/ci',
122
+ 'scripts/compress',
123
+ 'scripts/hooks/pre-commit',
124
+ 'scripts/lint',
125
+ 'scripts/lint-fix',
126
+ 'scripts/release',
127
+ 'scripts/test',
128
+ 'scripts/test-watch',
129
+ 'stylelint.config.js',
130
+ 'vite.config.js',
131
+ ]);
132
+ });
133
+
134
+ it('should write a correct circleCI file', async () => {
135
+ await run();
136
+
137
+ const circleciConfig = await read(hostGitPath('.circleci/config.yml'));
138
+
139
+ // Should not contain literal template placeholders
140
+ expect(circleciConfig).not.toContain('{nodeVersion}');
141
+ expect(circleciConfig).not.toContain('{yarnVersion}');
142
+
143
+ // Should contain actual versions
144
+ expect(circleciConfig).toContain(`cimg/node:${nodeVersion}`);
145
+ expect(circleciConfig).toContain(`yarn set version ${yarnVersion}`);
146
+ });
147
+ });
148
+ });
@@ -0,0 +1,218 @@
1
+ import {
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 {
11
+ nodeVersion,
12
+ norskaThemeDocsVersion,
13
+ norskaVersion,
14
+ yarnVersion,
15
+ } from 'aberlaas-versions';
16
+ import { __ as initHelper } from '../../helper.js';
17
+ import { __, run } from '../monorepo.js';
18
+
19
+ describe('init > monorepo', () => {
20
+ const testDirectory = tmpDirectory('aberlaas/init/monorepo');
21
+ beforeEach(async () => {
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'),
28
+ );
29
+
30
+ vi.spyOn(initHelper, 'getProjectName').mockReturnValue('my-project');
31
+ vi.spyOn(initHelper, 'getProjectAuthor').mockReturnValue('my-name');
32
+ });
33
+ afterEach(async () => {
34
+ await remove(hostGitRoot());
35
+ });
36
+
37
+ // WORKSPACES
38
+ describe('createRootWorkspace', () => {
39
+ it.each([
40
+ [
41
+ 'should have correct metadata',
42
+ {
43
+ name: 'my-project-monorepo',
44
+ author: 'my-name',
45
+ description: 'my-project monorepo',
46
+ repository: 'my-name/my-project',
47
+ homepage: 'https://projects.pixelastic.com/my-project',
48
+ license: 'MIT',
49
+ },
50
+ ],
51
+ [
52
+ 'should have root specific data',
53
+ {
54
+ private: true,
55
+ workspaces: ['modules/*'],
56
+ type: 'module',
57
+ packageManager: `yarn@${yarnVersion}`,
58
+ dependencies: {},
59
+ devDependencies: {
60
+ aberlaas: '1.2.3',
61
+ },
62
+ scripts: {
63
+ build: './scripts/build',
64
+ release: './scripts/release',
65
+ lint: './scripts/lint',
66
+ },
67
+ },
68
+ ],
69
+ ])('%s', async (_title, expected) => {
70
+ await __.createRootWorkspace();
71
+
72
+ const actual = await readJson(hostGitPath('package.json'));
73
+
74
+ expect(actual).toMatchObject(expected);
75
+ });
76
+ });
77
+ describe('createDocsWorkspace', () => {
78
+ it.each([
79
+ [
80
+ 'should have correct metadata',
81
+ {
82
+ name: 'my-project-docs',
83
+ version: '0.0.1',
84
+ author: 'my-name',
85
+ description: 'my-project docs',
86
+ repository: 'my-name/my-project',
87
+ homepage: 'https://projects.pixelastic.com/my-project',
88
+ license: 'MIT',
89
+ },
90
+ ],
91
+ [
92
+ 'should have docs specific data',
93
+ {
94
+ private: true,
95
+ devDependencies: {},
96
+ dependencies: {
97
+ norska: norskaVersion,
98
+ 'norska-theme-docs': norskaThemeDocsVersion,
99
+ },
100
+ scripts: {
101
+ build: 'cd ../.. && ./scripts/build',
102
+ release: 'cd ../.. && ./scripts/release',
103
+ lint: 'cd ../.. && ./scripts/lint',
104
+ },
105
+ },
106
+ ],
107
+ ])('%s', async (_title, expected) => {
108
+ await __.createDocsWorkspace();
109
+
110
+ const actual = await readJson(hostGitPath('modules/docs/package.json'));
111
+
112
+ expect(actual).toMatchObject(expected);
113
+ });
114
+ });
115
+ describe('createLibWorkspace', () => {
116
+ it.each([
117
+ [
118
+ 'should have correct metadata',
119
+ {
120
+ name: 'my-project',
121
+ version: '0.0.1',
122
+ author: 'my-name',
123
+ description: '',
124
+ keywords: [],
125
+ repository: 'my-name/my-project',
126
+ homepage: 'https://projects.pixelastic.com/my-project',
127
+ license: 'MIT',
128
+ },
129
+ ],
130
+ [
131
+ 'should have lib specific data',
132
+ {
133
+ private: false,
134
+ type: 'module',
135
+ sideEffects: false,
136
+ engines: {
137
+ node: `>=${nodeVersion}`,
138
+ },
139
+
140
+ files: ['*.js'],
141
+ exports: { '.': './main.js' },
142
+ // Some tools have trouble parsing the .exports field, so we keep the
143
+ // .main field for backward compatibility
144
+ main: './main.js',
145
+
146
+ devDependencies: {},
147
+ dependencies: {},
148
+
149
+ scripts: {
150
+ build: 'cd ../.. && ./scripts/build',
151
+ release: 'cd ../.. && ./scripts/release',
152
+ lint: 'cd ../.. && ./scripts/lint',
153
+ },
154
+ },
155
+ ],
156
+ ])('%s', async (_title, expected) => {
157
+ await __.createLibWorkspace();
158
+
159
+ const actual = await readJson(hostGitPath('modules/lib/package.json'));
160
+
161
+ expect(actual).toMatchObject(expected);
162
+ });
163
+ });
164
+
165
+ describe('addLicenseFiles', () => {
166
+ it('creates license file in root and ./lib', async () => {
167
+ await __.addLicenseFiles();
168
+
169
+ expect(await exists(hostGitPath('LICENSE'))).toBe(true);
170
+ expect(await exists(hostGitPath('modules/lib/LICENSE'))).toBe(true);
171
+ });
172
+ });
173
+
174
+ describe('run', () => {
175
+ it('should build a monorepo structure', async () => {
176
+ await run();
177
+
178
+ const actual = await glob('**/*', {
179
+ cwd: hostGitPath(),
180
+ absolutePaths: false,
181
+ directories: false,
182
+ });
183
+
184
+ expect(actual).toEqual([
185
+ '.circleci/config.yml',
186
+ '.editorconfig',
187
+ '.github/renovate.json',
188
+ '.gitignore',
189
+ '.README.template.md',
190
+ '.yarnrc.yml',
191
+ 'eslint.config.js',
192
+ 'LICENSE',
193
+ 'lintstaged.config.js',
194
+ 'modules/docs/package.json',
195
+ 'modules/lib/__tests__/main.js',
196
+ 'modules/lib/LICENSE',
197
+ 'modules/lib/main.js',
198
+ 'modules/lib/package.json',
199
+ 'package.json',
200
+ 'prettier.config.js',
201
+ 'scripts/build',
202
+ 'scripts/build-prod',
203
+ 'scripts/ci',
204
+ 'scripts/cms',
205
+ 'scripts/compress',
206
+ 'scripts/hooks/pre-commit',
207
+ 'scripts/lint',
208
+ 'scripts/lint-fix',
209
+ 'scripts/release',
210
+ 'scripts/serve',
211
+ 'scripts/test',
212
+ 'scripts/test-watch',
213
+ 'stylelint.config.js',
214
+ 'vite.config.js',
215
+ ]);
216
+ });
217
+ });
218
+ });
@@ -0,0 +1,234 @@
1
+ import { writeJson } from 'firost';
2
+ import { hostGitPath } from 'aberlaas-helper';
3
+ import {
4
+ nodeVersion,
5
+ norskaThemeDocsVersion,
6
+ norskaVersion,
7
+ yarnVersion,
8
+ } from 'aberlaas-versions';
9
+ import {
10
+ addConfigFiles,
11
+ addDefaultScripts,
12
+ addDocsScripts,
13
+ addLibFiles,
14
+ addLicenseFile,
15
+ getAberlaasVersion,
16
+ getProjectAuthor,
17
+ getProjectName,
18
+ } from '../helper.js';
19
+
20
+ export let __;
21
+
22
+ /**
23
+ * Scaffold a repo:
24
+ * - As a monorepo
25
+ * - With ./libs and ./docs subfolders
26
+ */
27
+ export async function run() {
28
+ await __.createRootWorkspace();
29
+ await __.createDocsWorkspace();
30
+ await __.createLibWorkspace();
31
+ await __.addLicenseFiles();
32
+
33
+ await addConfigFiles();
34
+ await addDefaultScripts();
35
+ await addDocsScripts();
36
+ await addLibFiles();
37
+ }
38
+
39
+ __ = {
40
+ // Public methods
41
+
42
+ /**
43
+ * Create the top-level workspace
44
+ */
45
+ async createRootWorkspace() {
46
+ const aberlaasVersion = await getAberlaasVersion();
47
+ const sharedProjectData = await __.getSharedProjectData();
48
+ const engines = {
49
+ node: `>=${nodeVersion}`,
50
+ };
51
+
52
+ const packageContent = {
53
+ // Name and version
54
+ name: `${sharedProjectData.name}-root`,
55
+
56
+ // Visibility
57
+ private: true,
58
+ workspaces: ['docs', 'lib'],
59
+
60
+ // Metadata
61
+ author: sharedProjectData.author,
62
+ description: `${sharedProjectData.name} root workspace`,
63
+ repository: sharedProjectData.repository,
64
+ homepage: sharedProjectData.homepage,
65
+
66
+ // Compatibility
67
+ type: 'module',
68
+ license: sharedProjectData.license,
69
+ engines,
70
+ packageManager: `yarn@${yarnVersion}`,
71
+
72
+ // Dependencies
73
+ dependencies: {},
74
+ devDependencies: {
75
+ aberlaas: aberlaasVersion,
76
+ },
77
+
78
+ // Scripts
79
+ scripts: {
80
+ // Docs
81
+ build: './scripts/build',
82
+ 'build:prod': './scripts/build-prod',
83
+ cms: './scripts/cms',
84
+ serve: './scripts/serve',
85
+
86
+ // Lib
87
+ release: './scripts/release',
88
+ test: './scripts/test',
89
+ 'test:watch': './scripts/test-watch',
90
+ ci: './scripts/ci',
91
+ compress: './scripts/compress',
92
+ lint: './scripts/lint',
93
+ 'lint:fix': './scripts/lint-fix',
94
+ },
95
+ };
96
+ await writeJson(packageContent, hostGitPath('./package.json'), {
97
+ sort: false,
98
+ });
99
+ },
100
+
101
+ /**
102
+ * Create the docs workspace
103
+ */
104
+ async createDocsWorkspace() {
105
+ const sharedProjectData = await __.getSharedProjectData();
106
+
107
+ const packageContent = {
108
+ // Name & Version
109
+ name: `${sharedProjectData.name}-docs`,
110
+ version: '0.0.1',
111
+
112
+ // Visibility
113
+ private: true,
114
+
115
+ // Metadata
116
+ author: sharedProjectData.author,
117
+ description: `${sharedProjectData.name} docs`,
118
+ repository: sharedProjectData.repository,
119
+ homepage: sharedProjectData.homepage,
120
+
121
+ // Compatibility
122
+ license: sharedProjectData.license,
123
+
124
+ // Dependencies
125
+ dependencies: {
126
+ norska: norskaVersion,
127
+ 'norska-theme-docs': norskaThemeDocsVersion,
128
+ },
129
+ devDependencies: {},
130
+
131
+ // Scripts
132
+ scripts: sharedProjectData.scripts,
133
+ };
134
+ await writeJson(packageContent, hostGitPath('./docs/package.json'), {
135
+ sort: false,
136
+ });
137
+ },
138
+
139
+ /**
140
+ * Create the lib workspace
141
+ */
142
+ async createLibWorkspace() {
143
+ const sharedProjectData = await __.getSharedProjectData();
144
+ const engines = {
145
+ node: `>=${nodeVersion}`,
146
+ };
147
+
148
+ const packageContent = {
149
+ // Name and version
150
+ name: sharedProjectData.name,
151
+ version: '0.0.1',
152
+
153
+ // Visibility
154
+ private: false,
155
+
156
+ // Metadata
157
+ author: sharedProjectData.author,
158
+ description: '',
159
+ keywords: [],
160
+ repository: sharedProjectData.repository,
161
+ homepage: sharedProjectData.homepage,
162
+
163
+ // Compatibility
164
+ type: 'module',
165
+ sideEffects: false,
166
+ license: sharedProjectData.license,
167
+ engines,
168
+
169
+ // Exports
170
+ files: ['*.js'],
171
+ exports: {
172
+ '.': './main.js',
173
+ },
174
+ main: './main.js',
175
+
176
+ // Dependencies
177
+ dependencies: {},
178
+ devDependencies: {},
179
+
180
+ // Scripts
181
+ scripts: sharedProjectData.scripts,
182
+ };
183
+ await writeJson(packageContent, hostGitPath('./lib/package.json'), {
184
+ sort: false,
185
+ });
186
+ },
187
+
188
+ /**
189
+ * Add MIT license files to the repository
190
+ */
191
+ async addLicenseFiles() {
192
+ // One at the repo root, for GitHub
193
+ await addLicenseFile('LICENSE');
194
+ // One in ./lib to be released with the module
195
+ await addLicenseFile('lib/LICENSE');
196
+ },
197
+
198
+ /**
199
+ * Returns shared project data, like name, author, scripts, etc
200
+ * @returns {object} Object of common keys
201
+ */
202
+ async getSharedProjectData() {
203
+ const name = await getProjectName();
204
+ const author = await getProjectAuthor();
205
+ const homepage = `https://projects.pixelastic.com/${name}`;
206
+ const repository = `${author}/${name}`;
207
+ const license = 'MIT';
208
+ const scripts = {
209
+ build: 'cd .. && ./scripts/build',
210
+ 'build:prod': 'cd .. && ./scripts/build-prod',
211
+ cms: 'cd .. && ./scripts/cms',
212
+ serve: 'cd .. && ./scripts/serve',
213
+ ci: 'cd .. && ./scripts/ci',
214
+ release: 'cd .. && ./scripts/release',
215
+ test: 'cd .. && ./scripts/test',
216
+ 'test:watch': 'cd .. && ./scripts/test-watch',
217
+ compress: 'cd .. && ./scripts/compress',
218
+ lint: 'cd .. && ./scripts/lint',
219
+ 'lint:fix': 'cd .. && ./scripts/lint-fix',
220
+ };
221
+ return {
222
+ author,
223
+ homepage,
224
+ license,
225
+ name,
226
+ repository,
227
+ scripts,
228
+ };
229
+ },
230
+ };
231
+
232
+ export default {
233
+ run,
234
+ };
@@ -0,0 +1,113 @@
1
+ import { writeJson } from 'firost';
2
+ import { hostGitPath } from 'aberlaas-helper';
3
+ import { nodeVersion, yarnVersion } from 'aberlaas-versions';
4
+ import {
5
+ addConfigFiles,
6
+ addDefaultScripts,
7
+ addLibFiles,
8
+ addLicenseFile,
9
+ getAberlaasVersion,
10
+ getProjectAuthor,
11
+ getProjectName,
12
+ } from '../helper.js';
13
+
14
+ export let __;
15
+
16
+ /**
17
+ * Scaffold a repo:
18
+ * - With ./lib holding the code
19
+ */
20
+ export async function run() {
21
+ await __.createPackageJson();
22
+
23
+ await addLicenseFile('LICENSE');
24
+ await addConfigFiles();
25
+ await addDefaultScripts();
26
+ await addLibFiles();
27
+ }
28
+
29
+ __ = {
30
+ /**
31
+ * Create the package.json
32
+ */
33
+ async createPackageJson() {
34
+ const aberlaasVersion = await getAberlaasVersion();
35
+ const name = await getProjectName();
36
+ const version = '0.0.1';
37
+
38
+ const author = await getProjectAuthor();
39
+ const description = '';
40
+ const keywords = [];
41
+ const repository = `${author}/${name}`;
42
+ const homepage = `https://github.com/${repository}`;
43
+
44
+ const type = 'module';
45
+ const sideEffects = false;
46
+ const license = 'MIT';
47
+ const engines = {
48
+ node: `>=${nodeVersion}`,
49
+ };
50
+ const packageManager = `yarn@${yarnVersion}`;
51
+
52
+ const files = ['lib/*.js'];
53
+ const exports = {
54
+ '.': './lib/main.js',
55
+ };
56
+ const main = './lib/main.js';
57
+
58
+ const dependencies = {};
59
+ const devDependencies = {
60
+ aberlaas: aberlaasVersion,
61
+ };
62
+
63
+ const scripts = {
64
+ ci: './scripts/ci',
65
+ compress: './scripts/compress',
66
+ lint: './scripts/lint',
67
+ 'lint:fix': './scripts/lint-fix',
68
+ test: './scripts/test',
69
+ 'test:watch': './scripts/test-watch',
70
+ release: './scripts/release',
71
+ };
72
+
73
+ const packageContent = {
74
+ // Name and version
75
+ name,
76
+ version,
77
+
78
+ // Metadata
79
+ author,
80
+ description,
81
+ keywords,
82
+ repository,
83
+ homepage,
84
+
85
+ // Compatibility
86
+ type,
87
+ sideEffects,
88
+ license,
89
+ engines,
90
+ packageManager,
91
+
92
+ // Exports
93
+ files,
94
+ exports,
95
+ main,
96
+
97
+ // Dependencies
98
+ dependencies,
99
+ devDependencies,
100
+
101
+ // Scripts
102
+ scripts,
103
+ };
104
+
105
+ await writeJson(packageContent, hostGitPath('./package.json'), {
106
+ sort: false,
107
+ });
108
+ },
109
+ };
110
+
111
+ export default {
112
+ run,
113
+ };
@@ -0,0 +1,241 @@
1
+ import { writeJson } from 'firost';
2
+ import { hostGitPath } from 'aberlaas-helper';
3
+ import {
4
+ nodeVersion,
5
+ norskaThemeDocsVersion,
6
+ norskaVersion,
7
+ yarnVersion,
8
+ } from 'aberlaas-versions';
9
+ import {
10
+ addConfigFiles,
11
+ addDefaultScripts,
12
+ addDocsScripts,
13
+ addLibFiles,
14
+ addLicenseFile,
15
+ getAberlaasVersion,
16
+ getProjectAuthor,
17
+ getProjectName,
18
+ } from '../helper.js';
19
+
20
+ export let __;
21
+
22
+ /**
23
+ * Scaffold a repo:
24
+ * - As a monorepo
25
+ * - With ./libs and ./docs subfolders
26
+ */
27
+ export async function run() {
28
+ await __.createRootWorkspace();
29
+ await __.createDocsWorkspace();
30
+ await __.createLibWorkspace();
31
+ await __.addLicenseFiles();
32
+
33
+ await addConfigFiles();
34
+ await addDefaultScripts();
35
+ await addDocsScripts();
36
+ await addLibFiles('./modules/lib');
37
+ }
38
+
39
+ __ = {
40
+ // Public methods
41
+
42
+ /**
43
+ * Scaffold a repo:
44
+ * - As a monorepo
45
+ * - With ./modules holding all modules, including ./lib and ./docs
46
+ */
47
+ async createRootWorkspace() {
48
+ const aberlaasVersion = await getAberlaasVersion();
49
+ const sharedProjectData = await __.getSharedProjectData();
50
+ const engines = {
51
+ node: `>=${nodeVersion}`,
52
+ };
53
+
54
+ const packageContent = {
55
+ // Name and version
56
+ name: `${sharedProjectData.name}-monorepo`,
57
+
58
+ // Visibility
59
+ private: true,
60
+ workspaces: ['modules/*'],
61
+
62
+ // Metadata
63
+ author: sharedProjectData.author,
64
+ description: `${sharedProjectData.name} monorepo`,
65
+ repository: sharedProjectData.repository,
66
+ homepage: sharedProjectData.homepage,
67
+
68
+ // Compatibility
69
+ type: 'module',
70
+ license: sharedProjectData.license,
71
+ engines,
72
+ packageManager: `yarn@${yarnVersion}`,
73
+
74
+ // Dependencies
75
+ dependencies: {},
76
+ devDependencies: {
77
+ aberlaas: aberlaasVersion,
78
+ },
79
+
80
+ // Scripts
81
+ scripts: {
82
+ // Docs
83
+ build: './scripts/build',
84
+ 'build:prod': './scripts/build-prod',
85
+ cms: './scripts/cms',
86
+ serve: './scripts/serve',
87
+
88
+ // Lib
89
+ release: './scripts/release',
90
+ test: './scripts/test',
91
+ 'test:watch': './scripts/test-watch',
92
+ ci: './scripts/ci',
93
+ compress: './scripts/compress',
94
+ lint: './scripts/lint',
95
+ 'lint:fix': './scripts/lint-fix',
96
+ },
97
+ };
98
+ await writeJson(packageContent, hostGitPath('./package.json'), {
99
+ sort: false,
100
+ });
101
+ },
102
+
103
+ /**
104
+ * Create the docs workspace
105
+ */
106
+ async createDocsWorkspace() {
107
+ const sharedProjectData = await __.getSharedProjectData();
108
+
109
+ const packageContent = {
110
+ // Name & Version
111
+ name: `${sharedProjectData.name}-docs`,
112
+ version: '0.0.1',
113
+
114
+ // Visibility
115
+ private: true,
116
+
117
+ // Metadata
118
+ author: sharedProjectData.author,
119
+ description: `${sharedProjectData.name} docs`,
120
+ repository: sharedProjectData.repository,
121
+ homepage: sharedProjectData.homepage,
122
+
123
+ // Compatibility
124
+ // "type": "module", // TODO: Uncomment once norska is ESM-compliant
125
+ license: sharedProjectData.license,
126
+
127
+ // Dependencies
128
+ dependencies: {
129
+ norska: norskaVersion,
130
+ 'norska-theme-docs': norskaThemeDocsVersion,
131
+ },
132
+ devDependencies: {},
133
+
134
+ // Scripts
135
+ scripts: sharedProjectData.scripts,
136
+ };
137
+ await writeJson(
138
+ packageContent,
139
+ hostGitPath('./modules/docs/package.json'),
140
+ {
141
+ sort: false,
142
+ },
143
+ );
144
+ },
145
+
146
+ /**
147
+ * Create the lib workspace
148
+ */
149
+ async createLibWorkspace() {
150
+ const sharedProjectData = await __.getSharedProjectData();
151
+ const engines = {
152
+ node: `>=${nodeVersion}`,
153
+ };
154
+
155
+ const packageContent = {
156
+ // Name and version
157
+ name: sharedProjectData.name,
158
+ version: '0.0.1',
159
+
160
+ // Visibility
161
+ private: false,
162
+
163
+ // Metadata
164
+ author: sharedProjectData.author,
165
+ description: '',
166
+ keywords: [],
167
+ repository: sharedProjectData.repository,
168
+ homepage: sharedProjectData.homepage,
169
+
170
+ // Compatibility
171
+ type: 'module',
172
+ sideEffects: false,
173
+ license: sharedProjectData.license,
174
+ engines,
175
+
176
+ // Exports
177
+ files: ['*.js'],
178
+ exports: {
179
+ '.': './main.js',
180
+ },
181
+ main: './main.js',
182
+
183
+ // Dependencies
184
+ dependencies: {},
185
+ devDependencies: {},
186
+
187
+ // Scripts
188
+ scripts: sharedProjectData.scripts,
189
+ };
190
+ await writeJson(packageContent, hostGitPath('./modules/lib/package.json'), {
191
+ sort: false,
192
+ });
193
+ },
194
+
195
+ /**
196
+ * Add MIT license files to the repository
197
+ */
198
+ async addLicenseFiles() {
199
+ // One at the repo root, for GitHub
200
+ await addLicenseFile('LICENSE');
201
+ // One in ./lib to be released with the module
202
+ await addLicenseFile('modules/lib/LICENSE');
203
+ },
204
+
205
+ /**
206
+ * Returns shared project data, like name, author, scripts, etc
207
+ * @returns {object} Object of common keys
208
+ */
209
+ async getSharedProjectData() {
210
+ const name = await getProjectName();
211
+ const author = await getProjectAuthor();
212
+ const homepage = `https://projects.pixelastic.com/${name}`;
213
+ const repository = `${author}/${name}`;
214
+ const license = 'MIT';
215
+ const scripts = {
216
+ build: 'cd ../.. && ./scripts/build',
217
+ 'build:prod': 'cd ../.. && ./scripts/build-prod',
218
+ cms: 'cd ../.. && ./scripts/cms',
219
+ serve: 'cd ../.. && ./scripts/serve',
220
+ ci: 'cd ../.. && ./scripts/ci',
221
+ release: 'cd ../.. && ./scripts/release',
222
+ test: 'cd ../.. && ./scripts/test',
223
+ 'test:watch': 'cd ../.. && ./scripts/test-watch',
224
+ compress: 'cd ../.. && ./scripts/compress',
225
+ lint: 'cd ../.. && ./scripts/lint',
226
+ 'lint:fix': 'cd ../.. && ./scripts/lint-fix',
227
+ };
228
+ return {
229
+ author,
230
+ homepage,
231
+ license,
232
+ name,
233
+ repository,
234
+ scripts,
235
+ };
236
+ },
237
+ };
238
+
239
+ export default {
240
+ run,
241
+ };
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
1
  {
2
2
  "name": "aberlaas-init",
3
+ "version": "2.22.0",
3
4
  "type": "module",
4
- "sideEffects": false,
5
5
  "description": "aberlaas init command: Setup the repository with all needed config",
6
- "version": "2.21.1",
7
- "repository": "pixelastic/aberlaas",
6
+ "author": "Tim Carry <tim@pixelastic.com>",
8
7
  "homepage": "https://projects.pixelastic.com/aberlaas/",
9
- "author": "Tim Carry (@pixelastic)",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/pixelastic/aberlaas"
11
+ },
12
+ "sideEffects": false,
10
13
  "license": "MIT",
11
14
  "files": [
12
15
  "lib/*.js",
13
- "lib/layouts/",
14
- "templates/"
16
+ "lib/layouts/**/*",
17
+ "templates/**/*"
15
18
  ],
16
19
  "exports": {
17
20
  ".": "./lib/main.js"
18
21
  },
19
22
  "main": "./lib/main.js",
20
- "engines": {
21
- "node": ">=18.18.0"
22
- },
23
23
  "dependencies": {
24
- "aberlaas-helper": "2.21.1",
25
- "aberlaas-versions": "2.21.1",
24
+ "aberlaas-helper": "2.22.0",
25
+ "aberlaas-versions": "2.22.0",
26
26
  "firost": "5.5.1",
27
27
  "gilmore": "1.2.0",
28
28
  "golgoth": "3.1.0"
@@ -31,13 +31,13 @@
31
31
  "build": "cd ../docs && yarn run build",
32
32
  "build:prod": "cd ../docs && yarn run build:prod",
33
33
  "cms": "cd ../docs && yarn run cms",
34
- "serve": "cd ../docs && yarn run serve",
35
- "release": "cd ../.. && ./scripts/release",
36
- "test:meta": "cd ../.. && ./scripts/test-meta",
37
- "test": "cd ../.. && ./scripts/test",
38
- "test:watch": "cd ../.. && ./scripts/test-watch",
39
34
  "compress": "cd ../.. && ./scripts/compress",
40
35
  "lint": "cd ../.. && ./scripts/lint",
41
- "lint:fix": "cd ../.. && ./scripts/lint-fix"
36
+ "lint:fix": "cd ../.. && ./scripts/lint-fix",
37
+ "release": "cd ../.. && ./scripts/release",
38
+ "serve": "cd ../docs && yarn run serve",
39
+ "test": "cd ../.. && ./scripts/test",
40
+ "test:meta": "cd ../.. && ./scripts/test-meta",
41
+ "test:watch": "cd ../.. && ./scripts/test-watch"
42
42
  }
43
43
  }