Skip to content

Commit 2831eaf

Browse files
authored
Merge pull request #278 from mStirner/dev
Finalizing v2
2 parents 4395f7e + 7ac1cd0 commit 2831eaf

File tree

8 files changed

+401
-108
lines changed

8 files changed

+401
-108
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"node_modules",
1212
"logs",
1313
"plugins/*",
14-
"dist"
14+
"dist",
15+
"build"
1516
],
1617
"extends": [
1718
"eslint:recommended"

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,7 @@ plugins/*
124124
tmp
125125

126126
demo-database*
127-
.vscode/archive-browser
127+
.vscode/archive-browser
128+
129+
build
130+
dist

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ WORKDIR /opt/OpenHaus/backend
2828
COPY --from=builder node_modules node_modules
2929
RUN apk --no-cache add openssl
3030

31-
COPY . ./
31+
COPY ./build/ ./
3232
#COPY ./package.json ./
3333

3434
#ENV HTTP_PORT=8080

Gruntfile.js

Lines changed: 84 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
const path = require("path");
22
const pkg = require("./package.json");
33
const cp = require("child_process");
4+
const crypto = require("crypto");
5+
const fs = require("fs");
6+
const os = require("os");
7+
8+
const PATH_DIST = path.resolve(process.cwd(), "dist");
9+
const PATH_BUILD = path.resolve(process.cwd(), "build");
10+
11+
process.env = Object.assign({
12+
NODE_ENV: "production"
13+
}, process.env);
414

515
module.exports = function (grunt) {
616

717
// Project configuration.
818
grunt.initConfig({
919
pkg,
10-
env: {
11-
options: {
12-
//Shared Options Hash
13-
},
14-
prod: {
15-
NODE_ENV: "production",
16-
}
17-
},
1820
uglify: {
19-
/*
2021
// NOTE: if true, this truncate variables&class names
2122
// Are original names neede for production?!
2223
// i dont thinks so, its only usefull in development
2324
options: {
24-
mangle: false
25-
},*/
25+
mangle: {
26+
toplevel: true
27+
}
28+
},
2629
build: {
2730
files: [{
2831
expand: true,
@@ -37,85 +40,52 @@ module.exports = function (grunt) {
3740
"!scripts/**",
3841
"!tests/**"
3942
],
40-
dest: path.join(process.cwd(), "dist"),
43+
dest: PATH_BUILD,
4144
//cwd: process.cwd()
4245
}]
4346
}
44-
},
45-
run: {
46-
install: {
47-
options: {
48-
cwd: path.join(process.cwd(), "dist")
49-
},
50-
cmd: "npm",
51-
args: [
52-
"install",
53-
"--prod-only"
54-
]
55-
},
56-
clean: {
57-
cmd: "rm",
58-
args: [
59-
"-rf",
60-
"./dist"
61-
]
62-
},
63-
copy: {
64-
exec: "cp ./package*.json ./dist"
65-
},
66-
folder: {
67-
exec: "mkdir ./dist/logs && mkdir ./dist/plugins"
68-
},
69-
"scripts-mock": {
70-
exec: "mkdir ./dist/scripts && echo 'exit 0' > ./dist/scripts/post-install.sh && chmod +x ./dist/scripts/post-install.sh"
71-
},
72-
"scripts-cleanup": {
73-
exec: "rm ./dist/scripts/post-install.sh && rmdir ./dist/scripts"
74-
}
75-
},
76-
compress: {
77-
main: {
78-
options: {
79-
archive: `backend-v${pkg.version}.tgz`
80-
},
81-
files: [{
82-
expand: true,
83-
src: "**/*",
84-
cwd: "dist/"
85-
}]
86-
}
8747
}
8848
});
8949

90-
// Load the plugin that provides the "uglify" task.
9150
grunt.loadNpmTasks("grunt-contrib-uglify");
92-
grunt.loadNpmTasks("grunt-run");
93-
grunt.loadNpmTasks("grunt-contrib-compress");
94-
grunt.loadNpmTasks("grunt-env");
95-
96-
grunt.registerTask("clean", ["run:clean"]);
97-
98-
grunt.registerTask("build", [
99-
"run:clean",
100-
"env:prod",
101-
"uglify",
102-
"run:folder",
103-
"run:copy",
104-
]);
105-
106-
// install npm dependencies
107-
grunt.registerTask("install", [
108-
"env:prod",
109-
"run:scripts-mock",
110-
"run:install",
111-
"run:scripts-cleanup"
112-
]);
113-
114-
grunt.registerTask("bundle", [
115-
"build",
116-
"install",
117-
"compress"
118-
]);
51+
52+
53+
grunt.registerTask("build", () => {
54+
[
55+
`rm -rf ${path.join(PATH_BUILD, "/*")}`,
56+
`rm -rf ${path.join(PATH_DIST, "/*")}`,
57+
`mkdir -p ${PATH_BUILD}`,
58+
`mkdir ${path.join(PATH_BUILD, "logs")}`,
59+
`mkdir ${path.join(PATH_BUILD, "plugins")}`,
60+
`mkdir ${path.join(PATH_BUILD, "scripts")}`,
61+
`echo "exit 0" > ${path.join(PATH_BUILD, "scripts/post-install.sh")}`,
62+
`chmod +x ${path.join(PATH_BUILD, "scripts/post-install.sh")}`,
63+
`cp ./package*.json ${PATH_BUILD}`,
64+
"grunt uglify",
65+
].forEach((cmd) => {
66+
cp.execSync(cmd, {
67+
env: process.env,
68+
stdio: "inherit"
69+
});
70+
});
71+
});
72+
73+
74+
grunt.registerTask("install", () => {
75+
cp.execSync(`cd ${PATH_BUILD} && npm install --prod-only`, {
76+
env: process.env,
77+
stdio: "inherit"
78+
});
79+
});
80+
81+
82+
grunt.registerTask("compress", () => {
83+
cp.execSync(`cd ${PATH_BUILD} && tar -czvf ${path.join(PATH_DIST, `${pkg.name}-v${pkg.version}.tgz`)} *`, {
84+
env: process.env,
85+
stdio: "inherit"
86+
});
87+
});
88+
11989

