aberlaas 2.2.0 → 2.4.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 (55) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +1 -19
  3. package/commands/ci/index.js +14 -99
  4. package/commands/init/index.js +322 -205
  5. package/commands/lint/css.js +2 -2
  6. package/commands/lint/helpers/prettier.js +2 -2
  7. package/commands/lint/index.js +3 -2
  8. package/commands/lint/js.js +1 -1
  9. package/commands/precommit/index.js +4 -3
  10. package/commands/setup/index.js +0 -12
  11. package/commands/test/index.js +56 -48
  12. package/configs/eslint.cjs +9 -2
  13. package/configs/lintstaged.js +25 -0
  14. package/configs/node.cjs +4 -0
  15. package/configs/{prettier.cjs → prettier.js} +1 -1
  16. package/configs/{stylelint.cjs → stylelint.js} +1 -1
  17. package/configs/vite.js +9 -2
  18. package/main.js +31 -2
  19. package/package.json +24 -23
  20. package/templates/_circleci/config.yml +0 -1
  21. package/templates/_eslintignore.conf +4 -1
  22. package/templates/_gitattributes +4 -0
  23. package/templates/_gitignore +29 -0
  24. package/templates/lerna.json +6 -0
  25. package/templates/lib/__tests__/main.js +7 -5
  26. package/templates/lib/main.js +2 -2
  27. package/templates/lintstaged.config.js +4 -0
  28. package/templates/prettier.config.js +4 -0
  29. package/templates/scripts/ci +3 -1
  30. package/templates/scripts/compress +2 -2
  31. package/templates/scripts/docs/build +4 -0
  32. package/templates/scripts/docs/build-prod +4 -0
  33. package/templates/scripts/docs/cms +4 -0
  34. package/templates/scripts/docs/serve +4 -0
  35. package/templates/scripts/hooks/pre-commit +1 -1
  36. package/templates/scripts/lib/release +5 -0
  37. package/templates/scripts/lib/test +4 -0
  38. package/templates/scripts/lib/test-watch +4 -0
  39. package/templates/scripts/lint +2 -2
  40. package/templates/scripts/lint-fix +2 -2
  41. package/templates/stylelint.config.js +4 -0
  42. package/templates/vite.config.js +2 -2
  43. package/commands/ci/autoRelease.js +0 -143
  44. package/commands/release/index.js +0 -76
  45. package/commands/setup/autoRelease/envVars.js +0 -56
  46. package/commands/setup/autoRelease/index.js +0 -59
  47. package/commands/setup/autoRelease/privateKey.js +0 -41
  48. package/commands/setup/autoRelease/publicKey.js +0 -55
  49. package/configs/lintstaged.cjs +0 -31
  50. package/templates/_lintstagedrc.cjs +0 -4
  51. package/templates/_prettierrc.cjs +0 -4
  52. package/templates/_stylelintrc.cjs +0 -4
  53. package/templates/scripts/release +0 -4
  54. package/templates/scripts/test +0 -4
  55. package/templates/scripts/test-watch +0 -4
@@ -1,4 +1,4 @@
1
- import viteConfig from 'aberlaas/configs/vite.js';
1
+ import config from 'aberlaas/configs/vite';
2
2
  export default {
3
- ...viteConfig,
3
+ ...config,
4
4
  };
