Browse Source

Reorganize directories to clean it up and make it more like standard JS projects.

master
Zed A. Shaw 5 months ago
parent
commit
7a7dd348b6
56 changed files with 50 additions and 42 deletions
  1. +0
    -0
      __tests__/fixtures/db/blog/index.json
  2. +0
    -0
      __tests__/fixtures/db/blog/posts/01-first-blog-post.md
  3. +0
    -0
      __tests__/fixtures/db/live/index.json
  4. +0
    -0
      __tests__/fixtures/db/live/streams/20200422-html-basics-ex02-attributes.md
  5. +0
    -0
      __tests__/fixtures/db/live/streams/20200423-test-2.md
  6. +0
    -0
      __tests__/fixtures/db/live/streams/20200424-test-3.md
  7. +0
    -0
      __tests__/fixtures/db/live/streams/20200425-test-4.md
  8. +0
    -0
      __tests__/fixtures/db/live/streams/20200426-test-5.md
  9. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/01-intro.md
  10. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/02-attributes.md
  11. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/03-links.md
  12. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/04-html5.md
  13. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/05-major-tags.md
  14. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/06-major-attributes.md
  15. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/07-layout-tags.md
  16. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/08-tables.md
  17. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/09-forms.md
  18. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/10-forbidden-tags.md
  19. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/11-custom-tags.md
  20. +0
    -0
      __tests__/fixtures/db/modules/example/exercises/12-final-exam.md
  21. +0
    -0
      __tests__/fixtures/db/modules/example/index.json
  22. +0
    -0
      __tests__/models/auth.spec.js
  23. +0
    -0
      __tests__/models/user.spec.js
  24. +0
    -0
      __tests__/models/user_auth.spec.js
  25. +0
    -0
      __tests__/models/user_episode_state.spec.js
  26. +0
    -0
      __tests__/models/user_exercise_state.spec.js
  27. +0
    -0
      __tests__/models/user_module_state.spec.js
  28. +0
    -0
      __tests__/security/access.spec.js
  29. +0
    -0
      __tests__/ui/blog.spec.js
  30. +0
    -0
      __tests__/ui/live.spec.js
  31. +0
    -0
      __tests__/ui/login.spec.js
  32. +0
    -0
      __tests__/ui/modules.spec.js
  33. +0
    -0
      __tests__/ui/phones.spec.js
  34. +0
    -0
      __tests__/ui/register.spec.js
  35. +0
    -0
      __tests__/utils.js
  36. +0
    -0
      docs/DEPLOY.md
  37. +0
    -0
      docs/codecs.txt
  38. +0
    -0
      docs/generator.md
  39. +0
    -0
      docs/video_encode.md
  40. +3
    -3
      ecosystem.config.js
  41. +1
    -1
      jest.config.js
  42. +1
    -1
      lib/testing.js
  43. +1
    -1
      package.json
  44. +1
    -1
      scripts/generator.js
  45. +4
    -4
      scripts/services/auth.js
  46. +35
    -27
      scripts/services/ci.js
  47. +4
    -4
      scripts/services/generator.js
  48. +0
    -0
      scripts/shell/convert.sh
  49. +0
    -0
      scripts/shell/convert_webm.sh
  50. +0
    -0
      scripts/shell/killpg.sh
  51. +0
    -0
      scripts/shell/mktorrents.sh
  52. +0
    -0
      scripts/shell/pgmonit.sh
  53. +0
    -0
      scripts/shell/pull_torrents.js
  54. +0
    -0
      scripts/shell/sync.sh
  55. +0
    -0
      scripts/shell/torrents.prod.sh
  56. +0
    -0
      scripts/shell/torrents.sh

tests/fixtures/db/blog/index.json → __tests__/fixtures/db/blog/index.json View File


tests/fixtures/db/blog/posts/01-first-blog-post.md → __tests__/fixtures/db/blog/posts/01-first-blog-post.md View File


tests/fixtures/db/live/index.json → __tests__/fixtures/db/live/index.json View File


tests/fixtures/db/live/streams/20200422-html-basics-ex02-attributes.md → __tests__/fixtures/db/live/streams/20200422-html-basics-ex02-attributes.md View File


tests/fixtures/db/live/streams/20200423-test-2.md → __tests__/fixtures/db/live/streams/20200423-test-2.md View File


