aberlaas 2.9.0 → 2.11.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.
Files changed (70) hide show
  1. package/bin/aberlaas.js +1 -1
  2. package/configs/eslint.js +3 -0
  3. package/configs/lintstaged.js +2 -24
  4. package/configs/prettier.js +3 -4
  5. package/configs/stylelint.js +3 -41
  6. package/configs/vite.js +2 -41
  7. package/{main.js → lib/main.js} +26 -30
  8. package/package.json +37 -45
  9. package/commands/ci/index.js +0 -47
  10. package/commands/compress/dummy.js +0 -11
  11. package/commands/compress/index.js +0 -41
  12. package/commands/compress/png.js +0 -49
  13. package/commands/init/helper.js +0 -192
  14. package/commands/init/index.js +0 -59
  15. package/commands/init/module.js +0 -111
  16. package/commands/init/monorepo.js +0 -261
  17. package/commands/lint/circleci.js +0 -81
  18. package/commands/lint/css.js +0 -73
  19. package/commands/lint/helpers/prettier.js +0 -54
  20. package/commands/lint/index.js +0 -50
  21. package/commands/lint/js.js +0 -73
  22. package/commands/lint/json.js +0 -60
  23. package/commands/lint/yml.js +0 -62
  24. package/commands/precommit/index.js +0 -33
  25. package/commands/readme/index.js +0 -181
  26. package/commands/setup/circleci.js +0 -60
  27. package/commands/setup/github.js +0 -42
  28. package/commands/setup/helpers/circleci.js +0 -43
  29. package/commands/setup/helpers/github.js +0 -72
  30. package/commands/setup/helpers/npm.js +0 -16
  31. package/commands/setup/helpers/ssh.js +0 -77
  32. package/commands/setup/index.js +0 -52
  33. package/commands/setup/renovate.js +0 -54
  34. package/commands/test/index.js +0 -124
  35. package/configs/eslint.cjs +0 -154
  36. package/configs/node.cjs +0 -9
  37. package/configs/vite/test/setupFiles/captureOutput.js +0 -4
  38. package/configs/vite/test/setupFiles/dedent.js +0 -4
  39. package/configs/vite/test/setupFiles/fit-xit-fdescribe-xdescribe.js +0 -13
  40. package/configs/vite/test/setupFiles/jest-extended.js +0 -10
  41. package/configs/vite/test/setupFiles/testName.js +0 -9
  42. package/helper.js +0 -115
  43. package/templates/LICENSE +0 -9
  44. package/templates/_circleci/config.yml +0 -42
  45. package/templates/_eslintignore.conf +0 -12
  46. package/templates/_eslintrc.cjs +0 -3
  47. package/templates/_gitattributes +0 -4
  48. package/templates/_github/README.template.md +0 -7
  49. package/templates/_github/renovate.json +0 -3
  50. package/templates/_gitignore +0 -29
  51. package/templates/_yarnrc.yml +0 -15
  52. package/templates/lerna.json +0 -6
  53. package/templates/lib/__tests__/main.js +0 -13
  54. package/templates/lib/main.js +0 -5
  55. package/templates/lintstaged.config.js +0 -5
  56. package/templates/prettier.config.js +0 -5
  57. package/templates/scripts/ci +0 -6
  58. package/templates/scripts/compress +0 -4
  59. package/templates/scripts/docs/build +0 -4
  60. package/templates/scripts/docs/build-prod +0 -4
  61. package/templates/scripts/docs/cms +0 -4
  62. package/templates/scripts/docs/serve +0 -4
  63. package/templates/scripts/hooks/pre-commit +0 -11
  64. package/templates/scripts/lib/release +0 -5
  65. package/templates/scripts/lib/test +0 -5
  66. package/templates/scripts/lib/test-watch +0 -5
  67. package/templates/scripts/lint +0 -4
  68. package/templates/scripts/lint-fix +0 -4
  69. package/templates/stylelint.config.js +0 -5
  70. package/templates/vite.config.js +0 -5
@@ -1,192 +0,0 @@
1
- import path from 'path';
2
- import Gilmore from 'gilmore';
3
- import { copy, error as firostError, isFile, move, read, write } from 'firost';
4
- import { _ } from 'golgoth';
5
- import helper from '../../helper.js';
6
- import nodeConfig from '../../configs/node.cjs';
7
-
8
- /**
9
- * This hold functions shared for both the monorepo and simple init scenarios
10
- **/
11
- export default {
12
- /**
13
- * Return name of the current project, as the name of the current directory
14
- * @returns {string} Name of the project
15
- **/
16
- getProjectName() {
17
- return path.basename(helper.hostRoot());
18
- },
19
-
20
- /**
21
- * Return the name of the current author based on the GitHub project owner
22
- * @returns {string} Name of the author, or __placeholder__ if undefined
23
- **/
24
- async getProjectAuthor() {
25
- const repo = this.__getRepo();
26
- return (await repo.githubRepoOwner()) || '__placeholder__';
27
- },
28
-
29
- /**
30
- * Copy a config template to the host
31
- * @param {string} source Path to source file, relative to aberlaas
32
- * @param {string} destination Path to destination file, relative to the host
33
- * @returns {boolean} False if can't copy file, true otherwise
34
- **/
35
- async copyToHost(source, destination) {
36
- const absoluteSource = helper.aberlaasPath(source);
37
- const absoluteDestination = helper.hostPath(destination);
38
-
39
- // Source file does not exist
40
- if (!(await isFile(absoluteSource))) {
41
- throw firostError(
42
- 'ERROR_INIT_COPY_FILE',
43
- `Unable to locate ${absoluteSource} file`,
44
- );
45
- }
46
- // Destination file already exist
47
- if (await isFile(absoluteDestination)) {
48
- // Do nothing if content is already the same
49
- const sourceContent = await read(absoluteSource);
50
- const destinationContent = await read(absoluteDestination);
51
- if (sourceContent === destinationContent) {
52
- return true;
53
- }
54
-
55
- // Otherwise create a backup
56
- const backupDestination = `${absoluteDestination}.backup`;
57
- await move(absoluteDestination, backupDestination);
58
- }
59
-
60
- await copy(absoluteSource, absoluteDestination);
61
-
62
- return true;
63
- },
64
-
65
- /**
66
- * Add MIT license file
67
- * @param {string} hostFilepath Path to the LICENSE file, relative to the host
68
- **/
69
- async addLicenseFile(hostFilepath) {
70
- // Start by adding a template
71
- await this.copyToHost('templates/LICENSE', hostFilepath);
72
-
73
- // Replace placeholder with real value
74
- const licensePath = helper.hostPath(hostFilepath);
75
- const author = await this.getProjectAuthor();
76
- const templateContent = await read(licensePath);
77
- const actualContent = _.replace(templateContent, '{author}', author);
78
-
79
- // Write it again
80
- await write(actualContent, licensePath);
81
- },
82
-
83
- /**
84
- * Add CircleCI Config file
85
- **/
86
- async addCircleCIConfigFile() {
87
- const configFilepath = helper.hostPath('./.circleci/config.yml');
88
-
89
- // Start by adding a template
90
- await this.copyToHost('templates/_circleci/config.yml', configFilepath);
91
-
92
- // Replace placeholder with real value
93
- const templateContent = await read(configFilepath);
94
- const actualContent = _.chain(templateContent)
95
- .replace('{nodeVersion}', nodeConfig.nodeVersion)
96
- .replace('{yarnVersion}', nodeConfig.yarnVersion)
97
- .value();
98
-
99
- // Write it again
100
- await write(actualContent, configFilepath);
101
- },
102
-
103
- /**
104
- * Add default script files
105
- **/
106
- async addScripts() {
107
- // Common
108
- await this.copyToHost('templates/scripts/ci', 'scripts/ci');
109
- await this.copyToHost('templates/scripts/compress', 'scripts/compress');
110
- await this.copyToHost('templates/scripts/lint', 'scripts/lint');
111
- await this.copyToHost('templates/scripts/lint-fix', 'scripts/lint-fix');
112
-
113
- // Hooks
114
- await this.copyToHost(
115
- './templates/scripts/hooks/pre-commit',
116
- './scripts/hooks/pre-commit',
117
- );
118
-
119
- // Lib
120
- await this.copyToHost(
121
- 'templates/scripts/lib/release',
122
- 'scripts/lib/release',
123
- );
124
- await this.copyToHost('templates/scripts/lib/test', 'scripts/lib/test');
125
- await this.copyToHost(
126
- 'templates/scripts/lib/test-watch',
127
- 'scripts/lib/test-watch',
128
- );
129
- },
130
-
131
- /**
132
- * Add config files to the host. Each config files reference the default
133
- * aberlaas config for its tool. This pattern allow end-users to use aberlaas
134
- * default rules and overwrite them as they see fit
135
- **/
136
- async addConfigFiles() {
137
- // Git
138
- await this.copyToHost('./templates/_gitignore', './.gitignore');
139
- await this.copyToHost('./templates/_gitattributes', './.gitattributes');
140
-
141
- // Yarn
142
- await this.copyToHost('templates/_yarnrc.yml', '.yarnrc.yml');
143
-
144
- // ESLint
145
- await this.copyToHost('templates/_eslintrc.cjs', '.eslintrc.cjs');
146
- await this.copyToHost('templates/_eslintignore.conf', '.eslintignore');
147
-
148
- // Lint-staged
149
- await this.copyToHost(
150
- 'templates/lintstaged.config.js',
151
- 'lintstaged.config.js',
152
- );
153
-
154
- // Vite
155
- await this.copyToHost('templates/vite.config.js', 'vite.config.js');
156
-
157
- // Prettier
158
- await this.copyToHost('templates/prettier.config.js', 'prettier.config.js');
159
-
160
- // Stylelint
161
- await this.copyToHost(
162
- 'templates/stylelint.config.js',
163
- 'stylelint.config.js',
164
- );
165
-
166
- // Renovate
167
- await this.copyToHost(
168
- 'templates/_github/renovate.json',
169
- '.github/renovate.json',
170
- );
171
-
172
- // CircleCI
173
- await this.copyToHost(
174
- 'templates/_circleci/config.yml',
175
- '.circleci/config.yml',
176
- );
177
- },
178
-
179
- /**
180
- * Add default files required to have the minimum lib module
181
- **/
182
- async addLibFiles() {
183
- await this.copyToHost('templates/lib/main.js', 'lib/main.js');
184
- await this.copyToHost(
185
- 'templates/lib/__tests__/main.js',
186
- 'lib/__tests__/main.js',
187
- );
188
- },
189
- __getRepo() {
190
- return new Gilmore(helper.hostRoot());
191
- },
192
- };
@@ -1,59 +0,0 @@
1
- import { consoleInfo, run, spinner, write } from 'firost';
2
-
3
- import Gilmore from 'gilmore';
4
- import helper from '../../helper.js';
5
- import nodeConfig from '../../configs/node.cjs';
6
- import initMonorepo from './monorepo.js';
7
- import initModule from './module.js';
8
-
9
- export default {
10
- /**
11
- * Configure git hooks to use scripts/hooks instead of .git/hooks
12
- **/
13
- async configureGit() {
14
- const repo = new Gilmore(helper.hostRoot());
15
- await repo.setConfig('core.hooksPath', 'scripts/hooks');
16
- },
17
- /**
18
- * Pin the node version through nvm
19
- **/
20
- async configureNode() {
21
- const nvmrcPath = helper.hostPath('.nvmrc');
22
- await write(nodeConfig.nodeVersion, nvmrcPath);
23
- },
24
- /**
25
- * Run yarn install to install all deps
26
- **/
27
- async yarnInstall() {
28
- await run('yarn install');
29
- },
30
- /**
31
- * Copy all config files and configure the scripts
32
- * @param {object} args Argument object, as passed by minimist
33
- **/
34
- async run(args = {}) {
35
- const isMonorepo = args.monorepo;
36
-
37
- const progress = this.__spinner();
38
-
39
- progress.tick('Configuring Git & Node');
40
- await this.configureGit();
41
- await this.configureNode();
42
-
43
- progress.tick('Adding default files ');
44
-
45
- // Create a different scaffolding based on if creating a monorepo or not
46
- isMonorepo ? await initMonorepo.run() : await initModule.run();
47
-
48
- progress.success('aberlaas project initialized');
49
-
50
- this.__consoleInfo('Synchronizing dependencies');
51
- await this.yarnInstall();
52
-
53
- this.__consoleInfo(
54
- "Don't forget to run aberlaas setup after pushing your repository",
55
- );
56
- },
57
- __consoleInfo: consoleInfo,
58
- __spinner: spinner,
59
- };
@@ -1,111 +0,0 @@
1
- import { readJson, writeJson } from 'firost';
2
-
3
- import helper from '../../helper.js';
4
- import nodeConfig from '../../configs/node.cjs';
5
- import initHelper from './helper.js';
6
-
7
- export default {
8
- /**
9
- * Create the top-level package.json
10
- **/
11
- async createPackageJson() {
12
- // Get language and dependency version
13
- const { version: aberlaasVersion } = await readJson(
14
- helper.aberlaasPath('./package.json'),
15
- );
16
- const { nodeVersion, yarnVersion } = nodeConfig;
17
-
18
- const name = await this.__getProjectName();
19
- const version = '0.0.1';
20
-
21
- const author = await this.__getProjectAuthor();
22
- const description = '';
23
- const keywords = [];
24
- const repository = `${author}/${name}`;
25
- const homepage = `https://projects.pixelastic.com/${name}`;
26
-
27
- const type = 'module';
28
- const license = 'MIT';
29
- const engines = {
30
- node: `>=${nodeVersion}`,
31
- };
32
- const packageManager = `yarn@${yarnVersion}`;
33
-
34
- const files = ['*.js'];
35
- const exports = {
36
- '.': './main.js',
37
- };
38
- const main = './main.js';
39
-
40
- const dependencies = {};
41
- const devDependencies = {
42
- aberlaas: aberlaasVersion,
43
- };
44
-
45
- const scripts = {
46
- // Docs
47
- build: './scripts/docs/build',
48
- 'build:prod': './scripts/docs/build-prod',
49
- cms: './scripts/docs/cms',
50
- serve: './scripts/docs/serve',
51
- // Lib
52
- release: './scripts/lib/release',
53
- test: './scripts/lib/test',
54
- 'test:watch': './scripts/lib/test-watch',
55
- // Common
56
- ci: './scripts/ci',
57
- compress: './scripts/compress',
58
- lint: './scripts/lint',
59
- 'lint:fix': './scripts/lint-fix',
60
- };
61
-
62
- const packageContent = {
63
- // Name and version
64
- name,
65
- version,
66
-
67
- // Metadata
68
- author,
69
- description,
70
- keywords,
71
- repository,
72
- homepage,
73
-
74
- // Compatibility
75
- type,
76
- license,
77
- engines,
78
- packageManager,
79
-
80
- // Exports
81
- files,
82
- exports,
83
- main,
84
-
85
- // Dependencies
86
- dependencies,
87
- devDependencies,
88
-
89
- // Scripts
90
- scripts,
91
- };
92
-
93
- await writeJson(packageContent, helper.hostPath('./package.json'), {
94
- sort: false,
95
- });
96
- },
97
-
98
- /**
99
- * Scaffold a repo for use in a simple module contexte
100
- **/
101
- async run() {
102
- await this.createPackageJson();
103
-
104
- await initHelper.addLicenseFile('LICENSE');
105
- await initHelper.addConfigFiles();
106
- await initHelper.addScripts();
107
- await initHelper.addLibFiles();
108
- },
109
- __getProjectName: initHelper.getProjectName.bind(initHelper),
110
- __getProjectAuthor: initHelper.getProjectAuthor.bind(initHelper),
111
- };
@@ -1,261 +0,0 @@
1
- import { readJson, writeJson } from 'firost';
2
-
3
- import helper from '../../helper.js';
4
- import nodeConfig from '../../configs/node.cjs';
5
- import initHelper from './helper.js';
6
-
7
- export default {
8
- /**
9
- * Create the top-level monorepo root workspace
10
- **/
11
- async createRootWorkspace() {
12
- const aberlaasData = await readJson(helper.aberlaasPath('./package.json'));
13
- const sharedProjectData = await this.getSharedProjectData();
14
-
15
- const packageContent = {
16
- // Visibility
17
- private: true,
18
- workspaces: ['docs', 'lib'],
19
-
20
- // Name and version
21
- name: `${sharedProjectData.name}-monorepo`,
22
- version: '0.0.1',
23
-
24
- // Metadata
25
- author: sharedProjectData.author,
26
- description: `${sharedProjectData.name} monorepo`,
27
- repository: sharedProjectData.repository,
28
- homepage: sharedProjectData.homepage,
29
-
30
- // Compatibility
31
- type: 'module',
32
- license: sharedProjectData.license,
33
- packageManager: `yarn@${nodeConfig.yarnVersion}`,
34
-
35
- // Exports
36
-
37
- // Dependencies
38
- dependencies: {},
39
- devDependencies: {
40
- aberlaas: aberlaasData.version,
41
- lerna: nodeConfig.lernaVersion,
42
- },
43
-
44
- // Scripts
45
- scripts: {
46
- // ==> Docs-specific
47
- build: './scripts/docs/build',
48
- 'build:prod': './scripts/docs/build-prod',
49
- cms: './scripts/docs/cms',
50
- serve: './scripts/docs/serve',
51
- // ==> Lib-specific
52
- release: './scripts/lib/release',
53
- test: './scripts/lib/test',
54
- 'test:watch': './scripts/lib/test-watch',
55
- // Common
56
- ci: './scripts/ci',
57
- compress: './scripts/compress',
58
- lint: './scripts/lint',
59
- 'lint:fix': './scripts/lint-fix',
60
-
61
- // Global (called as aliases from any workspace)
62
- // ==> Docs-specific
63
- 'g:build': './scripts/docs/build',
64
- 'g:build:prod': './scripts/docs/build-prod',
65
- 'g:cms': './scripts/docs/cms',
66
- 'g:serve': './scripts/docs/serve',
67
- // ==> Lib-specific
68
- 'g:release': './scripts/lib/release',
69
- 'g:test': './scripts/lib/test',
70
- 'g:test:watch': './scripts/lib/test-watch',
71
- // Common
72
- 'g:compress': './scripts/compress',
73
- 'g:lint': './scripts/lint',
74
- 'g:lint:fix': './scripts/lint-fix',
75
- },
76
- };
77
- await writeJson(packageContent, helper.hostPath('./package.json'), {
78
- sort: false,
79
- });
80
- },
81
- /**
82
- * Create the docs workspace
83
- **/
84
- async createDocsWorkspace() {
85
- const sharedProjectData = await this.getSharedProjectData();
86
-
87
- const packageContent = {
88
- // Visibility
89
- private: true,
90
-
91
- // Name & Version
92
- name: `${sharedProjectData.name}-docs`,
93
- version: '0.0.1',
94
-
95
- // Metadata
96
- author: sharedProjectData.author,
97
- description: `${sharedProjectData.name} docs`,
98
- repository: sharedProjectData.repository,
99
- homepage: sharedProjectData.homepage,
100
-
101
- // Compatibility
102
- license: sharedProjectData.license,
103
-
104
- // Exports
105
-
106
- // Dependencies
107
- dependencies: {
108
- norska: nodeConfig.norskaVersion,
109
- 'norska-theme-docs': nodeConfig.norskaThemeDocsVersion,
110
- },
111
- devDependencies: {},
112
-
113
- // Scripts
114
- scripts: sharedProjectData.scripts,
115
- };
116
- await writeJson(packageContent, helper.hostPath('./docs/package.json'), {
117
- sort: false,
118
- });
119
- },
120
- /**
121
- * Create the lib workspace
122
- **/
123
- async createLibWorkspace() {
124
- const sharedProjectData = await this.getSharedProjectData();
125
- const engines = {
126
- node: `>=${nodeConfig.nodeVersion}`,
127
- };
128
-
129
- const packageContent = {
130
- // Visibility
131
- private: false,
132
-
133
- // Name and version
134
- name: sharedProjectData.name,
135
- version: '0.0.1',
136
-
137
- // Metadata
138
- author: sharedProjectData.author,
139
- description: '',
140
- keywords: [],
141
- repository: sharedProjectData.repository,
142
- homepage: sharedProjectData.homepage,
143
-
144
- // Compatibility
145
- type: 'module',
146
- license: sharedProjectData.license,
147
- engines,
148
-
149
- // Exports
150
- files: ['*.js'],
151
- exports: {
152
- '.': './main.js',
153
- },
154
- main: './main.js',
155
-
156
- // Dependencies
157
- dependencies: {},
158
- devDependencies: {},
159
-
160
- // Scripts
161
- scripts: sharedProjectData.scripts,
162
- };
163
- await writeJson(packageContent, helper.hostPath('./lib/package.json'), {
164
- sort: false,
165
- });
166
- },
167
- /**
168
- * Add MIT license files to the repository
169
- **/
170
- async addLicenseFiles() {
171
- // One at the repo root, for GitHub
172
- await initHelper.addLicenseFile('LICENSE');
173
- // One in ./lib to be released with the module
174
- await initHelper.addLicenseFile('lib/LICENSE');
175
- },
176
- /**
177
- * Add config files
178
- **/
179
- async addConfigFiles() {
180
- await initHelper.addConfigFiles();
181
-
182
- // Lerna
183
- await initHelper.copyToHost('templates/lerna.json', 'lerna.json');
184
- },
185
- /**
186
- * Add scripts to the repo
187
- **/
188
- async addScripts() {
189
- // Common scripts
190
- await initHelper.addScripts('LICENSE');
191
-
192
- // Docs scripts
193
- await initHelper.copyToHost(
194
- 'templates/scripts/docs/build',
195
- 'scripts/docs/build',
196
- );
197
- await initHelper.copyToHost(
198
- 'templates/scripts/docs/build-prod',
199
- 'scripts/docs/build-prod',
200
- );
201
- await initHelper.copyToHost(
202
- 'templates/scripts/docs/cms',
203
- 'scripts/docs/cms',
204
- );
205
- await initHelper.copyToHost(
206
- 'templates/scripts/docs/serve',
207
- 'scripts/docs/serve',
208
- );
209
- },
210
- /**
211
- * Returns shared project data, like name, author, scripts, etc
212
- * @returns {object} Object of common keys
213
- **/
214
- async getSharedProjectData() {
215
- const name = await this.__getProjectName();
216
- const author = await this.__getProjectAuthor();
217
- const homepage = `https://projects.pixelastic.com/${name}`;
218
- const repository = `${author}/${name}`;
219
- const license = 'MIT';
220
- const scripts = {
221
- // Docs
222
- build: 'ABERLAAS_CWD=$INIT_CWD yarn g:build',
223
- 'build:prod': 'ABERLAAS_CWD=$INIT_CWD yarn g:build:prod',
224
- cms: 'ABERLAAS_CWD=$INIT_CWD yarn g:cms',
225
- serve: 'ABERLAAS_CWD=$INIT_CWD yarn g:serve',
226
-
227
- // Lib
228
- release: 'ABERLAAS_CWD=$INIT_CWD yarn g:release',
229
- test: 'ABERLAAS_CWD=$INIT_CWD yarn g:test',
230
- 'test:watch': 'ABERLAAS_CWD=$INIT_CWD yarn g:test:watch',
231
-
232
- // Common
233
- compress: 'ABERLAAS_CWD=$INIT_CWD yarn g:compress',
234
- lint: 'ABERLAAS_CWD=$INIT_CWD yarn g:lint',
235
- 'lint:fix': 'ABERLAAS_CWD=$INIT_CWD yarn g:lint:fix',
236
- };
237
- return {
238
- author,
239
- homepage,
240
- license,
241
- name,
242
- repository,
243
- scripts,
244
- };
245
- },
246
- /**
247
- * Scaffold a repo for use in a monorepo module contexte
248
- **/
249
- async run() {
250
- await this.createRootWorkspace();
251
- await this.createDocsWorkspace();
252
- await this.createLibWorkspace();
253
-
254
- await this.addLicenseFiles();
255
- await this.addScripts();
256
- await this.addConfigFiles();
257
- await initHelper.addLibFiles();
258
- },
259
- __getProjectName: initHelper.getProjectName,
260
- __getProjectAuthor: initHelper.getProjectAuthor.bind(initHelper),
261
- };
@@ -1,81 +0,0 @@
1
- import ciInfo from 'ci-info';
2
- import { exists, firostError, run, which } from 'firost';
3
- import helper from '../../helper.js';
4
- import lintYml from './yml.js';
5
-
6
- export default {
7
- configPath: '.circleci/config.yml',
8
- /**
9
- * Find all relevant files
10
- * @returns {Array} Array of files
11
- **/
12
- async getInputFiles() {
13
- return await helper.findHostFiles([this.configPath]);
14
- },
15
- /**
16
- * Check if the code is currently running on CircleCI
17
- * @returns {boolean} True if running on CircleCI, false otherwise
18
- **/
19
- isRunningOnCircleCi() {
20
- return ciInfo.CIRCLE;
21
- },
22
- /**
23
- * Check if the circleci binary is available in the $PATH
24
- * @returns {boolean} True if available, false otherwise
25
- **/
26
- async hasCircleCiBin() {
27
- const binary = await which('circleci');
28
- return !!binary;
29
- },
30
- /**
31
- * Validate the CircleCI config file.
32
- * @returns {boolean} True if valid, throws an error if not
33
- **/
34
- async validateConfig() {
35
- await run('circleci config validate', { stdout: false });
36
- },
37
- /**
38
- * Lint the file, both for yml issues and if possible circleci specifics
39
- * @returns {boolean} True on success
40
- **/
41
- async run() {
42
- const absoluteConfigPath = helper.hostPath(this.configPath);
43
- const hasConfigFile = await exists(absoluteConfigPath);
44
- const isRunningOnCircleCi = this.isRunningOnCircleCi();
45
-
46
- // Stop early if no config file, or if running on CircleCI
47
- if (!hasConfigFile || isRunningOnCircleCi) {
48
- return true;
49
- }
50
-
51
- // Lint as yml first
52
- await lintYml.run([absoluteConfigPath]);
53
-
54
- // Stop early if no circleci bin available
55
- if (!(await this.hasCircleCiBin())) {
56
- return true;
57
- }
58
-
59
- // Validate the config
60
- try {
61
- await this.validateConfig();
62
- } catch (error) {
63
- const errorMessage = `CircleCI config error on ${this.configPath}\n${error.message}`;
64
- throw firostError('CircleCiLintError', errorMessage);
65
- }
66
-
67
- return true;
68
- },
69
- /**
70
- * Autofix yml issues in file
71
- * @returns {boolean} True on success
72
- **/
73
- async fix() {
74
- const absoluteConfigPath = helper.hostPath(this.configPath);
75
- // Fix yml issues
76
- await lintYml.fix([absoluteConfigPath]);
77
-
78
- // Check for file errors so it still fails if file is invalid
79
- await this.run();
80
- },
81
- };