Skip to content

Commit 7901b87

Browse files
committed
🔩 Set up a new nodejs development environment
1 parent 21bf648 commit 7901b87

16 files changed

+177
-5
lines changed

packages/mocha-setup/package.json

-5
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,5 @@
2727
"mocha": "^6.2.2",
2828
"sinon": "^7.5.0",
2929
"sinon-chai": "^3.3.0"
30-
},
31-
"devDependencies": {
32-
"@omrilotan/eslint-config": "^1.1.0",
33-
"eslint": "^6.5.1",
34-
"eslint-plugin-log": "^1.2.3"
3530
}
3631
}

packages/setenv/.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.*
2+
*.log

packages/setenv/.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package-lock=false
2+
access=public

packages/setenv/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# setenv [![](https://img.shields.io/npm/v/@omrilotan/setenv.svg)](https://www.npmjs.com/package/@omrilotan/setenv) [![](https://img.shields.io/badge/source--000000.svg?logo=github&style=social)](https://github.com/omrilotan/mono/tree/master/packages/setenv)
2+
3+
```
4+
npx @omrilotan/setenv
5+
```
6+
7+
![](https://user-images.githubusercontent.com/516342/68055642-cdb8b000-fcf9-11e9-8ac4-bb7b535316a8.png)

packages/setenv/bin.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env node
2+
3+
const { resolve, join } = require('path');
4+
const { promises: { copyFile, readdir } } = require('fs');
5+
const { prompt } = require('inquirer');
6+
const exist = require('@does/exist');
7+
const exec = require('async-execute');
8+
9+
(async() => {
10+
await fixtures();
11+
await dependencies();
12+
})();
13+
14+
15+
async function dependencies() {
16+
const dir = join(__dirname, 'devDependencies');
17+
const devDependencies = await readdir(dir);
18+
19+
while(devDependencies.length) {
20+
const dependency = devDependencies.pop();
21+
const list = require(join(dir, dependency));
22+
const { dependencies } = await prompt([{
23+
name: 'dependencies',
24+
type: 'checkbox',
25+
message: `Pick devDependencies to install for ${dependency.split('.').shift()}`,
26+
choices: list.map(name => (
27+
{ name, value: name, checked: true }
28+
)),
29+
}]);
30+
31+
await exec(
32+
`npm i -D ${dependencies.map(d => [d, 'latest'].join('@')).join(' ')}`,
33+
{ pipe: true }
34+
);
35+
}
36+
}
37+
38+
async function fixtures() {
39+
const dir = join(__dirname, 'fixtures');
40+
const fixtures = await readdir(dir);
41+
42+
while (fixtures.length) {
43+
const fixture = fixtures.pop();
44+
const target = fixture.replace(/^__/, '.');
45+
const source = join(dir, fixture);
46+
const destination = resolve(target);
47+
48+
const exists = await exist(destination);
49+
50+
const { answer } = await prompt([{
51+
name: 'answer',
52+
type: 'confirm',
53+
message: [
54+
exists ? 'Override' : 'Create',
55+
target,
56+
'?',
57+
].join(' '),
58+
default: !exists,
59+
}]);
60+
61+
answer && await copyFile(source, destination);
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
"@omrilotan/eslint-config",
3+
"eslint",
4+
"eslint-plugin-log"
5+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
"abuser",
3+
"chai",
4+
"chai-as-promised",
5+
"chai-string",
6+
"deep-equal-in-any-order",
7+
"mocha",
8+
"sinon",
9+
"sinon-chai"
10+
]
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
charset = utf-8
9+
indent_style = tab
10+
tab_width = 2
11+
12+
[*.{yml,json}]
13+
indent_size = 2
14+
indent_style = space

packages/setenv/fixtures/.eslintrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
extends: "@omrilotan",
3+
overrides: [
4+
{
5+
"files": [ "**/spec.js" ],
6+
"globals": {
7+
"abuser": true,
8+
"fake": true,
9+
"stub": true,
10+
"spy": true
11+
}
12+
}
13+
]
14+
}

packages/setenv/fixtures/.mocha.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const chai = require('chai');
2+
const sinon = require('sinon');
3+
const abuser = require('abuser');
4+
5+
chai.use(require('chai-as-promised'));
6+
chai.use(require('chai-string'));
7+
chai.use(require('deep-equal-in-any-order'));
8+
chai.use(require('sinon-chai'));
9+
10+
Object.assign(
11+
global,
12+
chai,
13+
sinon,
14+
{
15+
sinon,
16+
abuser,
17+
},
18+
);

packages/setenv/fixtures/.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12

packages/setenv/fixtures/LICENSE

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) <year> <copyright holders>
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

packages/setenv/fixtures/__gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
*.log
3+
node_modules
4+
package-lock.json

packages/setenv/fixtures/__npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.*
2+
*.log
3+
spec.js

packages/setenv/fixtures/__npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package-lock=false
2+
access=public

packages/setenv/package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@omrilotan/setenv",
3+
"version": "0.0.0",
4+
"description": "🔩 Set up a new nodejs development environment",
5+
"keywords": [
6+
"development",
7+
"environment",
8+
"setup",
9+
"🔩"
10+
],
11+
"author": "omrilotan",
12+
"license": "MIT",
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/omrilotan/mono.git"
16+
},
17+
"homepage": "https://omrilotan.com/mono/setenv/",
18+
"bin": "bin.js",
19+
"dependencies": {
20+
"@does/exist": "^1.0.0",
21+
"async-execute": "^1.1.0",
22+
"inquirer": "^7.0.0"
23+
}
24+
}

0 commit comments

Comments
 (0)