12090
grunt.registerTask("build:docker", () => {
12191
cp.execSync(`docker build . -t openhaus/${pkg.name}:latest --build-arg version=${pkg.version}`, {
@@ -124,15 +94,40 @@ module.exports = function (grunt) {
12494
});
12595
});
12696

97+
98+
grunt.registerTask("checksum", () => {
99+
100+
let m5f = path.join(PATH_DIST, "./checksums.md5");
101+
102+
fs.rmSync(m5f, { force: true });
103+
let files = fs.readdirSync(PATH_DIST);
104+
let fd = fs.openSync(m5f, "w");
105+
106+
files.forEach((name) => {
107+
108+
let file = path.join(PATH_DIST, name);
109+
let content = fs.readFileSync(file);
110+
let hasher = crypto.createHash("md5");
111+
let hash = hasher.update(content).digest("hex");
112+
fs.writeSync(fd, `${hash}\t${name}${os.EOL}`);
113+
114+
});
115+
116+
fs.closeSync(fd);
117+
118+
});
119+
120+
127121
grunt.registerTask("release", () => {
128122
[
129-
"rm -rf ./dist/*",
130-
"npm run build",
131-
"npm run build:docker",
132-
`docker save openhaus/frontend:latest | gzip > ./${pkg.name}-v${pkg.version}-docker.tgz`,
123+
`mkdir -p ${PATH_DIST}`,
124+
"grunt build",
133125
"grunt compress",
134-
`cd dist && NODE_ENV=production npm install --prod-only --ignore-scripts`,
135-
`cd dist && tar -czvf ../${pkg.name}-v${pkg.version}-bundle.tgz *`
126+
"grunt build:docker",
127+
`docker save openhaus/${pkg.name}:latest | gzip > ${path.join(PATH_DIST, `${pkg.name}-v${pkg.version}-docker.tgz`)}`,
128+
"grunt install",
129+
`cd ${PATH_BUILD} && tar -czvf ${path.join(PATH_DIST, `${pkg.name}-v${pkg.version}-bundle.tgz`)} *`,
130+
"grunt checksum"
136131
].forEach((cmd) => {
137132
cp.execSync(cmd, {
138133
env: process.env,
@@ -141,9 +136,5 @@ module.exports = function (grunt) {
141136
});
142137
});
143138

144-
// Default task(s).
145-
//grunt.registerTask("default", ["uglify"]);
146-
//grunt.registerTask("install", ["install"]);
147-
//grunt.registerTask("compress", ["compress"]);
148139

149140
};

components/plugins/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ class C_PLUGINS extends COMPONENT {
7474
recursive: true
7575
}, (err) => {
7676

77+
// ignore when folder not exists
78+
if (err?.code === "ENOENT") {
79+
this.logger.warn("Plugin folder does not exists, continue anway.", err);
80+
err = null;
81+
}
82+
7783
next(err || null, item, result, _id);
7884

7985
});

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ process.env = Object.assign({
3333
DATABASE_UPDATE_DEBOUNCE_TIMER: "15",
3434
HTTP_PORT: "8080",
3535
HTTP_ADDRESS: "0.0.0.0",
36-
HTTP_SOCKET: "",
36+
HTTP_SOCKET: "/tmp/open-haus.sock",
3737
LOG_PATH: path.resolve(process.cwd(), "logs"),
3838
LOG_LEVEL: "info",
3939
LOG_DATEFORMAT: "yyyy.mm.dd - HH:MM.ss.l",
@@ -473,9 +473,9 @@ const starter = new Promise((resolve) => {
473473
});
474474

475475
if (bootable.length > started) {
476-
logger.debug(`${started}/${bootable.length} Plugins started (Someones are ignored! Check the logfiles.)`);
476+
logger.warn(`${started}/${bootable.length} Plugins started (Check the previously logs)`);
477477
} else {
478-
logger.debug(`${started}/${bootable.length} Plugins started`);
478+
logger.info(`${started}/${bootable.length} Plugins started`);
479479
}
480480

481481
logger.info("Startup complete");

0 commit comments

Comments
 (0)