@fishawack/lab-env 1.6.3

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 (58) hide show
  1. package/.gitattributes +1 -0
  2. package/CHANGELOG.md +234 -0
  3. package/README.md +197 -0
  4. package/cli.js +71 -0
  5. package/commands/artisan.js +15 -0
  6. package/commands/check.js +16 -0
  7. package/commands/clean.js +16 -0
  8. package/commands/composer.js +15 -0
  9. package/commands/connect.js +15 -0
  10. package/commands/content.js +10 -0
  11. package/commands/create/cmds/delete.js +27 -0
  12. package/commands/create/cmds/diagnose.js +77 -0
  13. package/commands/create/cmds/new.js +48 -0
  14. package/commands/create/libs/prompts.js +60 -0
  15. package/commands/create/libs/utilities.js +50 -0
  16. package/commands/create/libs/vars.js +95 -0
  17. package/commands/create/services/api.js +3 -0
  18. package/commands/create/services/bitbucket.js +92 -0
  19. package/commands/create/services/egnyte.js +31 -0
  20. package/commands/create/services/git.js +31 -0
  21. package/commands/create/services/gitlab.js +30 -0
  22. package/commands/create/services/guide.js +296 -0
  23. package/commands/create/services/test.js +138 -0
  24. package/commands/deploy.js +23 -0
  25. package/commands/docker/build.js +10 -0
  26. package/commands/docker/config.js +10 -0
  27. package/commands/docker/down.js +10 -0
  28. package/commands/docker/mocha.js +10 -0
  29. package/commands/docker/rebuild.js +10 -0
  30. package/commands/docker/up.js +15 -0
  31. package/commands/docker/volumes.js +27 -0
  32. package/commands/execute.js +21 -0
  33. package/commands/install.js +15 -0
  34. package/commands/npm.js +15 -0
  35. package/commands/nuke.js +17 -0
  36. package/commands/origin.js +126 -0
  37. package/commands/php.js +15 -0
  38. package/commands/production.js +10 -0
  39. package/commands/regenerate.js +16 -0
  40. package/commands/reinstall.js +16 -0
  41. package/commands/run.js +25 -0
  42. package/commands/setup.js +27 -0
  43. package/commands/start.js +33 -0
  44. package/commands/test.js +22 -0
  45. package/commands/uninstall.js +15 -0
  46. package/commands/watch.js +20 -0
  47. package/core/0.0.19/Dockerfile +234 -0
  48. package/core/0.0.19/docker-compose.yml +27 -0
  49. package/core/0.0.19/entrypoint.sh +4 -0
  50. package/globals.js +85 -0
  51. package/intercept.sh +37 -0
  52. package/laravel/8/docker-compose.yml +49 -0
  53. package/laravel/8/nginx/nginx.conf +37 -0
  54. package/laravel/8/php/custom.conf +7 -0
  55. package/package.json +33 -0
  56. package/wordpress/5.7.2/apache/.htaccess +25 -0
  57. package/wordpress/5.7.2/apache/uploads.ini +6 -0
  58. package/wordpress/5.7.2/docker-compose.yml +42 -0
