Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | 5x 5x 5x | import {join} from 'path';
import {
EslintConfigModuleEditor,
PackageJsonEditor,
Scaffolder,
allDoExist,
allDoExistSync,
install
} from '../../api';
const DEPENDENCIES = [
'apollo-server-express',
'compression',
'config',
'cookie-session',
'dotenv',
'ejs',
'express',
'express-session',
'feature-policy',
'fs-extra',
'graphql',
'helmet',
'lusca',
'remarkable',
'highlight.js',
'uuid',
'npmlog',
'protocolify',
'ws'
];
const DEV_DEPENDENCIES = [
'autocannon',
'clinic',
'nodemon',
'npm-run-all',
'open-cli',
'stmux',
'supertest',
'wait-on'
];
/**
* @type {task[]}
* @see https://expressjs.com/
* @see https://github.com/websockets/ws
* @see https://www.apollographql.com/docs/apollo-server/
*/
export const tasks = [
{
text: 'Copy server files',
task: async ({overwrite}) => {
await (new Scaffolder(join(__dirname, 'templates')))
.overwrite(overwrite)
.target('./')
.copy('.env')
.copy('favicon.ico')
.copy('_gitignore', '.gitignore')
.copy('index.js')
.copy('server.js')
.copy('socket.js')
.copy('graphql.js')
.copy('db.json')
.target('config')
.copy('default.js')
.copy('default.js', 'test.js')
.target('ssl')
.copy('server.key')
.copy('server.cert')
.target('public')
.copy('index.html')
.copy('main.js')
.copy('example.md')
.target('__tests__')
.overwrite(true)
.copy('example.test.js')
.commit();
},
condition: () => true
},
{
text: 'Configure metadata and add tasks to package.json',
task: async () => {
const description = `Node.js HTTP(S), WebSocket, and GraphQL servers with an 80% solution for security 'baked in'`;
const main = 'index.js';
const name = 'server-made-with-tomo';
const PORT = 8111;
const scripts = {
'dev:wait': `wait-on http://localhost:${PORT}`,
'dev:open': 'npm-run-all --silent dev:wait open',
'dev:start': `stmux [ "nodemon ${main}" : "npm run lint:ing" ]`,
dev: 'npm-run-all --parallel dev:open dev:start',
prestart: 'npm audit --production',
start: `node ${main}`,
open: `open-cli http://localhost:${PORT}`,
'perf:measure': `autocannon -c 1000 -d 30 http://localhost:${PORT}`,
'perf:analyze': `clinic doctor -- node ${main}`
};
await (new PackageJsonEditor())
.extend({description, main, name, scripts})
.commit();
},
condition: () => allDoExist('package.json')
},
{
text: 'Configure .eslintrc.js for use with Node.js',
task: async ({browser}) => {
const env = {
browser,
node: true
};
await (new EslintConfigModuleEditor())
.extend({env})
.commit();
},
condition: () => allDoExist('.eslintrc.js'),
optional: () => allDoExistSync('.eslintrc.js')
},
{
text: 'Install server dependencies',
task: async ({skipInstall}) => {
await install(DEPENDENCIES, {skipInstall});
await install(DEV_DEPENDENCIES, {dev: true, skipInstall});
},
condition: ({skipInstall}) => !skipInstall && allDoExist('package.json')
}
];
export default tasks; |