Skip to content
This repository was archived by the owner on May 16, 2020. It is now read-only.

Commit 086aafd

Browse files
fix(atlauncher-scripts): fix linting errors
1 parent 416e5e4 commit 086aafd

File tree

9 files changed

+129
-53
lines changed

9 files changed

+129
-53
lines changed

.markdownlint.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"default": true,
3+
"ul-style": { "style": "asterisk" },
4+
"ul-start-left": false,
5+
"ul-indent": { "indent": 2 },
6+
"no-multiple-blanks": { "maximum": 1 },
7+
"line-length": { "line_length": 120 },
8+
"hr-style": { "style": "---" }
9+
}

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
# ATLauncher Style Guide
2+
23
This is the style guide for ATLauncher.
34

45
## Contents
6+
57
This repository is a mono repo powered with Lerna and contains the following packages:
68

7-
* babel-preset-atlauncher
8-
* eslint-config-atlauncher
9-
* ui-components
9+
* @atlauncher/atlauncher-scripts
10+
* @atlauncher/babel-preset-atlauncher
11+
* @atlauncher/commitlint-config-atlauncher
12+
* @atlauncher/eslint-config-atlauncher
13+
* @atlauncher/eslint-plugin-atlauncher
14+
* @atlauncher/ui-components
1015

1116
## Packages
12-
Each package is a single npm package within the `@atlauncher` scope and is independently published
17+
18+
Each package is a single npm package within the `` scope and is independently published
1319
from one another.
1420

1521
Lerna provides the ability to link the modules up with one another so that packages can be devleoped
1622
with a dependency on another package in this mono repo without the need to publish ahead of time.
1723

18-
### atlauncher-scripts
24+
### @atlauncher/atlauncher-scripts
25+
1926
This package provides all the scripts needed to run, test, lint, build and more for ATLauncher
2027
projects.
2128