tests/fixtures/db/live/streams/20200424-test-3.md → __tests__/fixtures/db/live/streams/20200424-test-3.md View File


tests/fixtures/db/live/streams/20200425-test-4.md → __tests__/fixtures/db/live/streams/20200425-test-4.md View File


tests/fixtures/db/live/streams/20200426-test-5.md → __tests__/fixtures/db/live/streams/20200426-test-5.md View File


tests/fixtures/db/modules/example/exercises/01-intro.md → __tests__/fixtures/db/modules/example/exercises/01-intro.md View File


tests/fixtures/db/modules/example/exercises/02-attributes.md → __tests__/fixtures/db/modules/example/exercises/02-attributes.md View File


tests/fixtures/db/modules/example/exercises/03-links.md → __tests__/fixtures/db/modules/example/exercises/03-links.md View File


tests/fixtures/db/modules/example/exercises/04-html5.md → __tests__/fixtures/db/modules/example/exercises/04-html5.md View File


tests/fixtures/db/modules/example/exercises/05-major-tags.md → __tests__/fixtures/db/modules/example/exercises/05-major-tags.md View File


tests/fixtures/db/modules/example/exercises/06-major-attributes.md → __tests__/fixtures/db/modules/example/exercises/06-major-attributes.md View File


tests/fixtures/db/modules/example/exercises/07-layout-tags.md → __tests__/fixtures/db/modules/example/exercises/07-layout-tags.md View File


tests/fixtures/db/modules/example/exercises/08-tables.md → __tests__/fixtures/db/modules/example/exercises/08-tables.md View File


tests/fixtures/db/modules/example/exercises/09-forms.md → __tests__/fixtures/db/modules/example/exercises/09-forms.md View File


tests/fixtures/db/modules/example/exercises/10-forbidden-tags.md → __tests__/fixtures/db/modules/example/exercises/10-forbidden-tags.md View File


tests/fixtures/db/modules/example/exercises/11-custom-tags.md → __tests__/fixtures/db/modules/example/exercises/11-custom-tags.md View File


tests/fixtures/db/modules/example/exercises/12-final-exam.md → __tests__/fixtures/db/modules/example/exercises/12-final-exam.md View File


tests/fixtures/db/modules/example/index.json → __tests__/fixtures/db/modules/example/index.json View File


tests/models/auth.spec.js → __tests__/models/auth.spec.js View File


tests/models/user.spec.js → __tests__/models/user.spec.js View File


tests/models/user_auth.spec.js → __tests__/models/user_auth.spec.js View File


tests/models/user_episode_state.spec.js → __tests__/models/user_episode_state.spec.js View File


tests/models/user_exercise_state.spec.js → __tests__/models/user_exercise_state.spec.js View File


tests/models/user_module_state.spec.js → __tests__/models/user_module_state.spec.js View File


tests/security/access.spec.js → __tests__/security/access.spec.js View File


tests/ui/blog.spec.js → __tests__/ui/blog.spec.js View File


tests/ui/live.spec.js → __tests__/ui/live.spec.js View File


tests/ui/login.spec.js → __tests__/ui/login.spec.js View File


tests/ui/modules.spec.js → __tests__/ui/modules.spec.js View File


tests/ui/phones.spec.js → __tests__/ui/phones.spec.js View File


tests/ui/register.spec.js → __tests__/ui/register.spec.js View File


tests/utils.js → __tests__/utils.js View File


notes/DEPLOY.md → docs/DEPLOY.md View File


notes/codecs.txt → docs/codecs.txt View File


notes/generator.md → docs/generator.md View File


notes/video_encode.md → docs/video_encode.md View File


+ 3
- 3
ecosystem.config.js View File