@@ -1,143 +0,0 @@
1
- import release from '../release/index.js';
2
- import consoleInfo from 'firost/consoleInfo.js';
3
- import _ from 'golgoth/lodash.js';
4
- import run from 'firost/run.js';
5
- import write from 'firost/write.js';
6
- import exists from 'firost/exists.js';
7
- import helper from '../../helper.js';
8
-
9
- export default {
10
- /**
11
- * Run a git command in the repo
12
- *
13
- * @param {string} gitCommand Git command to run
14
- * @returns {string} Command output
15
- */
16
- async gitRun(gitCommand) {
17
- const repoPath = helper.hostPath();
18
- const result = await run(`cd ${repoPath} && ${gitCommand}`, {
19
- shell: true,
20
- stdout: false,
21
- });
22
- return result.stdout;
23
- },
24
- /**
25
- * Set a git config value only if wasn't set before
26
- * @param {string} name Name of the config
27
- * @param {string} value Value of the config
28
- **/
29
- async gitConfigSet(name, value) {
30
- // We test to see if there is already a value. If no, we write it
31
- try {
32
- await this.gitRun(`git config ${name}`);
33
- } catch (err) {
34
- await this.gitRun(`git config ${name} ${value}`);
35
- }
36
- },
37
- /**
38
- * Returns the latest tag of the repo
39
- *
40
- * @returns {string} Latest tag
41
- **/
42
- async gitGetLatestTag() {
43
- const allTags = await this.gitRun('git tag -l --sort=creatordate');
44
- return _.chain(allTags).split('\n').last().value();
45
- },
46
- /**
47
- * Returns an array of all commit description since last release
48
- *
49
- * @returns {Array} List of all commit description
50
- **/
51
- async getCommitsSinceLastRelease() {
52
- const latestTag = await this.gitGetLatestTag();
53
- const range = latestTag ? `${latestTag}..HEAD` : 'HEAD';
54
- const commitList = await this.gitRun(`git log ${range} --format=%B`);
55
- return _.chain(commitList).split('\n').compact().reverse().value();
56
- },
57
- /**
58
- * Determines what version should be released based on the commits since the
59
- * last release
60
- * @returns {string|boolean} False if no release, otherwise minor or patch
61
- **/
62
- async getReleaseVersion() {
63
- const commits = await this.getCommitsSinceLastRelease();
64
- const status = {
65
- isMinor: false,
66
- isPatch: false,
67
- };
68
- _.each(commits, (commit) => {
69
- const isMinor = _.startsWith(commit, 'feat(');
70
- const isPatch = _.startsWith(commit, 'fix(');
71
- status.isMinor = status.isMinor || isMinor;
72
- status.isPatch = status.isPatch || isPatch;
73
- });
74
-
75
- if (status.isMinor) {
76
- return 'minor';
77
- }
78
- if (status.isPatch) {
79
- return 'patch';
80
- }
81
- return false;
82
- },
83
- /**
84
- * Run the auto-release script.
85
- * If there had been any feat() of fix() commits since last release,
86
- * automatically release a new one
87
- **/
88
- async run() {
89
- this.__consoleInfo('Attempt to auto-release...');
90
-
91
- const releaseVersion = await this.getReleaseVersion();
92
- // Don't release if no relevant changes
93
- if (!releaseVersion) {
94
- this.__consoleInfo('No relevant commits since last release.');
95
- return;
96
- }
97
-
98
- this.__consoleInfo(`Releasing a ${releaseVersion} version`);
99
- await this.configureGit();
100
- await this.configureNpm();
101
-
102
- const releaseArguments = {
103
- _: [releaseVersion],
104
- test: false,
105
- };
106
- await this.__releaseRun(releaseArguments);
107
- },
108
- /**
109
- * Set git user name and email
110
- * */
111
- async configureGit() {
112
- const email = this.getEnvVar('GIT_USER_EMAIL');
113
- const name = this.getEnvVar('GIT_USER_NAME');
114
- await this.gitConfigSet('user.email', email);
115
- await this.gitConfigSet('user.name', name);
116
- },
117
- /**
118
- * Write a ~/.npmrc with the token
119
- * @returns {boolean} true on success, false if already a .npmrc
120
- **/
121
- async configureNpm() {
122
- const npmRcPath = '~/.npmrc';
123
- if (await this.__exists(npmRcPath)) {
124
- return false;
125
- }
126
- const token = this.getEnvVar('NPM_TOKEN');
127
- const content = `//registry.npmjs.org/:_authToken=${token}`;
128
- await this.__write(content, npmRcPath);
129
- return true;
130
- },
131
- /**
132
- * Return an ENV var value
133
- * @param {string} key ENV var key
134
- * @returns {string} ENV var value
135
- **/
136
- getEnvVar(key) {
137
- return _.get(process, `env.${key}`);
138
- },
139
- __releaseRun: release.run.bind(release),
140
- __consoleInfo: consoleInfo,
141
- __write: write,
142
- __exists: exists,
143
- };
@@ -1,76 +0,0 @@
1
- import _ from 'golgoth/lodash.js';
2
- import run from 'firost/run.js';
3
- import readJson from 'firost/readJson.js';
4
- import helper from '../../helper.js';
5
-
6
- export default {
7
- /**
8
- * Release the host package.
9
- * @param {object} cliArgs CLI Argument object, as created by minimist
10
- * @returns {boolean} True on success, false otherwise
11
- **/
12
- async run(cliArgs = {}) {
13
- this.fixNpmRegistry();
14
- await this.fetchOrigin();
15
-
16
- const binary = await helper.which('np');
17
- const npOptions = await this.getNpArguments(cliArgs);
18
- const command = `FORCE_COLOR=1 ${binary} ${npOptions}`;
19
- await this.__run(command, {
20
- stdin: true,
21
- shell: true,
22
- });
23
- },
24
- /**
25
- * Returns the CLI options to pass to np
26
- * @param {object} cliArgs CLI Argument object, as created by minimist
27
- * @returns {string} Arguments to pass to np
28
- **/
29
- async getNpArguments(cliArgs = {}) {
30
- const options = [
31
- cliArgs._,
32
- '--no-release-draft',
33
- '--no-2fa',
34
- '--any-branch',
35
- ];
36
- const packageJson = await this.getHostPackageJson();
37
-
38
- // Skip tests if called with --no-test or if no scripts.test entry
39
- const cliTestStatus = _.get(cliArgs, 'test', true);
40
- const cliPackageStatus = _.get(packageJson, 'scripts.test', false);
41
- if (!cliTestStatus || !cliPackageStatus) {
42
- options.push('--no-tests');
43
- }
44
-
45
- // Run in preview mode if --dry-run is set
46
- const isDryRun = _.get(cliArgs, 'dry-run', false);
47
- if (isDryRun) {
48
- options.push('--preview');
49
- }
50
-
51
- return _.chain(options).compact().join(' ').value();
52
- },
53
- /**
54
- * Yarn changes the npm_config_registry value, preventing npm publish to
55
- * actually work. We revert it to its default value for publishing to work
56
- **/
57
- fixNpmRegistry() {
58
- // eslint-disable-next-line camelcase
59
- process.env.npm_config_registry = 'https://registry.npmjs.org/';
60
- },
61
- /**
62
- * Fetches origin information, so np can correctly keep the branch up to date
63
- **/
64
- async fetchOrigin() {
65
- await this.__run('git fetch --all', { stdout: false });
66
- },
67
- /**
68
- * Returns the content of the host package.json
69
- * @returns {object} The content of the host package.json
70
- **/
71
- async getHostPackageJson() {
72
- return await this.__readJson(helper.hostPath('package.json'));
73
- },
74
- __run: run,
75
- __readJson: readJson,
76
- };
@@ -1,56 +0,0 @@
1
- import circleciHelper from '../helpers/circleci.js';
2
- import githubHelper from '../helpers/github.js';
3
- import npmHelper from '../helpers/npm.js';
4
- import consoleInfo from 'firost/consoleInfo.js';
5
- import consoleSuccess from 'firost/consoleSuccess.js';
6
- import pMap from 'golgoth/pMap.js';
7
-
8
- export default {
9
- /**
10
- * Save an ENV variable to CircleCI
11
- * @param {string} name Name of the ENV variable
12
- * @param {string} value Value of the ENV variable
13
- **/
14
- async saveEnvVar(name, value) {
15
- const { username, repo } = await githubHelper.repoData();
16
- try {
17
- await circleciHelper.api(
18
- `project/github/${username}/${repo}/envvar/${name}`,
19
- {
20
- method: 'delete',
21
- },
22
- );
23
- } catch (err) {
24
- // Ignoring the error, it means the ENV var wasn't set in the first place
25
- }
26
- await circleciHelper.api(`project/github/${username}/${repo}/envvar`, {
27
- method: 'post',
28
- json: {
29
- name,
30
- value,
31
- },
32
- });
33
- this.__consoleSuccess(`${name} saved on CircleCI`);
34
- },
35
- /**
36
- * Save ENV Variables to CircleCI
37
- **/
38
- async enable() {
39
- // Vars to save
40
- const npmToken = npmHelper.token();
41
- const gitUserEmail = await githubHelper.config('user.email');
42
- const gitUserName = await githubHelper.config('user.name');
43
- const vars = [
44
- { name: 'NPM_TOKEN', value: npmToken },
45
- { name: 'GIT_USER_EMAIL', value: gitUserEmail },
46
- { name: 'GIT_USER_NAME', value: gitUserName },
47
- ];
48
-
49
- // Saving them in parallel
50
- await pMap(vars, async ({ name, value }) => {
51
- await this.saveEnvVar(name, value);
52
- });
53
- },
54
- __consoleInfo: consoleInfo,
55
- __consoleSuccess: consoleSuccess,
56
- };
@@ -1,59 +0,0 @@
1
- import envVars from './envVars.js';
2
- import privateKey from './privateKey.js';
3
- import publicKey from './publicKey.js';
4
- import sshHelper from '../helpers/ssh.js';
5
- import npmHelper from '../helpers/npm.js';
6
- import githubHelper from '../helpers/github.js';
7
- import circleciHelper from '../helpers/circleci.js';
8
- import _ from 'golgoth/lodash.js';
9
- import consoleError from 'firost/consoleError.js';
10
-
11
- export default {
12
- /**
13
- * Enable autoRelease by configuring CircleCI and GitHub
14
- * @returns {boolean} True if enabled, false otherwise
15
- **/
16
- async enable() {
17
- // Fail early if we're missing the required tokens
18
- const validationErrors = await this.validationErrors();
19
- if (!_.isEmpty(validationErrors)) {
20
- this.__consoleError(
21
- '[autoRelease] Please fix the following errors and try again:',
22
- );
23
- _.each(validationErrors, (error) => {
24
- this.__consoleError(error);
25
- });
26
- return false;
27
- }
28
-
29
- await this.__envVarsEnable();
30
- await this.__privateKeyEnable();
31
- await this.__publicKeyEnable();
32
- },
33
- /**
34
- * Returns an array of error messages for every token/binary missing
35
- * @returns {Array} List of error messages
36
- **/
37
- async validationErrors() {
38
- const validationErrors = [];
39
- if (!circleciHelper.hasToken()) {
40
- validationErrors.push('You need a CIRCLECI_TOKEN');
41
- }
42
- if (!npmHelper.hasToken()) {
43
- validationErrors.push('You need a NPM_TOKEN');
44
- }
45
- if (!githubHelper.hasToken()) {
46
- validationErrors.push('You need a GITHUB_TOKEN');
47
- }
48
- if (!sshHelper.hasBinary()) {
49
- validationErrors.push('You need ssh-keygen available in your $PATH');
50
- }
51
-
52
- return validationErrors;
53
- },
54
- __consoleError: consoleError,
55
- __envVarsEnable: envVars.enable.bind(envVars),
56
- __privateKeyEnable: privateKey.enable.bind(privateKey),
57
- __publicKeyEnable: publicKey.enable.bind(publicKey),
58
- __cache: {},
59
- };
@@ -1,41 +0,0 @@
1
- import circleciHelper from '../helpers/circleci.js';
2
- import githubHelper from '../helpers/github.js';
3
- import sshHelper from '../helpers/ssh.js';
4
- import consoleSuccess from 'firost/consoleSuccess.js';
5
-
6
- export default {
7
- /**
8
- * Save a private SSH key on CircleCI.
9
- * The CircleCI API does not allow checking if a SSH key has been defined,
10
- * so we will need to re-add it each time. But to avoid creating duplicates,
11
- * we will delete any key with the same fingerprint first
12
- **/
13
- async enable() {
14
- const keys = await sshHelper.getKeys();
15
- const privateKey = keys.private;
16
- const privateFingerprint = keys.privateFingerprint;
17
- const { username, repo } = await githubHelper.repoData();
18
- const hostname = 'github.com';
19
-
20
- // Delete it first
21
- await circleciHelper.api(`project/github/${username}/${repo}/ssh-key`, {
22
- method: 'delete',
23
- json: {
24
- fingerprint: privateFingerprint,
25
- hostname,
26
- },
27
- });
28
-
29
- // Then, add it
30
- await circleciHelper.api(`project/github/${username}/${repo}/ssh-key`, {
31
- method: 'post',
32
- json: {
33
- hostname,
34
- private_key: privateKey,
35
- },
36
- });
37
-
38
- this.__consoleSuccess('SSH private key force saved on CircleCI');
39
- },
40
- __consoleSuccess: consoleSuccess,
41
- };
@@ -1,55 +0,0 @@
1
- import githubHelper from '../helpers/github.js';
2
- import sshHelper from '../helpers/ssh.js';
3
- import _ from 'golgoth/lodash.js';
4
- import consoleInfo from 'firost/consoleInfo.js';
5
- import consoleSuccess from 'firost/consoleSuccess.js';
6
- import consoleError from 'firost/consoleError.js';
7
-
8
- export default {
9
- /**
10
- * Check if SSH public key is already added to GitHub
11
- * @returns {boolean} True if already enabled, false otherwise
12
- **/
13
- async isEnabled() {
14
- const { username: owner, repo } = await githubHelper.repoData();
15
- const keys = await githubHelper.octokit('repos.listDeployKeys', {
16
- owner,
17
- repo,
18
- });
19
- const { public: publicKey } = await sshHelper.getKeys();
20
- // GitHub does not save the email as part of the key, so we shave it off our
21
- // key
22
- const truncatedKey = _.chain(publicKey)
23
- .split(' ')
24
- .slice(0, 2)
25
- .join(' ')
26
- .value();
27
-
28
- const foundKey = _.find(keys, { key: truncatedKey });
29
- return !!foundKey;
30
- },
31
- /**
32
- * Add the SSH public key to GitHub
33
- * @returns {boolean} True on success
34
- **/
35
- async enable() {
36
- if (await this.isEnabled()) {
37
- this.__consoleInfo('SSH public key already saved on GitHub');
38
- return true;
39
- }
40
- const { public: key } = await sshHelper.getKeys();
41
- const { username: owner, repo } = await githubHelper.repoData();
42
- await githubHelper.octokit('repos.createDeployKey', {
43
- owner,
44
- repo,
45
- key,
46
- title: 'aberlaas - Push from CircleCI',
47
- read_only: false,
48
- });
49
- this.__consoleSuccess('SSH public key saved on GitHub');
50
- return true;
51
- },
52
- __consoleInfo: consoleInfo,
53
- __consoleSuccess: consoleSuccess,
54
- __consoleError: consoleError,
55
- };
@@ -1,31 +0,0 @@
1
- const pkg = require(`${process.cwd()}/package.json`);
2
-
3
- // We update the README.md and ./lib/README.md whenever documentation changes
4
- const aberlaasRunCommands = [
5
- 'yarn run aberlaas readme',
6
- 'git add ./README.md ./lib/README.md',
7
- ];
8
- const result = {
9
- '.github/README.template.md': aberlaasRunCommands,
10
- 'docs/src/**/*.md': aberlaasRunCommands,
11
- };
12
-
13
- // Linting and autofixing supported files
14
- if (pkg.scripts && pkg.scripts.lint) {
15
- result['*.css'] = ['yarn run lint:fix --css'];
16
- result['*.{yml,yaml}'] = ['yarn run lint:fix --yml'];
17
- result['.circleci/config.yml'] = ['yarn run lint --circleci'];
18
- result['*.json'] = ['yarn run lint:fix --json'];
19
- result['*.js'] = ['yarn run lint:fix --js'];
20
- }
21
-
22
- // Compressing images
23
- if (pkg.scripts && pkg.scripts.compress) {
24
- result['*.png'] = ['yarn run compress --png'];
25
- }
26
-
27
- // Testing changed js files
28
- if (pkg.scripts && pkg.scripts.test) {
29
- result['./lib/**/*.js'] = ['yarn run test --failFast --related'];
30
- }
31
- module.exports = result;
@@ -1,4 +0,0 @@
1
- const config = require('aberlaas/configs/lintstaged.cjs');
2
- module.exports = {
3
- ...config,
4
- };
@@ -1,4 +0,0 @@
1
- const config = require('aberlaas/configs/prettier.cjs');
2
- module.exports = {
3
- ...config,
4
- };
@@ -1,4 +0,0 @@
1
- const config = require('aberlaas/configs/stylelint.cjs');
2
- module.exports = {
3
- ...config,
4
- };
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env sh
2
- set -e
3
-
4
- aberlaas release "$@"
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env sh
2
- set -e
3
-
4
- aberlaas test "$@"
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env sh
2
- set -e
3
-
4
- aberlaas test "$@" --watch