@@ -27,7 +34,8 @@ do certain things over time by just having it contained within one directory.
2734
* [More Info](https://github.com/ATLauncher/style-guide/blob/master/atlauncher-scripts/README.md)
2835
* [NPM](https://www.npmjs.com/package/@atlauncher/atlauncher-scripts)
2936

30-
### babel-preset-atlauncher
37+
### @atlauncher/babel-preset-atlauncher
38+
3139
This package contains a preset for Babel which is setup to work for ATLauncher's projects.
3240

3341
It's intended to support all browsers and versions we need to and be a quick preset to get up and
@@ -36,13 +44,15 @@ going quickly.
3644
* [More Info](https://github.com/ATLauncher/style-guide/blob/master/babel-present-atlauncher/README.md)
3745
* [NPM](https://www.npmjs.com/package/@atlauncher/babel-present-atlauncher)
3846

39-
### commitlint-config-atlauncher
47+
### @atlauncher/commitlint-config-atlauncher
48+
4049
This package ensures that all commits done to ATLauncher repositories follows our commit standards.
4150

4251
* [More Info](https://github.com/ATLauncher/style-guide/blob/master/commitlint-config-atlauncher/README.md)
4352
* [NPM](https://www.npmjs.com/package/@atlauncher/commitlint-config-atlauncher)
4453

45-
### eslint-config-atlauncher
54+
### @atlauncher/eslint-config-atlauncher
55+
4656
This package contains our ESLint configs.
4757

4858
This allows all ATLauncher projects to simply extend from this base config to ensure that all code
@@ -51,15 +61,17 @@ is consistent and follows the same styling rules.
5161
* [More Info](https://github.com/ATLauncher/style-guide/blob/master/eslint-config-atlauncher/README.md)
5262
* [NPM](https://www.npmjs.com/package/@atlauncher/eslint-config-atlauncher)
5363

54-
### eslint-plugin-atlauncher
64+
### @atlauncher/eslint-plugin-atlauncher
65+
5566
This package contains our custom ESLint rules.
5667

5768
Currently only used to allow ignoring method names from requiring `@returns` JSDoc comments.
5869

5970
* [More Info](https://github.com/ATLauncher/style-guide/blob/master/eslint-plugin-atlauncher/README.md)
6071
* [NPM](https://www.npmjs.com/package/@atlauncher/eslint-plugin-atlauncher)
6172

62-
### ui-components
73+
### @atlauncher/ui-components
74+
6375
This package contains all the components used by ATLauncher in it's various projects to provide a
6476
consistent visual look through all sites and applications.
6577

@@ -71,6 +83,7 @@ play with components.
7183
* [Storybook](https://atlauncher.github.io/style-guide/)
7284

7385
## Developing
86+
7487
To get developing with any of these modules, first install Lerna globally:
7588

7689
```bash
@@ -88,22 +101,27 @@ To run the linter simply run `npm run lint` which will run the linter on all the
88101
To run tests on all the packages, simply run `npm run test`.
89102

90103
## Publishing
104+
91105
### Production
106+
92107
```bash
93108
npm run publish
94109
```
95110

96111
Or for a single package:
112+
97113
```bash
98114
npm run publish -- --scope @atlauncher/package-name
99115
```
100116

101117
### Testing versions
118+
102119
```bash
103120
npm run publish:prerelease
104121
```
105122

106123
Or for a single package:
124+
107125
```bash
108126
npm run publish:prerelease -- --scope @atlauncher/package-name
109127
```

packages/atlauncher-scripts/config/.markdownlint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"default": true,
33
"ul-style": { "style": "asterisk" },
44
"ul-start-left": false,
5-
"ul-indent": 2,
5+
"ul-indent": { "indent": 2 },
66
"no-multiple-blanks": { "maximum": 1 },
77
"line-length": { "line_length": 120 },
88
"hr-style": { "style": "---" }

packages/atlauncher-scripts/scripts/clean.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (args.length) {
1818
});
1919
}
2020

21-
const projectBasePath = utils.getProjectBasePath();
21+
const projectBasePath = utils.getProjectPath();
2222

2323
const extraToClean = utils.getConfigFromPackageJson('extraToClean', []);
2424

packages/atlauncher-scripts/scripts/lint-js.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ if (watch) {
3030

3131
const processArguments = [
3232
'--config',
33-
utils.getRootFile('.eslintrc'),
33+
utils.getConfigFile('.eslintrc'),
3434
'--ignore-path',
35-
utils.getRootFile('.eslintignore'),
35+
utils.getConfigFile('.eslintignore'),
3636
debug && '--debug',
3737
utils.getSourceCodeGlob('js'),
3838
];

packages/atlauncher-scripts/scripts/lint-md.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const utils = require('../utils');
22

33
const processArguments = [
44
'--config',
5-
utils.getRootFile('.markdownlint.json'),
5+
utils.getConfigFile('.markdownlint.json'),
66
utils.getRootGlob('md'),
77
];
88

packages/atlauncher-scripts/scripts/lint-pj.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const utils = require('../utils');
22

33
const processArguments = [
44
'--rules-file',
5-
utils.getRootFile('.npmpackagejsonlintrc'),
6-
utils.getRootFile('package.json'),
5+
utils.getConfigFile('.npmpackagejsonlintrc'),
6+
utils.getConfigFile('package.json'),
77
];
88

99
utils.spawnSyncProcess(utils.getNodeModulesBinPath('pjl-cli'), processArguments);

packages/atlauncher-scripts/scripts/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ if (args.length) {
3131

3232
const processArguments = [
3333
'--rootDir',
34-
utils.getProjectBasePath(),
34+
utils.getProjectPath(),
3535
'--config',
36-
utils.getRootFile('jest.json'),
36+
utils.getConfigFile('jest.json'),
3737
watch && '--watch',
3838
debug && '--debug',
3939
coverage && '--coverage',

packages/atlauncher-scripts/utils/index.js

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ const chalk = require('chalk');
44
const spawn = require('cross-spawn');
55
const isWindows = require('is-windows');
66

7-
function getScripts() {
8-
const scripts = fs.readdirSync(getATLauncherScriptsBasePath('scripts'));
9-
10-
// remove the file extension and turn all '-' to ':' so 'lint-js' is run by using 'lint:js'
11-
return scripts.map((script) => script.replace('.js', '').replace('-', ':'));
12-
}
13-
14-
function getProjectBasePath() {
15-
return path.resolve(process.cwd());
7+
/**
8+
* This gets a path to the project (where atlauncher-scripts was called from).
9+
*
10+
* @param {string} [pathString=''] the path to get, otherwise the root
11+
* @returns {string}
12+
*/
13+
function getProjectPath(pathString = '') {
14+
return path.resolve(process.cwd(), pathString);
1615
}
1716

17+
/**
18+
* This reads in the projects package.json (if it exists) and returns it as an object.
19+
*
20+
* @returns {Object}
21+
*/
1822
function getProjectPackageJson() {
1923
const packageJsonPath = getProjectPath('package.json');
2024

@@ -25,6 +29,15 @@ function getProjectPackageJson() {
2529
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
2630
}
2731

32+
/**
33+
* This gets the specified value from the projects package.json config option if it exists.
34+
*
35+
* If it doesn't exist, the optional defaultValue will be returned.
36+
*
37+
* @param {string} name
38+
* @param {any} [defaultValue=null]
39+
* @returns {any}
40+
*/
2841
function getConfigFromPackageJson(name, defaultValue = null) {
2942
const packageJson = getProjectPackageJson();
3043

@@ -43,39 +56,68 @@ function getConfigFromPackageJson(name, defaultValue = null) {
4356
return packageJson.config.atlauncher[name];
4457
}
4558

59+
/**
60+
* This gets the base path for the atlauncher-scripts directory,
61+
*
62+
* @param {string} [pathString='']
63+
* @returns {string}
64+
*/
4665
function getATLauncherScriptsBasePath(pathString = '') {
4766
return path.resolve(__dirname, '../', pathString);
4867
}
4968

50-
function getSourceCodePath() {
51-
return getProjectPath('src');
52-
}
69+
/**
70+
* This gets the list of scripts available to be executed by atlauncher-scripts.
71+
*
72+
* @returns {string[]}
73+
*/
74+
function getScripts() {
75+
const scripts = fs.readdirSync(getATLauncherScriptsBasePath('scripts'));
5376

54-
function getProjectPath(pathString = '/') {
55-
return path.resolve(getProjectBasePath(), pathString);
77+
// remove the file extension and turn all '-' to ':' so 'lint-js' is run by using 'lint:js'
78+
return scripts.map((script) => script.replace('.js', '').replace('-', ':'));
5679
}
5780

81+
/**
82+
* This gets a path from the node_modules folder.
83+
*
84+
* It first checks the projects node_modules folder, and then if that doesn't exist will check the atlauncher-scripts
85+
* node_modules folder. Finally if that doesn't exist it will assume it's being run from lerna and use lerna's hoisted
86+
* node_modules folder if it exists, else null.
87+
*
88+
* @param {string} filename
89+
* @returns {string|null}
90+
*/
5891
function getNodeModulesPath(filename) {
59-
const projectBasePath = getProjectBasePath();
60-
61-
const projectRootFile = `${projectBasePath}/node_modules/${filename}`;
92+
const projectRootFile = getProjectPath(`node_modules/${filename}`);
6293

6394
if (fs.existsSync(projectRootFile)) {
6495
return projectRootFile;
6596
}
6697

67-
const atlauncherScriptsBasePath = getATLauncherScriptsBasePath();
68-
const atlauncherScriptsFile = `${atlauncherScriptsBasePath}/node_modules/${filename}`;
98+
const atlauncherScriptsFile = getATLauncherScriptsBasePath(`node_modules/${filename}`);
6999

70100
if (fs.existsSync(atlauncherScriptsFile)) {
71101
return atlauncherScriptsFile;
72102
}
73103

74-
const lernaRootBasePath = path.resolve(atlauncherScriptsBasePath, '../../../');
104+
const lernaRootBasePath = getATLauncherScriptsBasePath(`../../../node_modules/${filename}`);
75105

76-
return `${lernaRootBasePath}/node_modules/${filename}`;
106+
if (fs.existsSync(lernaRootBasePath)) {
107+
return lernaRootBasePath;
108+
}
109+
110+
return null;
77111
}
78112

113+
/**
114+
* This will get the path to a file in the .bin directory of node_modules.
115+
*
116+
* If on Windows it will return the path to the `.cmd` version if it exists.
117+
*
118+
* @param {string} packageName
119+
* @returns {string}
120+
*/
79121
function getNodeModulesBinPath(packageName) {
80122
if (isWindows()) {
81123
const cmdBin = getNodeModulesPath(`.bin/${packageName}.cmd`);
@@ -88,24 +130,31 @@ function getNodeModulesBinPath(packageName) {
88130
return getNodeModulesPath(`.bin/${packageName}`);
89131
}
90132

91-
function getRootFile(filename) {
92-
const projectBasePath = getProjectBasePath();
93-
94-
const projectRootFile = `${projectBasePath}/${filename}`;
133+
/**
134+
* This will get the path to a config file, either in the projects base directory, or provided as a default by
135+
* atlauncher-scripts.
136+
*
137+
* @param {string} filename
138+
* @returns {string|null}
139+
*/
140+
function getConfigFile(filename) {
141+
const projectRootFile = getProjectPath(filename);
95142

96143
if (fs.existsSync(projectRootFile)) {
97144
return projectRootFile;
98145
}
99146

100-
const atlauncherScriptsBasePath = getATLauncherScriptsBasePath();
147+
const defaultRootFile = getATLauncherScriptsBasePath(`config/${filename}`);
101148

102-
const defaultRootFile = `${atlauncherScriptsBasePath}/config/${filename}`;
149+
if (fs.existsSync(defaultRootFile)) {
150+
return defaultRootFile;
151+
}
103152

104-
return defaultRootFile;
153+
return null;
105154
}
106155

107156
function getRootGlob(type = 'js') {
108-
let sourceCodePath = getProjectBasePath();
157+
let sourceCodePath = getProjectPath();
109158

110159
if (sourceCodePath.substr(-1) === '/') {
111160
sourceCodePath = sourceCodePath.substr(0, sourceCodePath.length - 1);
@@ -119,7 +168,7 @@ function getRootGlob(type = 'js') {
119168
}
120169

121170
function getSourceCodeGlob(type = 'js') {
122-
let sourceCodePath = getSourceCodePath();
171+
let sourceCodePath = getProjectPath('src');
123172

124173
if (sourceCodePath.substr(-1) === '/') {
125174
sourceCodePath = sourceCodePath.substr(0, sourceCodePath.length - 1);
@@ -134,7 +183,7 @@ function getSourceCodeGlob(type = 'js') {
134183
return `${sourceCodePath}/**/*`;
135184
}
136185

137-
function spawnSyncProcess(command = 'node', processes = [], workingDirectory = getProjectBasePath()) {
186+
function spawnSyncProcess(command = 'node', processes = [], workingDirectory = getProjectPath()) {
138187
if (typeof processes !== 'object') {
139188
return;
140189
}
@@ -181,15 +230,15 @@ function spawnSyncProcess(command = 'node', processes = [], workingDirectory = g
181230
});
182231
}
183232

233+
// eslint-disable-next-line immutable/no-mutation
184234
module.exports = {
185235
getScripts,
186-
getRootFile,
236+
getRootGlob,
237+
getConfigFile,
187238
getProjectPath,
188239
spawnSyncProcess,
189240
getSourceCodeGlob,
190-
getSourceCodePath,
191241
getNodeModulesPath,
192-
getProjectBasePath,
193242
getNodeModulesBinPath,
194243
getConfigFromPackageJson,
195244
};

0 commit comments

Comments
 (0)