@@ -2,10 +2,10 @@ module.exports = {
apps : [
{
name: 'auth',
script: 'services/auth.js',
script: 'scripts/services/auth.js',
instances: 1,
autorestart: true,
watch: ["lib", "service"],
watch: ["lib", "scripts/services"],
max_memory_restart: '1G',
env: {
NODE_ENV: 'development'
@@ -30,7 +30,7 @@ module.exports = {
},
{
name: 'redis',
script: '/usr/local/bin/redis-server --dir temp',
script: '/usr/local/bin/redis-server --dir /tmp',
instances: 1,
autorestart: true,
watch: false,


+ 1
- 1
jest.config.js View File

@@ -17,7 +17,7 @@ module.exports = {
snapshotSerializers: [
],
testMatch: [
'**/tests/*/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
'**/__tests__/*/**/*.spec.(js|jsx|ts|tsx)'
],
testURL: 'http://localhost:3000/',
globals: {


+ 1
- 1
lib/testing.js View File

@@ -47,7 +47,7 @@ const device_check = async (start, device) => {

page.setViewport({width, height});

await page.screenshot({ path: `devices/${device}.jpeg`,
await page.screenshot({ path: `__tests__/devices/${device}.jpeg`,
clip: {x: 0, y: 0, width, height },
type: 'jpeg',
quality: 80,


+ 1
- 1
package.json View File

@@ -8,7 +8,7 @@
"export": "sapper export --legacy -p 7778",
"start": "node __sapper__/build",
"test": "NODE_OPTIONS='--unhandled-rejections=strict' jest --detectOpenHandles --bail --forceExit",
"fixtures": "rm -rf deployment/testing/* protected && ln -sf ./deployment/testing protected && node generator.js -d -w -s tests/fixtures -t protected",
"fixtures": "rm -rf deployment/testing/* protected && ln -sf ./deployment/testing protected && node scripts/generator.js -d -w -s __tests__/fixtures -t protected",
"testwatch": "NODE_OPTIONS='--unhandled-rejections=strict' jest --watch --notify --detectOpenHandles",
"deploy": "npx sapper export && rsync -azzv __sapper__/export/ $DEP_USER@learnjsthehardway.com:/srv/http/www/learnjsthehardway.com/"
},


generator.js → scripts/generator.js View File

@@ -1,7 +1,7 @@
const { program } = require('commander');
const watch = require('watch');
const generator = require('./services/generator');
const { log } = require('./lib/logging');
const { log } = require('../lib/logging');

program.version('0.0.2');
program.option('-s, --source <path>', 'source directory to read');

services/auth.js → scripts/services/auth.js View File

@@ -1,9 +1,9 @@
const Queue = require('bull');
const { User, Auth } = require('../lib/models');
const { log } = require('../lib/logging');
const train = require('../lib/train');
const { User, Auth } = require('../../lib/models');
const { log } = require('../../lib/logging');
const train = require('../../lib/train');
const assert = require('assert');
const { transporter } = require('../lib/mail');
const { transporter } = require('../../lib/mail');

const gen_reg_email = (to, authtoken) => {
return {

services/ci.js → scripts/services/ci.js View File

@@ -1,9 +1,9 @@
// const Queue = require('bull');
const secrets = require('../lib/secrets');
const secrets = require('../../lib/secrets');
const generator = require('./generator');
const build = require('../lib/builderator');
const { log } = require('../lib/logging');
const { transporter } = require('../lib/mail');
const build = require('../../lib/builderator');
const { log } = require('../../lib/logging');
const { transporter } = require('../../lib/mail');
const fs = require('fs').promises;
const exists = require('fs').existsSync;
const pm2 = require('pm2');
@@ -12,8 +12,25 @@ const assert = require('assert');

// const gitQ = new Queue('ci.git', secrets.redis);

const dev_server_wait = {resources: ['http://localhost:3000'], delay: 1000, timeout: 30000};
const prod_server_wait = {resources: ['http://localhost:7778'], delay: 1000, timeout: 30000};
const config = {
private: '../ljsthw-private/',
testing_target: 'deployment/testing',
prod_target: 'deployment/production',
fixtures: '__tests__/fixtures',
email: {
to: 'zed@learnjsthehardway.com',
from: '"CI from LJSTHW" ci@learnjsthehardway.com',
subject: 'Build complete',
text: `CI build completed.`
},
state_file: 'deployment/cistate.json',
dev_server_wait: {
resources: ['http://localhost:3000'], delay: 1000, timeout: 30000
},
prod_server_wait: {
resources: ['http://localhost:7778'], delay: 1000, timeout: 30000
}
}

const pm2_restart = (name) => {
log.debug(`Restarting the ${name} process.`);
@@ -47,22 +64,22 @@ const needs_tests = build.rule('needs tests run', {
then: async (f) => {
log.info("Generating test fixtures");
// generate test fixtures
await generator.run('tests/fixtures', 'deployment/testing');
await generator.run(config.fixtures, config.testing_target);

log.debug('Linking in the new content');
if(exists('protected')) {
await fs.unlink('protected'); // removes the symlink
}

log.debug('Creating symlink protected to deployment/testing');
await fs.symlink('./deployment/testing', 'protected');
log.debug(`Creating symlink protected to ${config.testing_target}`);
await fs.symlink(config.testing_target, 'protected');

log.debug("Finished generating the tests now running them.");

process.env.HEADLESS=1;

pm2_restart('ljsthw-dev');
await waitOn(dev_server_wait);
await waitOn(config.dev_server_wait);

log.info("---- Running tests...");
let res = build.exec('npm run test');
@@ -81,7 +98,7 @@ const needs_git_pull = build.rule('needs git pull', {
let git = build.exec(`git pull`, {}).toString();
log.debug("GIT code", git);
f.code_updated = git != 'Already up to date.\n';
git = build.exec(`git pull`, {cwd: '../ljsthw-private'}).toString();
git = build.exec(`git pull`, {cwd: config.private}).toString();
f.media_updated = git != 'Already up to date.\n';
log.debug("GIT media", git);

@@ -95,15 +112,7 @@ const needs_email_notify = build.rule('needs email notification', {
then: f => {
log.info("Sending notification email with results.");
// email that it's done for visual testing

let options = {
to: 'zed@learnjsthehardway.com',
from: '"CI from LJSTHW" ci@learnjsthehardway.com',
subject: 'Build complete',
text: `CI build completed.`
}

transporter.sendMail(options, (err, info) => {
transporter.sendMail(config.email, (err, info) => {
if(err) {
log.error(err);
} else {
@@ -125,7 +134,8 @@ const needs_prod_media = build.rule('needs production media', {
// need to get the videos into the web server somehow
// and other media. Need a difference between generated media and source media
// why can't source media be in the db?
await generator.run('../ljsthw-private', 'deployment/production');
await generator.run(config.private, config.prod_target);

f.prod_media_ready = true;
}
@@ -143,7 +153,7 @@ const needs_prod_code = build.rule('needs production code', {

// tell pm2 reload
pm2_restart('ljsthw');
await waitOn(prod_server_wait);
await waitOn(config.prod_server_wait);

f.build_complete = true;
}
@@ -155,13 +165,11 @@ const targets = [
needs_git_pull, needs_tests
]

const state_file = 'deployment/cistate.json';

const run = async () => {
let facts;

if(exists(state_file)) {
facts = JSON.parse(await fs.readFile(state_file));
if(exists(config.state_file)) {
facts = JSON.parse(await fs.readFile(config.state_file));
log.debug("FACTS", facts);
} else {
facts = {git_push_received: true};
@@ -172,7 +180,7 @@ const run = async () => {
} catch(error) {
log.error(error, "Running build.");
} finally {
await fs.writeFile(state_file, JSON.stringify(facts));
await fs.writeFile(config.state_file, JSON.stringify(facts));
}
}


services/generator.js → scripts/services/generator.js View File

@@ -1,15 +1,15 @@
const build = require('../lib/builderator');
const { log } = require('../lib/logging');
const build = require('../../lib/builderator');
const { log } = require('../../lib/logging');
const fs = require('fs');
const _ = require('lodash');
const rules = require('../lib/buildrules');
const rules = require('../../lib/buildrules');
const sharp = require('sharp');
const exif = require('fast-exif');
const cleaner = require('deep-cleaner');
const glob = require('glob').sync;
const path = require('path');
const Feed = require('feed').Feed;
const secrets = require('../lib/secrets');
const secrets = require('../../lib/secrets');

const inject_json = (target, data) => {
return JSON.stringify({

tools/convert.sh → scripts/shell/convert.sh View File


tools/convert_webm.sh → scripts/shell/convert_webm.sh View File


tools/killpg.sh → scripts/shell/killpg.sh View File


tools/mktorrents.sh → scripts/shell/mktorrents.sh View File


tools/pgmonit.sh → scripts/shell/pgmonit.sh View File


tools/pull_torrents.js → scripts/shell/pull_torrents.js View File


tools/sync.sh → scripts/shell/sync.sh View File


tools/torrents.prod.sh → scripts/shell/torrents.prod.sh View File


tools/torrents.sh → scripts/shell/torrents.sh View File


Loading…
Cancel
Save