@@ -0,0 +1,138 @@
1
+ const os = require('os');
2
+ const fs = require('fs');
3
+
4
+ const utils = require('../libs/utilities');
5
+ const vars = require('../libs/vars');
6
+
7
+ module.exports.targets = async () => {
8
+ // Check targets folder exists
9
+ let spinner = new utils.Spinner('Looking for targets folder');
10
+
11
+ if (fs.existsSync(`${os.homedir()}/targets`)) {
12
+ spinner.update('Found \'targets\' folder');
13
+ return true;
14
+ } else {
15
+ spinner.update('Could not find targets folder', 'fail');
16
+ }
17
+ }
18
+
19
+ module.exports.misc = async () => {
20
+ // Check misc.json exists
21
+ let spinner = new utils.Spinner('Looking for misc file in targets');
22
+
23
+ if (fs.existsSync(`${os.homedir()}/targets/misc.json`)) {
24
+ spinner.update('Found \'misc.json\' file');
25
+ return true;
26
+ } else {
27
+ spinner.update('Could not find \'misc.json\' file', 'fail');
28
+ }
29
+ }
30
+
31
+ module.exports.bitbucket = async () => {
32
+ // Check misc.json has Bitbucket credentials
33
+ let spinner = new utils.Spinner('Looking for Bitbucket credentials and workspace UUID');
34
+
35
+ if (vars.misc.bitbucket && vars.misc.bitbucket.username && vars.misc.bitbucket.password && vars.misc.bitbucket.workspace) {
36
+ spinner.update('Found Bitbucket credentials and workspace UUID in \'misc.json\'');
37
+ return true;
38
+ } else {
39
+ spinner.update('Couldn\'t find Bitbucket credentials or workspace UUID in \'misc.json\'', 'fail');
40
+ }
41
+ }
42
+
43
+ module.exports.gitlab = async () => {
44
+ // Check misc.json has GitLab token
45
+ let spinner = new utils.Spinner('Looking for Gitlab credentials');
46
+
47
+ if (vars.misc.gitlab && vars.misc.gitlab.token) {
48
+ spinner.update('Found GitLab token in \'misc.json\'');
49
+ return true;
50
+ } else {
51
+ spinner.update('Could not find GitLab token in \'misc.json\'', 'info');
52
+ }
53
+ }
54
+
55
+ module.exports.ftppass = async () => {
56
+ // Check .ftppass exists
57
+ let spinner = new utils.Spinner('Looking for .ftppass file in targets');
58
+
59
+ if (fs.existsSync(`${os.homedir()}/targets/.ftppass`)) {
60
+ spinner.update('Found \'.ftppass\' file');
61
+ return true;
62
+ } else {
63
+ spinner.update('Could not find \'.ftppass\' file', 'fail');
64
+ }
65
+ }
66
+
67
+ module.exports.egnyte = async () => {
68
+ // Check .ftppass has Egnyte credentials
69
+ let spinner = new utils.Spinner('Looking for Egnyte credentials');
70
+
71
+ if (vars.ftppass['ftp-fishawack.egnyte.com'] && vars.ftppass['ftp-fishawack.egnyte.com'].username && vars.ftppass['ftp-fishawack.egnyte.com'].password) {
72
+ spinner.update('Found Egnyte credentials in \'.ftppass\'');
73
+ return true;
74
+ } else {
75
+ spinner.update('Couldn\'t find Egnyte credentials in \'.ftppass\'', 'fail');
76
+ }
77
+ }
78
+
79
+ module.exports.config = async () => {
80
+ // Check ssh config exists
81
+ let spinner = new utils.Spinner('Looking for ssh config file in .ssh');
82
+
83
+ if (fs.existsSync(`${os.homedir()}/.ssh/config`)) {
84
+ spinner.update('Found \'config\' file');
85
+ return true;
86
+ } else {
87
+ spinner.update('Could not find \'config\' file', 'fail');
88
+ }
89
+ }
90
+
91
+
92
+ module.exports.ignore = async () => {
93
+ // Check misc.json has Bitbucket credentials
94
+ let spinner = new utils.Spinner('Looking for IgnoreUnknown option in config');
95
+
96
+ if (fs.readFileSync(`${os.homedir()}/.ssh/config`, { encoding: 'utf8' }).includes(`Host *\n\tIgnoreUnknown AddKeysToAgent,UseKeychain`)) {
97
+ spinner.update('Found IgnoreUnknown option in \'config\'');
98
+ return true;
99
+ } else {
100
+ spinner.update('Couldn\'t find IgnoreUnknown option in \'config\'', 'fail');
101
+ }
102
+ }
103
+
104
+ module.exports.strict = async () => {
105
+ // Check misc.json has Bitbucket credentials
106
+ let spinner = new utils.Spinner('Looking for StrictHostKeyChecking option in config');
107
+
108
+ if (fs.readFileSync(`${os.homedir()}/.ssh/config`, { encoding: 'utf8' }).includes(`Host *\n\tStrictHostKeyChecking no`)) {
109
+ spinner.update('Found StrictHostKeyChecking option in \'config\'');
110
+ return true;
111
+ } else {
112
+ spinner.update('Couldn\'t find StrictHostKeyChecking option in \'config\'', 'fail');
113
+ }
114
+ }
115
+
116
+ module.exports.ssh = async () => {
117
+ // Check targets folder exists
118
+ let spinner = new utils.Spinner('Looking for .ssh folder');
119
+
120
+ if (fs.existsSync(`${os.homedir()}/.ssh`)) {
121
+ spinner.update('Found \'.ssh\' folder');
122
+ return true;
123
+ } else {
124
+ spinner.update('Could not find .ssh folder', 'fail');
125
+ }
126
+ }
127
+
128
+ module.exports.key = async () => {
129
+ // Check misc.json exists
130
+ let spinner = new utils.Spinner('Looking for id_rsa file in .ssh');
131
+
132
+ if (fs.existsSync(`${os.homedir()}/.ssh/id_rsa`)) {
133
+ spinner.update('Found \'id_rsa\' file');
134
+ return true;
135
+ } else {
136
+ spinner.update('Could not find \'id_rsa\' file', 'fail');
137
+ }
138
+ }
@@ -0,0 +1,23 @@
1
+ const _ = require('../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ 'deploy',
7
+ 'deploys the repo',
8
+ yargs => {},
9
+ argv => {
10
+ if(_.platform === "laravel" || _.platform === "wordpress"){
11
+ execSync(`lab-env up -d`, _.opts);
12
+
13
+ // Run deploy.sh directly as other containers need to run not just node/core
14
+ try{
15
+ execSync(`source ${__dirname}/../intercept.sh && /bin/bash ./_Scripts/deploy.sh`, _.opts);
16
+ } finally{
17
+ execSync(`lab-env down`, _.opts);
18
+ }
19
+ } else {
20
+ execSync(`${_.docker} ${_.run}c "xvfb-run npm run deploy"`, _.opts);
21
+ }
22
+ }
23
+ ];
@@ -0,0 +1,10 @@
1
+ const _ = require('../../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ 'build',
7
+ false,
8
+ yargs => {},
9
+ argv => execSync(`${_.docker} build`, _.opts)
10
+ ];
@@ -0,0 +1,10 @@
1
+ const _ = require('../../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ 'config',
7
+ false,
8
+ yargs => {},
9
+ argv => execSync(`${_.docker} config`, _.opts)
10
+ ];
@@ -0,0 +1,10 @@
1
+ const _ = require('../../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ 'down',
7
+ false,
8
+ yargs => {},
9
+ argv => execSync(`${_.docker} down`, _.opts)
10
+ ];
@@ -0,0 +1,10 @@
1
+ const _ = require('../../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ 'mocha',
7
+ false,
8
+ yargs => {},
9
+ argv => execSync(`${_.docker} ${_.run}c "xvfb-run npm run mocha"`, _.opts)
10
+ ];
@@ -0,0 +1,10 @@
1
+ const _ = require('../../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ 'rebuild',
7
+ false,
8
+ yargs => {},
9
+ argv => execSync(`${_.docker} build --no-cache`, _.opts)
10
+ ];
@@ -0,0 +1,15 @@
1
+ const _ = require('../../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ 'up [flags...]',
7
+ false,
8
+ yargs => {
9
+ yargs.positional('flags', {
10
+ describe: 'flags to pass',
11
+ default: ''
12
+ });
13
+ },
14
+ argv => execSync(`${_.docker} up ${argv.flags.join(' ')}`, _.opts)
15
+ ];
@@ -0,0 +1,27 @@
1
+ const _ = require('../../globals.js');
2
+
3
+ module.exports = [
4
+ 'volumes',
5
+ false,
6
+ yargs => {},
7
+ argv => {
8
+ let volumes = [
9
+ 'node_modules'
10
+ ];
11
+
12
+ if(_.platform === "laravel" || _.platform === "wordpress"){
13
+ volumes.push(
14
+ 'mysql'
15
+ );
16
+ }
17
+
18
+ if(_.platform === "laravel"){
19
+ volumes.push(
20
+ 'vendor',
21
+ 'redis'
22
+ );
23
+ }
24
+
25
+ console.log(`${volumes.map(d => `${_.repo_safe}_${d}`).join('\n')}`);
26
+ }
27
+ ];
@@ -0,0 +1,21 @@
1
+ const _ = require('../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ ['execute [command...]', 'exec'],
7
+ 'run a custom command in the container',
8
+ yargs => {
9
+ yargs.positional('command', {
10
+ describe: 'command to run',
11
+ default: 'ls'
12
+ });
13
+
14
+ yargs.option('display', {
15
+ alias: 'd',
16
+ describe: 'Run with a virtual display',
17
+ type: 'boolean'
18
+ });
19
+ },
20
+ argv => execSync(`${_.docker} ${_.run}c "${argv.d ? 'xvfb-run ' : ''}${argv.command.join(' ')}"`, _.opts)
21
+ ];
@@ -0,0 +1,15 @@
1
+ const _ = require('../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ ['install [package...]', 'i'],
7
+ 'runs npm install or installs a package/packages',
8
+ yargs => {
9
+ yargs.positional('package', {
10
+ describe: 'package to install',
11
+ default: ''
12
+ });
13
+ },
14
+ argv => execSync(`${_.docker} ${_.run}c "npm install ${argv.package.join(' ')}"`, _.opts)
15
+ ];
@@ -0,0 +1,15 @@
1
+ const _ = require('../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ 'npm [command...]',
7
+ 'run npm command',
8
+ yargs => {
9
+ yargs.positional('command', {
10
+ describe: 'command to run',
11
+ default: ''
12
+ });
13
+ },
14
+ argv => execSync(`${_.docker} ${_.run}c "npm ${argv.command.join(' ')}"`, _.opts)
15
+ ];
@@ -0,0 +1,17 @@
1
+ const _ = require('../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+
5
+ module.exports = [
6
+ 'nuke',
7
+ 'cleans out all files not tracked by git',
8
+ yargs => {},
9
+ argv => {
10
+ execSync(`git clean -xfd`, _.opts);
11
+
12
+ // Remove all virtual volumes
13
+ try{
14
+ execSync(`lab-env volumes | xargs docker volume rm $@`, _.opts);
15
+ } catch(e){}
16
+ }
17
+ ];
@@ -0,0 +1,126 @@
1
+ const _ = require('../globals.js');
2
+
3
+ const execSync = require('child_process').execSync;
4
+ const path = require('path');
5
+ const chalk = require('chalk');
6
+
7
+ module.exports = [
8
+ 'origin',
9
+ 'add gitlab as a second remote',
10
+ yargs => {},
11
+ argv => {
12
+ try{
13
+ let misc = require(path.join(require('os').homedir(), 'targets', 'misc.json'));
14
+ let username = misc.bitbucket.username;
15
+ let password = misc.bitbucket.password;
16
+ let workspace = misc.gitlab.workspace;
17
+ let token = misc.gitlab.token;
18
+
19
+ let url = {
20
+ bitbucket: `https://api.bitbucket.org/2.0/repositories/fishawackdigital/${_.repo}`,
21
+ gitlab: `curl -H "Content-Type:application/json" http://${workspace}/api/v4/`
22
+ };
23
+ let info;
24
+ let group;
25
+ let fullpath;
26
+
27
+ if(!username || !password){
28
+ console.log("Can't find bitbucket credentials in ~/targets/misc.json");
29
+ } else {
30
+ try{
31
+ info = JSON.parse(execSync(`curl --connect-timeout 5 -s -u "${username}":"${password}" ${url.bitbucket}`, {encoding: 'utf8', stdio: 'pipe'}));
32
+ group = info.project.name.toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'-');
33
+ fullpath = `${group}/${_.repo}`;
34
+ } catch (e){
35
+ console.log(`Can't connect to ${url.bitbucket}`);
36
+ return;
37
+ }
38
+
39
+ let bitbucket = `git@bitbucket.org:fishawackdigital/${_.repo}`;
40
+ let gitlab = `git@diggit01.fw.local:${fullpath}`;
41
+
42
+ execSync(`
43
+ git remote remove origin 2>/dev/null;
44
+ git remote add origin ${bitbucket};
45
+ git remote set-url --add --push origin ${bitbucket};
46
+ git remote set-url --add --push origin ${gitlab};
47
+ git fetch origin;
48
+ git branch -u origin/production production 2>/dev/null;
49
+ git branch -u origin/master master 2>/dev/null;
50
+ git branch -u origin/staging staging 2>/dev/null;
51
+ git branch -u origin/development development 2>/dev/null;
52
+ echo "\\033[0;32mSuccess\\033[0m"
53
+ `, _.opts);
54
+
55
+ var res = {};
56
+
57
+ if(!username || !password){
58
+ console.log("Can't find gitlab credentials in ~/targets/misc.json");
59
+ } else {
60
+ try{
61
+ // Check group
62
+ console.log(`Checking if group ${group} exists...`);
63
+ res.group = JSON.parse(execSync(`${url.gitlab}groups?search=${group}`, {encoding: 'utf8', stdio: 'pipe'}))
64
+ .find(d => d.name === group);
65
+
66
+ if(!res.group){
67
+ console.log(`${chalk.yellow(`Group not found`)}`);
68
+
69
+ // Create group
70
+ console.log(`Creating group: ${group}...`);
71
+
72
+ res.group = JSON.parse(execSync(`${url.gitlab}groups?private_token=${token} -d ${JSON.stringify(JSON.stringify(
73
+ {
74
+ "name": group,
75
+ "path": group,
76
+ "visibility": "public"
77
+ }
78
+ ))}`, {encoding: 'utf8', stdio: 'pipe'}));
79
+
80
+ console.log(`${chalk.green(`Group created`)}`);
81
+ } else {
82
+ console.log(`${chalk.green(`Group found`)}`);
83
+ }
84
+
85
+ // Adding users
86
+ console.log(`Ensuring users have access to ${group}...`);
87
+
88
+ var users = JSON.parse(execSync(`${url.gitlab}users?private_token=${token}`, {encoding: 'utf8', stdio: 'pipe'}));
89
+
90
+ execSync(`${url.gitlab}groups/${res.group.id}/members?private_token=${token} -d ${JSON.stringify(JSON.stringify(
91
+ {
92
+ "id": 3,
93
+ "user_id": users.map(d => d.id).join(','),
94
+ "access_level": 50
95
+ }
96
+ ))}`, {encoding: 'utf8', stdio: 'pipe'});
97
+
98
+ console.log(`${chalk.green(`Users with access: ${users.length}`)}`);
99
+
100
+ // Create project
101
+ console.log(`Creating project ${_.repo}...`);
102
+
103
+ res.project = JSON.parse(execSync(`${url.gitlab}projects?private_token=${token} -d ${JSON.stringify(JSON.stringify(
104
+ {
105
+ "name": _.repo,
106
+ "path": _.repo,
107
+ "namespace_id": res.group.id,
108
+ "visibility": "public"
109
+ }
110
+ ))}`, {encoding: 'utf8', stdio: 'pipe'}));
111
+
112
+ if(res.project.message){
113
+ console.log(`${chalk.green(`Project already exists`)}`);
114
+ } else {
115
+ console.log(`${chalk.green(`Project created`)}`);
116
+ }
117
+ } catch(e){
118
+ console.log(e.message, `Can't resolve host: ${workspace}`);
119
+ }
120
+ }
121
+ }
122
+ } catch(e){
123
+ console.log("Can't find ~/targets/misc.json", e);
124
+ }
125
+ }
126
+ ];