서준혁

set frontend development environment

1 +/node_modules/
2 +/public/build/
3 +
4 +.DS_Store
1 -var createError = require('http-errors');
2 -var express = require('express');
3 -var path = require('path');
4 -var cookieParser = require('cookie-parser');
5 -var logger = require('morgan');
6 -
7 -var indexRouter = require('./routes/index');
8 -var usersRouter = require('./routes/users');
9 -
10 -var app = express();
11 -
12 -// view engine setup
13 -app.set('views', path.join(__dirname, 'views'));
14 -app.set('view engine', 'ejs');
15 -
16 -app.use(logger('dev'));
17 -app.use(express.json());
18 -app.use(express.urlencoded({ extended: false }));
19 -app.use(cookieParser());
20 -app.use(express.static(path.join(__dirname, 'public')));
21 -
22 -app.use('/', indexRouter);
23 -app.use('/users', usersRouter);
24 -
25 -// catch 404 and forward to error handler
26 -app.use(function(req, res, next) {
27 - next(createError(404));
28 -});
29 -
30 -// error handler
31 -app.use(function(err, req, res, next) {
32 - // set locals, only providing error in development
33 - res.locals.message = err.message;
34 - res.locals.error = req.app.get('env') === 'development' ? err : {};
35 -
36 - // render the error page
37 - res.status(err.status || 500);
38 - res.render('error');
39 -});
40 -
41 -module.exports = app;
1 -#!/usr/bin/env node
2 -
3 -/**
4 - * Module dependencies.
5 - */
6 -
7 -var app = require('../app');
8 -var debug = require('debug')('tft:server');
9 -var http = require('http');
10 -
11 -/**
12 - * Get port from environment and store in Express.
13 - */
14 -
15 -var port = normalizePort(process.env.PORT || '3000');
16 -app.set('port', port);
17 -
18 -/**
19 - * Create HTTP server.
20 - */
21 -
22 -var server = http.createServer(app);
23 -
24 -/**
25 - * Listen on provided port, on all network interfaces.
26 - */
27 -
28 -server.listen(port);
29 -server.on('error', onError);
30 -server.on('listening', onListening);
31 -
32 -/**
33 - * Normalize a port into a number, string, or false.
34 - */
35 -
36 -function normalizePort(val) {
37 - var port = parseInt(val, 10);
38 -
39 - if (isNaN(port)) {
40 - // named pipe
41 - return val;
42 - }
43 -
44 - if (port >= 0) {
45 - // port number
46 - return port;
47 - }
48 -
49 - return false;
50 -}
51 -
52 -/**
53 - * Event listener for HTTP server "error" event.
54 - */
55 -
56 -function onError(error) {
57 - if (error.syscall !== 'listen') {
58 - throw error;
59 - }
60 -
61 - var bind = typeof port === 'string'
62 - ? 'Pipe ' + port
63 - : 'Port ' + port;
64 -
65 - // handle specific listen errors with friendly messages
66 - switch (error.code) {
67 - case 'EACCES':
68 - console.error(bind + ' requires elevated privileges');
69 - process.exit(1);
70 - break;
71 - case 'EADDRINUSE':
72 - console.error(bind + ' is already in use');
73 - process.exit(1);
74 - break;
75 - default:
76 - throw error;
77 - }
78 -}
79 -
80 -/**
81 - * Event listener for HTTP server "listening" event.
82 - */
83 -
84 -function onListening() {
85 - var addr = server.address();
86 - var bind = typeof addr === 'string'
87 - ? 'pipe ' + addr
88 - : 'port ' + addr.port;
89 - debug('Listening on ' + bind);
90 -}
1 -div.svelte-hpuxjp{text-align:left;box-sizing:border-box;display:block}body{padding:0;margin:0}html{scroll-behavior:smooth}nav.svelte-pxoyop{background-color:rgb(225, 175, 85);font-family:"Helvetica Neue", "Helvetica", "Arial", sans-serif;height:70px;top:0}.inner.svelte-pxoyop{max-width:500px;padding-left:10px;padding-right:10px;margin:auto;box-sizing:border-box;display:flex;align-items:center;height:100%}.logo.svelte-pxoyop{display:flex;position:absolute;width:50px;left:40px;top:25px
2 - }.navbar-list.svelte-pxoyop{display:flex;padding:0;width:100%;justify-content:space-between;margin:0}#backtotop.svelte-16na1oq{border-radius:100%;width:50px;height:50px;position:fixed;right:4%;bottom:10%}.article.svelte-90y9ti.svelte-90y9ti{font-family:맑은고딕, Malgun Gothic, dotum, gulim, sans-serif;font-size:24pt;padding:10vw;text-align:center;display:flex}.wbg.svelte-90y9ti.svelte-90y9ti{background-color:#ffffff}.gbg.svelte-90y9ti.svelte-90y9ti{background-color:#edeff2}.article.svelte-90y9ti img.svelte-90y9ti{display:inline-block;max-width:500px;width:20vw;margin-left:4vw;margin-right:4vw}.article.svelte-90y9ti .text.svelte-90y9ti{display:inline-block;width:50vw}.contents.svelte-90y9ti.svelte-90y9ti{display:flex;align-items:center}li.svelte-1c821dq{list-style-type:none;position:relative}li.svelte-1c821dq:before{content:"";position:absolute;bottom:0;left:0;width:100%;height:1px}a.svelte-1c821dq{color:#e5e6e5;text-decoration:none;display:inline-flex;height:45px;align-items:center;padding:0 10px;font-size:20px}@media only screen and (max-width: 767px){a.svelte-1c821dq{display:none}}.onmouse.svelte-1c821dq{color:#ffffff}#chat_bg.svelte-1177unw{box-sizing:border-box;display:flex;height:100vh;background-color:#edeff2}
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
1 -html, body {
2 - position: relative;
3 - width: 100%;
4 - height: 100%;
5 -}
6 -
7 -body {
8 - color: #333;
9 - margin: 0;
10 - padding: 8px;
11 - box-sizing: border-box;
12 - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
13 -}
14 -
15 -a {
16 - color: rgb(0,100,200);
17 - text-decoration: none;
18 -}
19 -
20 -a:hover {
21 - text-decoration: underline;
22 -}
23 -
24 -a:visited {
25 - color: rgb(0,80,160);
26 -}
27 -
28 -label {
29 - display: block;
30 -}
31 -
32 -input, button, select, textarea {
33 - font-family: inherit;
34 - font-size: inherit;
35 - -webkit-padding: 0.4em 0;
36 - padding: 0.4em;
37 - margin: 0 0 0.5em 0;
38 - box-sizing: border-box;
39 - border: 1px solid #ccc;
40 - border-radius: 2px;
41 -}
42 -
43 -input:disabled {
44 - color: #ccc;
45 -}
46 -
47 -button {
48 - color: #333;
49 - background-color: #f4f4f4;
50 - outline: none;
51 -}
52 -
53 -button:disabled {
54 - color: #999;
55 -}
56 -
57 -button:not(:disabled):active {
58 - background-color: #ddd;
59 -}
60 -
61 -button:focus {
62 - border-color: #666;
63 -}
1 -<!DOCTYPE html>
2 -<html lang="en">
3 -<head>
4 - <meta charset='utf-8'>
5 - <meta name='viewport' content='width=device-width,initial-scale=1'>
6 -
7 - <title>Svelte app</title>
8 -
9 - <link rel='icon' type='image/png' href='./favicon.png'>
10 - <link rel='stylesheet' href='./global.css'>
11 - <link rel='stylesheet' href='./build/bundle.css'>
12 -
13 - <script defer src='./build/bundle.js'></script>
14 -</head>
15 -
16 -<body>
17 -</body>
18 -</html>
This diff is collapsed. Click to expand it.
1 { 1 {
2 - "name": "tft", 2 + "name": "svelte-app",
3 - "version": "0.0.0", 3 + "version": "1.0.0",
4 "private": true, 4 "private": true,
5 "scripts": { 5 "scripts": {
6 - "start": "node ./bin/www" 6 + "build": "rollup -c",
7 + "dev": "rollup -c -w",
8 + "start": "sirv public --no-clear"
9 + },
10 + "devDependencies": {
11 + "@rollup/plugin-commonjs": "^17.0.0",
12 + "@rollup/plugin-node-resolve": "^11.0.0",
13 + "rollup": "^2.3.4",
14 + "rollup-plugin-css-only": "^3.1.0",
15 + "rollup-plugin-livereload": "^2.0.0",
16 + "rollup-plugin-svelte": "^7.0.0",
17 + "rollup-plugin-terser": "^7.0.0",
18 + "svelte": "^3.0.0"
7 }, 19 },
8 "dependencies": { 20 "dependencies": {
9 - "cookie-parser": "~1.4.4", 21 + "engine.io-parser": "^5.0.1",
10 - "debug": "~2.6.9", 22 + "sirv-cli": "^1.0.0"
11 - "ejs": "~2.6.1",
12 - "express": "~4.16.1",
13 - "http-errors": "~1.6.3",
14 - "morgan": "~1.9.1"
15 } 23 }
16 } 24 }
......
1 -body {
2 - padding: 50px;
3 - font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 -}
5 -
6 -a {
7 - color: #00B7FF;
8 -}
1 +import svelte from 'rollup-plugin-svelte';
2 +import commonjs from '@rollup/plugin-commonjs';
3 +import resolve from '@rollup/plugin-node-resolve';
4 +import livereload from 'rollup-plugin-livereload';
5 +import { terser } from 'rollup-plugin-terser';
6 +import css from 'rollup-plugin-css-only';
7 +
8 +const production = !process.env.ROLLUP_WATCH;
9 +
10 +function serve() {
11 + let server;
12 +
13 + function toExit() {
14 + if (server) server.kill(0);
15 + }
16 +
17 + return {
18 + writeBundle() {
19 + if (server) return;
20 + server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
21 + stdio: ['ignore', 'inherit', 'inherit'],
22 + shell: true
23 + });
24 +
25 + process.on('SIGTERM', toExit);
26 + process.on('exit', toExit);
27 + }
28 + };
29 +}
30 +
31 +export default {
32 + input: 'src/main.js',
33 + output: {
34 + sourcemap: true,
35 + format: 'iife',
36 + name: 'app',
37 + file: 'public/build/bundle.js'
38 + },
39 + plugins: [
40 + svelte({
41 + compilerOptions: {
42 + // enable run-time checks when not in production
43 + dev: !production
44 + }
45 + }),
46 + // we'll extract any component CSS out into
47 + // a separate file - better for performance
48 + css({ output: 'bundle.css' }),
49 +
50 + // If you have external dependencies installed from
51 + // npm, you'll most likely need these plugins. In
52 + // some cases you'll need additional configuration -
53 + // consult the documentation for details:
54 + // https://github.com/rollup/plugins/tree/master/packages/commonjs
55 + resolve({
56 + browser: true,
57 + dedupe: ['svelte']
58 + }),
59 + commonjs(),
60 +
61 + // In dev mode, call `npm run start` once
62 + // the bundle has been generated
63 + !production && serve(),
64 +
65 + // Watch the `public` directory and refresh the
66 + // browser on changes when not in production
67 + !production && livereload('public'),
68 +
69 + // If we're building for production (npm run build
70 + // instead of npm run dev), minify
71 + production && terser()
72 + ],
73 + watch: {
74 + clearScreen: false
75 + }
76 +};
1 -var express = require('express');
2 -var router = express.Router();
3 -
4 -/* GET home page. */
5 -router.get('/', function(req, res, next) {
6 - res.render('index', { title: 'Express' });
7 -});
8 -
9 -module.exports = router;
1 -var express = require('express');
2 -var router = express.Router();
3 -
4 -/* GET users listing. */
5 -router.get('/', function(req, res, next) {
6 - res.send('respond with a resource');
7 -});
8 -
9 -module.exports = router;
1 +// @ts-check
2 +
3 +/** This script modifies the project to support TS code in .svelte files like:
4 +
5 + <script lang="ts">
6 + export let name: string;
7 + </script>
8 +
9 + As well as validating the code for CI.
10 + */
11 +
12 +/** To work on this script:
13 + rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template
14 +*/
15 +
16 +const fs = require("fs")
17 +const path = require("path")
18 +const { argv } = require("process")
19 +
20 +const projectRoot = argv[2] || path.join(__dirname, "..")
21 +
22 +// Add deps to pkg.json
23 +const packageJSON = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8"))
24 +packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, {
25 + "svelte-check": "^2.0.0",
26 + "svelte-preprocess": "^4.0.0",
27 + "@rollup/plugin-typescript": "^8.0.0",
28 + "typescript": "^4.0.0",
29 + "tslib": "^2.0.0",
30 + "@tsconfig/svelte": "^2.0.0"
31 +})
32 +
33 +// Add script for checking
34 +packageJSON.scripts = Object.assign(packageJSON.scripts, {
35 + "check": "svelte-check --tsconfig ./tsconfig.json"
36 +})
37 +
38 +// Write the package JSON
39 +fs.writeFileSync(path.join(projectRoot, "package.json"), JSON.stringify(packageJSON, null, " "))
40 +
41 +// mv src/main.js to main.ts - note, we need to edit rollup.config.js for this too
42 +const beforeMainJSPath = path.join(projectRoot, "src", "main.js")
43 +const afterMainTSPath = path.join(projectRoot, "src", "main.ts")
44 +fs.renameSync(beforeMainJSPath, afterMainTSPath)
45 +
46 +// Switch the app.svelte file to use TS
47 +const appSveltePath = path.join(projectRoot, "src", "App.svelte")
48 +let appFile = fs.readFileSync(appSveltePath, "utf8")
49 +appFile = appFile.replace("<script>", '<script lang="ts">')
50 +appFile = appFile.replace("export let name;", 'export let name: string;')
51 +fs.writeFileSync(appSveltePath, appFile)
52 +
53 +// Edit rollup config
54 +const rollupConfigPath = path.join(projectRoot, "rollup.config.js")
55 +let rollupConfig = fs.readFileSync(rollupConfigPath, "utf8")
56 +
57 +// Edit imports
58 +rollupConfig = rollupConfig.replace(`'rollup-plugin-terser';`, `'rollup-plugin-terser';
59 +import sveltePreprocess from 'svelte-preprocess';
60 +import typescript from '@rollup/plugin-typescript';`)
61 +
62 +// Replace name of entry point
63 +rollupConfig = rollupConfig.replace(`'src/main.js'`, `'src/main.ts'`)
64 +
65 +// Add preprocessor
66 +rollupConfig = rollupConfig.replace(
67 + 'compilerOptions:',
68 + 'preprocess: sveltePreprocess({ sourceMap: !production }),\n\t\t\tcompilerOptions:'
69 +);
70 +
71 +// Add TypeScript
72 +rollupConfig = rollupConfig.replace(
73 + 'commonjs(),',
74 + 'commonjs(),\n\t\ttypescript({\n\t\t\tsourceMap: !production,\n\t\t\tinlineSources: !production\n\t\t}),'
75 +);
76 +fs.writeFileSync(rollupConfigPath, rollupConfig)
77 +
78 +// Add TSConfig
79 +const tsconfig = `{
80 + "extends": "@tsconfig/svelte/tsconfig.json",
81 +
82 + "include": ["src/**/*"],
83 + "exclude": ["node_modules/*", "__sapper__/*", "public/*"]
84 +}`
85 +const tsconfigPath = path.join(projectRoot, "tsconfig.json")
86 +fs.writeFileSync(tsconfigPath, tsconfig)
87 +
88 +// Add global.d.ts
89 +const dtsPath = path.join(projectRoot, "src", "global.d.ts")
90 +fs.writeFileSync(dtsPath, `/// <reference types="svelte" />`)
91 +
92 +// Delete this script, but not during testing
93 +if (!argv[2]) {
94 + // Remove the script
95 + fs.unlinkSync(path.join(__filename))
96 +
97 + // Check for Mac's DS_store file, and if it's the only one left remove it
98 + const remainingFiles = fs.readdirSync(path.join(__dirname))
99 + if (remainingFiles.length === 1 && remainingFiles[0] === '.DS_store') {
100 + fs.unlinkSync(path.join(__dirname, '.DS_store'))
101 + }
102 +
103 + // Check if the scripts folder is empty
104 + if (fs.readdirSync(path.join(__dirname)).length === 0) {
105 + // Remove the scripts folder
106 + fs.rmdirSync(path.join(__dirname))
107 + }
108 +}
109 +
110 +// Adds the extension recommendation
111 +fs.mkdirSync(path.join(projectRoot, ".vscode"), { recursive: true })
112 +fs.writeFileSync(path.join(projectRoot, ".vscode", "extensions.json"), `{
113 + "recommendations": ["svelte.svelte-vscode"]
114 +}
115 +`)
116 +
117 +console.log("Converted to TypeScript.")
118 +
119 +if (fs.existsSync(path.join(projectRoot, "node_modules"))) {
120 + console.log("\nYou will need to re-run your dependency manager to get started.")
121 +}
1 -<h1><%= message %></h1>
2 -<h2><%= error.status %></h2>
3 -<pre><%= error.stack %></pre>
1 -<!DOCTYPE html>
2 -<html>
3 - <head>
4 - <title><%= title %></title>
5 - <link rel='stylesheet' href='/stylesheets/style.css' />
6 - </head>
7 - <body>
8 - <h1><%= title %></h1>
9 - <p>Welcome to <%= title %></p>
10 - </body>
11 -</html>