aberlaas-setup 2.18.1 → 2.20.2

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/circleci.js CHANGED
@@ -3,39 +3,42 @@ import { consoleError, consoleInfo, consoleSuccess } from 'firost';
3
3
  import circleCiHelper from './helpers/circleci.js';
4
4
  import githubHelper from './helpers/github.js';
5
5
 
6
- export default {
7
- /**
8
- * Attempt to automatically follow the repo in CircleCI if possible, otherwise
9
- * display the link to follow it manually
10
- * @returns {boolean} True if enabled, false otherwise
11
- */
12
- async enable() {
13
- const { username, repo } = await githubHelper.repoData();
14
- const projectUrl = `https://app.circleci.com/pipelines/github/${username}/${repo}`;
6
+ export let __;
15
7
 
16
- // Fail early if no token available
17
- if (!circleCiHelper.hasToken()) {
18
- this.__consoleError(
19
- 'CircleCI: ABERLAAS_CIRCLECI_TOKEN environment variable must be set',
20
- );
21
- this.__consoleInfo(' Create a token at CircleCI account settings');
22
- this.__consoleInfo(' https://circleci.com/account/api\n');
23
- return false;
24
- }
8
+ /**
9
+ * Attempt to automatically follow the repo in CircleCI if possible, otherwise
10
+ * display the link to follow it manually
11
+ * @returns {boolean} True if enabled, false otherwise
12
+ */
13
+ export async function enable() {
14
+ const { username, repo } = await githubHelper.repoData();
15
+ const projectUrl = `https://app.circleci.com/pipelines/github/${username}/${repo}`;
25
16
 
26
- // Do nothing if already enabled
27
- if (await this.isEnabled()) {
28
- this.__consoleSuccess('CircleCI: Already configured');
29
- this.__consoleInfo(` ${projectUrl}\n`);
30
- return true;
31
- }
17
+ // Fail early if no token available
18
+ if (!circleCiHelper.hasToken()) {
19
+ __.consoleError(
20
+ 'CircleCI: ABERLAAS_CIRCLECI_TOKEN environment variable must be set',
21
+ );
22
+ __.consoleInfo(' Create a token at CircleCI account settings');
23
+ __.consoleInfo(' https://circleci.com/account/api\n');
24
+ return false;
25
+ }
32
26
 
33
- // Follow the repo
34
- await this.followRepo();
35
- this.__consoleSuccess('CircleCI: Repository configured');
36
- this.__consoleInfo(` ${projectUrl}\n`);
27
+ // Do nothing if already enabled
28
+ if (await __.isEnabled()) {
29
+ __.consoleSuccess('CircleCI: Already configured');
30
+ __.consoleInfo(` ${projectUrl}\n`);
37
31
  return true;
38
- },
32
+ }
33
+
34
+ // Follow the repo
35
+ await __.followRepo();
36
+ __.consoleSuccess('CircleCI: Repository configured');
37
+ __.consoleInfo(` ${projectUrl}\n`);
38
+ return true;
39
+ }
40
+
41
+ __ = {
39
42
  /**
40
43
  * Check if CircleCI is already enabled for this project
41
44
  * @returns {boolean} True if already enabled, false otherwise
@@ -57,7 +60,9 @@ export default {
57
60
  method: 'post',
58
61
  });
59
62
  },
60
- __consoleInfo: consoleInfo,
61
- __consoleSuccess: consoleSuccess,
62
- __consoleError: consoleError,
63
+ consoleInfo,
64
+ consoleSuccess,
65
+ consoleError,
63
66
  };
67
+
68
+ export default { enable };
package/lib/github.js CHANGED
@@ -1,7 +1,9 @@
1
- import { consoleError, consoleInfo, consoleSuccess } from 'firost';
2
1
  import { _ } from 'golgoth';
2
+ import { consoleError, consoleInfo, consoleSuccess } from 'firost';
3
3
  import githubHelper from './helpers/github.js';
4
4
 
5
+ export let __;
6
+
5
7
  const gitHubSettings = {
6
8
  allow_merge_commit: false,
7
9
  allow_rebase_merge: true,
@@ -9,54 +11,55 @@ const gitHubSettings = {
9
11
  delete_branch_on_merge: true,
10
12
  };
11
13
 
12
- export default {
13
- /**
14
- * Configure the GitHub repo with default settings:
15
- * - Do not enable merge commits on PR
16
- * - Automatically delete branches after PR merge
17
- * @returns {boolean} True if enabled, false otherwise
18
- */
19
- async enable() {
20
- const { username, repo } = await githubHelper.repoData();
21
- const settingsUrl = `https://github.com/${username}/${repo}/settings`;
14
+ /**
15
+ * Configure the GitHub repo with default settings:
16
+ * - Do not enable merge commits on PR
17
+ * - Automatically delete branches after PR merge
18
+ * @returns {boolean} True if enabled, false otherwise
19
+ */
20
+ export async function enable() {
21
+ const { username, repo } = await githubHelper.repoData();
22
+ const settingsUrl = `https://github.com/${username}/${repo}/settings`;
23
+
24
+ // Fail early if no token available
25
+ if (!githubHelper.hasToken()) {
26
+ __.consoleError(
27
+ 'GitHub: ABERLAAS_GITHUB_TOKEN environment variable must be set',
28
+ );
29
+ __.consoleInfo(" Create a Classic token with 'repo' scope");
30
+ __.consoleInfo(' https://github.com/settings/tokens\n');
31
+ return false;
32
+ }
22
33
 
23
- // Fail early if no token available
24
- if (!githubHelper.hasToken()) {
25
- this.__consoleError(
26
- 'GitHub: ABERLAAS_GITHUB_TOKEN environment variable must be set',
27
- );
28
- this.__consoleInfo(" Create a Classic token with 'repo' scope");
29
- this.__consoleInfo(' https://github.com/settings/tokens\n');
34
+ // Check if already configured
35
+ try {
36
+ if (await __.isAlreadyConfigured()) {
37
+ __.consoleSuccess('GitHub: Already configured');
38
+ __.consoleInfo(` ${settingsUrl}\n`);
39
+ return true;
40
+ }
41
+ } catch (error) {
42
+ if (error.status === 401) {
43
+ __.consoleError('GitHub: ABERLAAS_GITHUB_TOKEN is invalid');
44
+ __.consoleInfo(" Create a Classic token with 'repo' scope");
45
+ __.consoleInfo(' https://github.com/settings/tokens\n');
30
46
  return false;
31
47
  }
48
+ throw error;
49
+ }
32
50
 
33
- // Check if already configured
34
- try {
35
- if (await this.isAlreadyConfigured()) {
36
- this.__consoleSuccess('GitHub: Already configured');
37
- this.__consoleInfo(` ${settingsUrl}\n`);
38
- return true;
39
- }
40
- } catch (error) {
41
- if (error.status === 401) {
42
- this.__consoleError('GitHub: ABERLAAS_GITHUB_TOKEN is invalid');
43
- this.__consoleInfo(" Create a Classic token with 'repo' scope");
44
- this.__consoleInfo(' https://github.com/settings/tokens\n');
45
- return false;
46
- }
47
- throw error;
48
- }
51
+ await githubHelper.octokit('repos.update', {
52
+ owner: username,
53
+ repo,
54
+ ...gitHubSettings,
55
+ });
49
56
 
50
- await githubHelper.octokit('repos.update', {
51
- owner: username,
52
- repo,
53
- ...gitHubSettings,
54
- });
57
+ __.consoleSuccess('GitHub: Repository configured');
58
+ __.consoleInfo(` ${settingsUrl}\n`);
59
+ return true;
60
+ }
55
61
 
56
- this.__consoleSuccess('GitHub: Repository configured');
57
- this.__consoleInfo(` ${settingsUrl}\n`);
58
- return true;
59
- },
62
+ __ = {
60
63
  /**
61
64
  * Check if GitHub repo is already configured with desired settings
62
65
  * @returns {boolean} True if already configured, false otherwise
@@ -70,7 +73,9 @@ export default {
70
73
 
71
74
  return _.isMatch(repoData, gitHubSettings);
72
75
  },
73
- __consoleSuccess: consoleSuccess,
74
- __consoleInfo: consoleInfo,
75
- __consoleError: consoleError,
76
+ consoleSuccess,
77
+ consoleInfo,
78
+ consoleError,
76
79
  };
80
+
81
+ export default { enable };
@@ -34,7 +34,7 @@ export default {
34
34
  return response.body;
35
35
  } catch (_error) {
36
36
  throw firostError(
37
- 'ERROR_CIRCLECI',
37
+ 'ABERLAAS_SETUP_CIRCLECI_API',
38
38
  "Can't connect to CircleCI API. Check that you have a valid ABERLAAS_CIRCLECI_TOKEN",
39
39
  );
40
40
  }
@@ -1,7 +1,7 @@
1
+ import { _ } from 'golgoth';
1
2
  import { run } from 'firost';
2
3
  import { Octokit } from '@octokit/rest';
3
4
  import parseGithubUrl from 'parse-github-repo-url';
4
- import { _ } from 'golgoth';
5
5
 
6
6
  export default {
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import { _ } from 'golgoth';
3
3
  import { exists, mkdirp, read, run, which } from 'firost';
4
- import helper from 'aberlaas-helper';
4
+ import { hostGitPath } from 'aberlaas-helper';
5
5
  import githubHelper from './github.js';
6
6
 
7
7
  export default {
@@ -18,7 +18,7 @@ export default {
18
18
  * @returns {object} Object with .public, .private and .privateFingerprint
19
19
  */
20
20
  async getKeys() {
21
- const keyPath = helper.hostPath('./tmp/ssh/key');
21
+ const keyPath = hostGitPath('./tmp/ssh/key');
22
22
 
23
23
  // Generating keys if do not exist
24
24
  const keyExists = await exists(keyPath);
package/lib/main.js CHANGED
@@ -1,52 +1,42 @@
1
1
  import { _ } from 'golgoth';
2
- import github from './github.js';
3
- import circleci from './circleci.js';
4
- import renovate from './renovate.js';
2
+ import { enable as enableCircleci } from './circleci.js';
3
+ import { enable as enableGithub } from './github.js';
4
+ import { enable as enableRenovate } from './renovate.js';
5
5
 
6
- export default {
7
- /**
8
- * Enable external services.
9
- * Will enable CircleCI, GitHub and Renovate by default.
10
- * @param {object} cliArgs CLI Argument object, as created by minimist
11
- */
12
- async run(cliArgs = {}) {
13
- const defaultServices = {
14
- circleci: true,
15
- renovate: true,
16
- github: true,
17
- };
18
- const cliServices = _.omit(cliArgs, ['_']);
19
- const servicesToEnable = {
20
- ...defaultServices,
21
- ...cliServices,
22
- };
6
+ export let __;
23
7
 
24
- if (servicesToEnable.github) {
25
- await this.github();
26
- }
27
- if (servicesToEnable.circleci) {
28
- await this.circleci();
29
- }
30
- if (servicesToEnable.renovate) {
31
- await this.renovate();
32
- }
33
- },
34
- /**
35
- * Configure GitHub
36
- */
37
- async github() {
38
- await github.enable();
39
- },
40
- /**
41
- * Enable CircleCI
42
- */
43
- async circleci() {
44
- await circleci.enable();
45
- },
46
- /**
47
- * Enable renovate
48
- */
49
- async renovate() {
50
- await renovate.enable();
51
- },
8
+ /**
9
+ * Enable external services.
10
+ * Will enable CircleCI, GitHub and Renovate by default.
11
+ * @param {object} cliArgs CLI Argument object, as created by minimist
12
+ */
13
+ export async function run(cliArgs = {}) {
14
+ const defaultServices = {
15
+ circleci: true,
16
+ renovate: true,
17
+ github: true,
18
+ };
19
+ const cliServices = _.omit(cliArgs, ['_']);
20
+ const servicesToEnable = {
21
+ ...defaultServices,
22
+ ...cliServices,
23
+ };
24
+
25
+ if (servicesToEnable.github) {
26
+ await __.enableGithub();
27
+ }
28
+ if (servicesToEnable.circleci) {
29
+ await __.enableCircleci();
30
+ }
31
+ if (servicesToEnable.renovate) {
32
+ await __.enableRenovate();
33
+ }
34
+ }
35
+
36
+ __ = {
37
+ enableGithub,
38
+ enableCircleci,
39
+ enableRenovate,
52
40
  };
41
+
42
+ export default { run };
package/lib/renovate.js CHANGED
@@ -1,8 +1,56 @@
1
1
  import { consoleError, consoleInfo, consoleSuccess } from 'firost';
2
2
  import githubHelper from './helpers/github.js';
3
3
 
4
- export default {
5
- renovateId: 2471197,
4
+ export let __;
5
+
6
+ const RENOVATE_ID = 2471197;
7
+
8
+ /**
9
+ * Attempt to automatically add the current repo to renovate, otherwise
10
+ * display the link to do it manually
11
+ * @returns {boolean} True if enabled, false otherwise
12
+ */
13
+ export async function enable() {
14
+ const { username, repo } = await githubHelper.repoData();
15
+ const manualUrl = `https://github.com/settings/installations/${RENOVATE_ID}`;
16
+ const renovateDashboardUrl = `https://developer.mend.io/github/${username}/${repo}`;
17
+
18
+ // Fail early if no token available
19
+ if (!githubHelper.hasToken()) {
20
+ __.consoleError(
21
+ 'Renovate: ABERLAAS_GITHUB_TOKEN environment variable must be set',
22
+ );
23
+ __.consoleInfo(" Create a Classic token with 'repo' scope");
24
+ __.consoleInfo(' https://github.com/settings/tokens\n');
25
+ return false;
26
+ }
27
+
28
+ // Check if already enabled
29
+ if (await __.isAlreadyEnabled()) {
30
+ __.consoleSuccess('Renovate: Already configured');
31
+ __.consoleInfo(` ${renovateDashboardUrl}\n`);
32
+ return true;
33
+ }
34
+
35
+ try {
36
+ const repositoryId = await __.getRepositoryId();
37
+ await githubHelper.octokit('apps.addRepoToInstallation', {
38
+ installation_id: RENOVATE_ID,
39
+ repository_id: repositoryId,
40
+ });
41
+ } catch (_err) {
42
+ __.consoleError('Renovate is not installed with this GitHub account');
43
+ __.consoleInfo(' Please visit the installation page to install it first');
44
+ __.consoleInfo(` ${manualUrl}\n`);
45
+ return false;
46
+ }
47
+
48
+ __.consoleSuccess('Renovate: Repository configured');
49
+ __.consoleInfo(` ${renovateDashboardUrl}\n`);
50
+ return true;
51
+ }
52
+
53
+ __ = {
6
54
  /**
7
55
  * Returns the GitHub repository Id
8
56
  * @returns {number} Repository Id
@@ -15,52 +63,6 @@ export default {
15
63
  });
16
64
  return id;
17
65
  },
18
- /**
19
- * Attempt to automatically add the current repo to renovate, otherwise
20
- * display the link to do it manually
21
- * @returns {boolean} True if enabled, false otherwise
22
- */
23
- async enable() {
24
- const { username, repo } = await githubHelper.repoData();
25
- const manualUrl = `https://github.com/settings/installations/${this.renovateId}`;
26
- const renovateDashboardUrl = `https://developer.mend.io/github/${username}/${repo}`;
27
-
28
- // Fail early if no token available
29
- if (!githubHelper.hasToken()) {
30
- this.__consoleError(
31
- 'Renovate: ABERLAAS_GITHUB_TOKEN environment variable must be set',
32
- );
33
- this.__consoleInfo(" Create a Classic token with 'repo' scope");
34
- this.__consoleInfo(' https://github.com/settings/tokens\n');
35
- return false;
36
- }
37
-
38
- // Check if already enabled
39
- if (await this.isAlreadyEnabled()) {
40
- this.__consoleSuccess('Renovate: Already configured');
41
- this.__consoleInfo(` ${renovateDashboardUrl}\n`);
42
- return true;
43
- }
44
-
45
- try {
46
- const repositoryId = await this.getRepositoryId();
47
- await githubHelper.octokit('apps.addRepoToInstallation', {
48
- installation_id: this.renovateId,
49
- repository_id: repositoryId,
50
- });
51
- } catch (_err) {
52
- this.__consoleError('Renovate is not installed with this GitHub account');
53
- this.__consoleInfo(
54
- ' Please visit the installation page to install it first',
55
- );
56
- this.__consoleInfo(` ${manualUrl}\n`);
57
- return false;
58
- }
59
-
60
- this.__consoleSuccess('Renovate: Repository configured');
61
- this.__consoleInfo(` ${renovateDashboardUrl}\n`);
62
- return true;
63
- },
64
66
  /**
65
67
  * Check if Renovate is already enabled for this repository
66
68
  * @returns {boolean} True if already enabled, false otherwise
@@ -71,7 +73,7 @@ export default {
71
73
  const installations = await githubHelper.octokit(
72
74
  'apps.listReposAccessibleToInstallation',
73
75
  {
74
- installation_id: this.renovateId,
76
+ installation_id: RENOVATE_ID,
75
77
  },
76
78
  );
77
79
 
@@ -84,7 +86,9 @@ export default {
84
86
  return false;
85
87
  }
86
88
  },
87
- __consoleSuccess: consoleSuccess,
88
- __consoleInfo: consoleInfo,
89
- __consoleError: consoleError,
89
+ consoleSuccess,
90
+ consoleInfo,
91
+ consoleError,
90
92
  };
93
+
94
+ export default { enable };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "aberlaas-setup",
3
3
  "type": "module",
4
+ "sideEffects": false,
4
5
  "description": "aberlaas setup helper: Setup third parties like GitHub, Netlify or CircleCI",
5
- "version": "2.18.1",
6
+ "version": "2.20.2",
6
7
  "repository": "pixelastic/aberlaas",
7
8
  "homepage": "https://projects.pixelastic.com/aberlaas/",
8
9
  "author": "Tim Carry (@pixelastic)",
@@ -18,27 +19,24 @@
18
19
  "engines": {
19
20
  "node": ">=18.18.0"
20
21
  },
21
- "scripts": {
22
- "build": "../../scripts/local/build",
23
- "build:prod": "../../scripts/local/build-prod",
24
- "cms": "../../scripts/local/cms",
25
- "serve": "../../scripts/local/serve",
26
- "ci": "../../scripts/local/ci",
27
- "release": "../../scripts/local/release",
28
- "update-dependencies": "node ../../scripts/meta/update-dependencies.js",
29
- "test:meta": "../../scripts/local/test-meta",
30
- "test": "../../scripts/local/test",
31
- "test:watch": "../../scripts/local/test-watch",
32
- "compress": "../../scripts/local/compress",
33
- "lint": "../../scripts/local/lint",
34
- "lint:fix": "../../scripts/local/lint-fix"
35
- },
36
22
  "dependencies": {
37
- "@octokit/rest": "21.0.2",
38
- "aberlaas-helper": "^2.18.1",
39
- "firost": "5.2.1",
40
- "golgoth": "3.0.0",
23
+ "@octokit/rest": "22.0.1",
24
+ "aberlaas-helper": "workspace:*",
25
+ "firost": "5.5.1",
26
+ "golgoth": "3.1.0",
41
27
  "parse-github-repo-url": "1.4.1"
42
28
  },
43
- "gitHead": "00b60dcf9aebab442a809ccc81942005d87d1b5c"
29
+ "scripts": {
30
+ "build": "cd ../docs && yarn run build",
31
+ "build:prod": "cd ../docs && yarn run build:prod",
32
+ "cms": "cd ../docs && yarn run cms",
33
+ "serve": "cd ../docs && yarn run serve",
34
+ "release": "cd ../.. && ./scripts/release",
35
+ "test:meta": "cd ../.. && ./scripts/test-meta",
36
+ "test": "cd ../.. && ./scripts/test",
37
+ "test:watch": "cd ../.. && ./scripts/test-watch",
38
+ "compress": "cd ../.. && ./scripts/compress",
39
+ "lint": "cd ../.. && ./scripts/lint",
40
+ "lint:fix": "cd ../.. && ./scripts/lint-fix"
41
+ }
44
42
  }