fix: several distribution problems
Massimo Melina committed
Jan 16, 2022 at 21:50 UTC
b85fc9c142d058f2822326b0737faaf3b6bff2cd
9 files changed
+57
-22
.gitignore
+2
-1
@@ -1,5 +1,6 @@
1
node_modules
2
-build
2
.idea
3
dist
4
+#produced by running
5
+counters.yaml
6
*.log
afterbuild.js
new
+37
@@ -0,0 +1,37 @@
1
+const fs = require('fs')
2
+const glob = require('fast-glob')
3
+const { execSync } = require('child_process')
4
+const dist = 'dist/'
5
+console.log('updating timestamp', process.cwd())
6
+const FN = dist+'src/index.js'
7
+fs.writeFileSync(FN,
8
+ fs.readFileSync(FN,'utf8')
9
+ .replace(/(BUILD_TIMESTAMP = ")(.*)"/, '$1'+new Date().toISOString()+'"'))
10
+for (const fn of glob.sync(dist+'node_modules/**/*.map'))
11
+ fs.unlinkSync(fn)
12
+
13
+console.log('pruning lodash')
14
+const nm = dist+'node_modules/'
15
+fs.mkdirSync(nm+'lodash2')
16
+fs.cpSync(nm+'lodash/package.json', nm+'lodash2/package.json')
17
+fs.cpSync(nm+'lodash/lodash.min.js', nm+'lodash2/lodash.js')
18
+fs.rmSync(nm+'lodash', {recursive:true})
19
+fs.renameSync(nm+'lodash2', nm+'lodash')
20
+
21
+console.log('launching nm-prune')
22
+fs.renameSync(nm+'yaml/dist/doc', nm+'yaml/dist/do_c') // "hide" this folder
23
+execSync('nm-prune --force', { cwd:'dist' })
24
+fs.renameSync(nm+'yaml/dist/do_c', nm+'yaml/dist/doc')
25
+
26
+console.log('removing package.json')
27
+fs.unlinkSync(dist+'package.json')
28
+fs.unlinkSync(dist+'package-lock.json')
29
+
30
+{
31
+ const fn = dist+'run.bat'
32
+ console.log(fn)
33
+ fs.writeFileSync(fn, 'node src')
34
+ fs.chmodSync(fn, 0o755)
35
+}
36
+
37
+console.log('afterbuild done')
package-lock.json
+2
-2
@@ -1,12 +1,12 @@
1
{
2
"name": "hfs",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
"lockfileVersion": 2,
5
"requires": true,
6
"packages": {
7
"": {
8
"name": "hfs",
9
- "version": "0.6.0",
9
+ "version": "0.6.1",
10
"license": "GPL-3.0",
11
"dependencies": {
12
"@koa/router": "^10.1.1",
package.json
+7
-8
@@ -1,6 +1,6 @@
1
{
2
"name": "hfs",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
"description": "HTTP File Server",
5
"keywords": [
6
"file server",
@@ -13,17 +13,16 @@
13
"watch-server": "nodemon --ignore tests/ --watch src -e ts,tsx --exec ts-node src/index.ts",
14
"start-frontend": "cd frontend && npm run start",
15
"start": "node dist",
16
- "build": "npm install && tsc --target es2018 && node timestamp && cp package*.json dist && cd dist && npm ci --production && cd .. && npm run build-prune",
17
- "build-prune": "cd dist/node_modules/yaml/dist && mv doc do_c && cd ../.. && mkdir lodash2 && cp lodash/lodash.min.js lodash2/lodash.js && cp lodash/package.json lodash2 && rm -rf lodash && mv lodash2 lodash && cd .. && nm-prune --force && cd node_modules/yaml/dist && mv do_c doc",
16
+ "build": "npm install && tsc --target es2018 && cp -v -r package*.json config.yaml accounts.yaml READ* plugins tests dist && cd dist && npm ci --production && cd .. && node afterbuild",
17
"build-all": "rm -rf dist && npm run build && cd frontend && npm install && npm run build && echo COMPLETED",
18
"test": "mocha -r ts-node/register 'tests/**/*.ts'",
20
- "zip-dist": "zip hfs.zip -r config.yaml accounts.yaml READ* dist/* plugins/* tests/*",
21
- "make-exe-after-build": "pkg . -C brotli"
19
+ "zip-dist": "cd dist && zip hfs.zip -r * -x *.zip *.exe",
20
+ "make-exe-after-build": "pkg . -C brotli && cd dist && zip hfs.exe.zip -r * -x src src/** *.zip run.bat"
21
},
23
- "bin": "dist/index.js",
22
+ "bin": "dist/src/index.js",
23
"pkg": {
25
- "scripts": "dist/**/*.js",
26
- "assets": "dist/frontend/**/*",
24
+ "scripts": "dist/src/**/*.js",
25
+ "assets": "",
26
"targets": [
27
"node16-win"
28
],
src/const.ts
+1
-1
@@ -1,6 +1,6 @@
1
import minimist from 'minimist'
2
3
-export const DEV = __dirname.endsWith('src') ? 'DEV' : ''
3
+export const DEV = process.env.DEV ? 'DEV' : ''
4
5
if (DEV)
6
console.clear()
src/serveFrontend.ts
+5
-4
@@ -1,17 +1,18 @@
1
import proxy from 'koa-better-http-proxy'
2
import Koa from 'koa'
3
import fs from 'fs/promises'
4
-import { DEV, FRONTEND_URI, METHOD_NOT_ALLOWED, NO_CONTENT, PLUGINS_PUB_URI } from './const'
4
+import { FRONTEND_URI, METHOD_NOT_ALLOWED, NO_CONTENT, PLUGINS_PUB_URI } from './const'
5
import { serveFile } from './serveFile'
6
import { mapPlugins } from './plugins'
7
import { refresh_session } from './api.auth'
8
import { ApiError } from './apis'
9
10
-export const serveFrontend = DEV ? serveProxyFrontend() : serveStaticFrontend()
10
+const proxyPort = process.env.FRONTEND_PROXY
11
+export const serveFrontend = proxyPort ? serveProxyFrontend() : serveStaticFrontend()
12
13
function serveProxyFrontend() {
14
console.debug('fronted: proxied')
14
- return proxy('localhost:3000', {
15
+ return proxy('localhost:'+proxyPort, {
16
filter: ctx => ctx.method === 'GET' || (ctx.status = METHOD_NOT_ALLOWED) && false,
17
proxyReqPathResolver: (ctx) => ctx.path.endsWith('/') ? '/' : ctx.path,
18
userResDecorator(res, data, ctx) {
@@ -22,7 +23,7 @@ function serveProxyFrontend() {
23
}
24
25
function serveStaticFrontend() : Koa.Middleware {
25
- const BASE = __dirname + (DEV ? '/../dist' : '') + '/frontend/'
26
+ const BASE = 'frontend/'
27
return async (ctx, next) => {
28
let { path, method } = ctx
29
if (method === 'OPTIONS') {
timestamp.js
deleted
-5
@@ -1,5 +0,0 @@
1
-const fs = require('fs')
2
-const FN = 'dist/index.js'
3
-fs.writeFileSync(FN,
4
- fs.readFileSync(FN,'utf8')
5
- .replace(/(BUILD_TIMESTAMP = ")(.*)"/, '$1'+new Date().toISOString()+'"'))
todo.md
+2
@@ -1,6 +1,8 @@
1
# To do
2
+- fix: if plugins folder is not found at the start, it won't try anymore
3
- log filter option
4
- log filter plugin
5
+- frontend search supporting masks
6
- remove seconds from time
7
- update tests to SRP login
8
- upload
tsconfig.json
+1
-1
@@ -48,7 +48,7 @@
48
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
49
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
50
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
51
- "outDir": "./dist", /* Specify an output folder for all emitted files. */
51
+ "outDir": "./dist/src", /* Specify an output folder for all emitted files. */
52
// "removeComments": true, /* Disable emitting comments. */
53
// "noEmit": true, /* Disable emitting files from a compilation. */
54
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */