Skip to content

Commit

Permalink
Merge pull request #251 from n0th1ng-else/docker-2
Browse files Browse the repository at this point in the history
fix(server): Copy welcome script in docker
  • Loading branch information
n0th1ng-else authored Jan 14, 2024
2 parents 5c6f9f6 + a2507b8 commit cc5f1f0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ WORKDIR $APP_DIR
COPY --from=builder $APP_DIR/package.json $APP_DIR
# TODO: copy only production dependencies
COPY --from=builder $APP_DIR/node_modules $APP_DIR/node_modules

# copy the app build
COPY --from=builder $APP_DIR/dist $APP_DIR/dist
# copy the context file
COPY --from=builder $APP_DIR/meta $APP_DIR/meta
COPY --from=builder $APP_DIR/src/ci/welcome.js $APP_DIR/src/ci
# copy welcome script
COPY --from=builder $APP_DIR/src/ci/dirs.js $APP_DIR/src/ci/dirs.js
COPY --from=builder $APP_DIR/src/ci/welcome.js $APP_DIR/src/ci/welcome.js

EXPOSE 8080

Expand Down
19 changes: 19 additions & 0 deletions src/ci/dirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,22 @@ export const rootDirURL = new URL('../..', import.meta.url);
export const rootDir = fileURLToPath(rootDirURL);

export const externalResourcesFile = new URL('./resources.json', rootDirURL);

export const metaFolderName = 'meta';

export const metaFileName = 'index.json';

/**
*
* @param rootDir {URL}
* @param folder {string}
* @param [file] {string|undefined}
*
* @returns {URL}
*/
export const getPathUrl = (rootDir, folder, file) => {
if (file) {
return new URL(`./${folder}/${file}`, rootDir);
}
return new URL(`./${folder}`, rootDir);
};
39 changes: 5 additions & 34 deletions src/ci/link.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'node:fs';
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import scrapper from 'metascraper';
import sauthor from 'metascraper-author';
import sdate from 'metascraper-date';
Expand All @@ -9,53 +9,24 @@ import spublisher from 'metascraper-publisher';
import stitle from 'metascraper-title';
import surl from 'metascraper-url';
import { env } from './env.js';

const folder = 'meta';
const file = 'index.json';

/**
*
* @param rootDir {URL}
* @param fol {string}
* @param [fil] {string}
*/
const getPath = (rootDir, fol, fil) => {
if (fil) {
return new URL(`./${fol}/${fil}`, rootDir);
}
return new URL(`./${fol}`, rootDir);
};
import { getPathUrl, metaFileName, metaFolderName } from './dirs.js';

/**
*
* @param rootDir {URL}
* @param meta {object}
*/
export const saveMetaToFile = (rootDir, meta) => {
if (!existsSync(getPath(rootDir, folder))) {
mkdirSync(getPath(rootDir, folder));
if (!existsSync(getPathUrl(rootDir, metaFolderName))) {
mkdirSync(getPathUrl(rootDir, metaFolderName));
}

const filePath = getPath(rootDir, folder, file);
const filePath = getPathUrl(rootDir, metaFolderName, metaFileName);
const content = JSON.stringify(meta, null, 2);
writeFileSync(filePath, `${content}\n`);
return filePath;
};

/**
*
* @param rootDir {URL}
* @return {object}
*/
export const readMetaFile = rootDir => {
if (!existsSync(getPath(rootDir, folder))) {
throw new Error('meta file does not exist!');
}

const filePath = getPath(rootDir, folder, file);
return JSON.parse(readFileSync(filePath, { encoding: 'utf-8' }));
};

/**
*
* @param service {string}
Expand Down
18 changes: 16 additions & 2 deletions src/ci/welcome.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import { readMetaFile } from './link.js';
import { rootDirURL } from './dirs.js';
import { existsSync, readFileSync } from 'node:fs';
import { getPathUrl, metaFileName, metaFolderName, rootDirURL } from './dirs.js';

/**
*
* @param rootDir {URL}
* @returns {object}
*/
export const readMetaFile = rootDir => {
if (!existsSync(getPathUrl(rootDir, metaFolderName))) {
throw new Error('meta file does not exist!');
}

const filePath = getPathUrl(rootDir, metaFolderName, metaFileName);
return JSON.parse(readFileSync(filePath, { encoding: 'utf-8' }));
};

const meta = readMetaFile(rootDirURL);
const { version, versionBuild } = meta.env;
Expand Down

0 comments on commit cc5f1f0

Please sign in to comment.