Skip to content

Commit 673b67c

Browse files
authored
feat(scully): killServers now works even when the config is not found (#691)
1 parent 35ea650 commit 673b67c

6 files changed

Lines changed: 202 additions & 42 deletions

File tree

libs/scully/src/lib/utils/config.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ import { cpus } from 'os';
1212
export const angularRoot = findAngularJsonPath();
1313
export const scullyConfig: ScullyConfig = {} as ScullyConfig;
1414

15+
export const scullyDefaults: Partial<ScullyConfig> = {
16+
bareProject: false,
17+
homeFolder: angularRoot,
18+
outDir: join(angularRoot, './dist/static/'),
19+
logFileSeverity: LogSeverity.warning,
20+
inlineStateOnly: false,
21+
thumbnails: false,
22+
maxRenderThreads: cpus().length,
23+
handle404: '',
24+
appPort: /** 1864 */ 'herodevs'
25+
.split('')
26+
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
27+
staticport: /** 1668 */ 'scully'
28+
.split('')
29+
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
30+
reloadPort: /** 2667 */ 'scullyLiveReload'
31+
.split('')
32+
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
33+
hostName: 'localhost',
34+
defaultPostRenderers: [],
35+
};
36+
1537
const loadIt = async () => {
1638
const compiledConfig = await compileConfig();
1739
let angularConfig = {} as any;
@@ -37,7 +59,7 @@ const loadIt = async () => {
3759
compiledConfig.projectName
3860
)}" in 'angular.json'.`
3961
);
40-
process.exit(15);
62+
// process.exit(15);
4163
}
4264

4365
if (compiledConfig.hostUrl && compiledConfig.hostUrl.endsWith('/')) {
@@ -46,34 +68,18 @@ const loadIt = async () => {
4668
compiledConfig.hostUrl.length - 1
4769
);
4870
}
71+
4972
// TODO: update types in interfacesandenums to force correct types in here.
5073
// tslint:disable-next-line: no-unused-expression
5174
Object.assign(
5275
scullyConfig,
5376
/** the default config */
77+
scullyDefaults,
78+
/** calculated defaults. */
5479
{
55-
bareProject: false,
56-
homeFolder: angularRoot,
57-
outDir: join(angularRoot, './dist/static/'),
5880
sourceRoot: projectConfig.sourceRoot,
5981
projectRoot: projectConfig.root,
6082
distFolder,
61-
logFileSeverity: LogSeverity.warning,
62-
inlineStateOnly: false,
63-
tumbnails: false,
64-
maxRenderThreads: cpus().length,
65-
handle404: '',
66-
appPort: /** 1864 */ 'herodevs'
67-
.split('')
68-
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
69-
staticport: /** 1668 */ 'scully'
70-
.split('')
71-
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
72-
reloadPort: /** 2667 */ 'scullyLiveReload'
73-
.split('')
74-
.reduce((sum, token) => (sum += token.charCodeAt(0)), 1000),
75-
hostName: 'localhost',
76-
defaultPostRenderers: [],
7783
}
7884
) as ScullyConfig;
7985
/** activate loaded config */

libs/scully/src/lib/utils/log.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ import { loadConfig, scullyConfig } from '../utils/config';
66
export const orange = chalk.hex('#FFA500');
77
export const { white, red, yellow, green }: { [x: string]: any } = chalk;
88

9-
export enum LogSeverity {
9+
export const enum LogSeverity {
1010
normal,
1111
warning,
1212
error,
1313
none,
1414
}
1515

16-
const logToFile = loadConfig
17-
.then(() => (string) => {
18-
return new Promise((res, rej) =>
19-
appendFile(join(scullyConfig.homeFolder, 'scully.log'), string, (e) =>
20-
e ? rej(e) : res
21-
)
22-
);
23-
})
24-
.then((file) => {
25-
/** inject a couple of newlines to indicate new run */
26-
return file;
27-
});
16+
const logToFile = Promise.resolve((string) => {
17+
return new Promise((res, rej) =>
18+
appendFile(join(__dirname, '../../', 'scully.log'), string, (e) =>
19+
e ? rej(e) : res
20+
)
21+
);
22+
}).then((file) => {
23+
/** inject a couple of newlines to indicate new run */
24+
return file;
25+
});
26+
2827
export const log = (...a) => enhancedLog(white, LogSeverity.normal, ...a);
2928
export const logError = (...a) => enhancedLog(red, LogSeverity.error, ...a);
3029
export const logWarn = (...a) => enhancedLog(orange, LogSeverity.warning, ...a);
@@ -43,7 +42,7 @@ function enhancedLog(colorFn, severity: LogSeverity, ...args: any[]) {
4342
})
4443
.catch((e) => {
4544
/** silently ignore log errors */
46-
console.log('log error', e);
45+
// console.log('log error', e)
4746
});
4847
console.log(colorFn(...out));
4948
}

libs/scully/src/scully.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import open from 'open';
88
import { join } from 'path';
99
import './lib/pluginManagement/systemPlugins';
1010
import { startBackgroundServer } from './lib/startBackgroundServer';
11-
import { waitForServerToBeAvailable } from './lib/utils';
11+
import { waitForServerToBeAvailable, ScullyConfig } from './lib/utils';
1212
import * as cliOption from './lib/utils/cli-options';
1313
import { ssl } from './lib/utils/cli-options';
14-
import { loadConfig } from './lib/utils/config';
14+
import { loadConfig, scullyDefaults } from './lib/utils/config';
1515
import { moveDistAngular } from './lib/utils/fsAngular';
1616
import { httpGetJson } from './lib/utils/httpGetJson';
1717
import { logError, logWarn, yellow } from './lib/utils/log';
@@ -31,11 +31,18 @@ if (process.argv.includes('version')) {
3131

3232
(async () => {
3333
/** make sure not to do something before the config is ready */
34-
const scullyConfig = await loadConfig;
35-
if (cliOption.hostName) {
36-
scullyConfig.hostName = cliOption.hostName;
34+
let scullyConfig: ScullyConfig;
35+
let err;
36+
/** load the config, and use the defaults when there is an error */
37+
try {
38+
scullyConfig = await loadConfig;
39+
} catch (e) {
40+
scullyConfig = scullyDefaults as ScullyConfig;
41+
/** store the error */
42+
err = e;
3743
}
38-
if (cliOption.killServer) {
44+
/** do we need to kill something? */
45+
if (process.argv.includes('killServer')) {
3946
await httpGetJson(
4047
`http://${scullyConfig.hostName}:${scullyConfig.appPort}/killMe`,
4148
{
@@ -50,7 +57,15 @@ if (process.argv.includes('version')) {
5057
).catch((e) => e);
5158
logWarn('Sent kill command to server');
5259
process.exit(0);
53-
return;
60+
}
61+
62+
if (err) {
63+
/** exit due to severe error during config parsing */
64+
process.exit(15);
65+
}
66+
67+
if (cliOption.hostName) {
68+
scullyConfig.hostName = cliOption.hostName;
5469
}
5570
await isBuildThere(scullyConfig);
5671

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"server:testDocs": "npm run server:docs &",
1919
"server:sample": "npm run scully -- --project sample-blog --tds serve ",
2020
"server:docs": "npm run scully -- --project scully-docs --tds serve ",
21-
"server:kill": "npm run scully -- --project scully-docs killServer ",
21+
"server:kill": "npm run scully -- killServer ",
2222
"e2e": "nx e2e",
2323
"docs": "run-s server:kill build:code symlinks build:docs deploy:docs",
2424
"deploy:docs": "echo No deploy script yet",
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
FROM ubuntu:20.04
2+
3+
4+
# Dependencies + NodeJS
5+
RUN apt-get -qq update && \
6+
echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections && \
7+
apt-get -y -qq install software-properties-common &&\
8+
apt-add-repository "deb http://archive.canonical.com/ubuntu $(lsb_release -sc) partner" && \
9+
apt-get -qq update && apt-get -y -qq --no-install-recommends install \
10+
dumb-init \
11+
adobe-flashplugin \
12+
git \
13+
ffmpeg \
14+
msttcorefonts \
15+
fonts-roboto \
16+
fonts-ubuntu \
17+
fonts-noto-color-emoji \
18+
fonts-noto-cjk \
19+
fonts-ipafont-gothic \
20+
fonts-wqy-zenhei \
21+
fonts-kacst \
22+
fonts-freefont-ttf \
23+
fonts-thai-tlwg \
24+
fonts-indic \
25+
fontconfig \
26+
libappindicator3-1 \
27+
pdftk \
28+
unzip \
29+
locales \
30+
gconf-service \
31+
libasound2 \
32+
libatk1.0-0 \
33+
libc6 \
34+
libcairo2 \
35+
libcups2 \
36+
libdbus-1-3 \
37+
libexpat1 \
38+
libfontconfig1 \
39+
libgcc1 \
40+
libgconf-2-4 \
41+
libgdk-pixbuf2.0-0 \
42+
libglib2.0-0 \
43+
libgtk-3-0 \
44+
libnspr4 \
45+
libpango-1.0-0 \
46+
libpangocairo-1.0-0 \
47+
libstdc++6 \
48+
libx11-6 \
49+
libx11-xcb1 \
50+
libxcb1 \
51+
libxcomposite1 \
52+
libxcursor1 \
53+
libxdamage1 \
54+
libxext6 \
55+
libxfixes3 \
56+
libxi6 \
57+
libxrandr2 \
58+
libxrender1 \
59+
libxss1 \
60+
libxtst6 \
61+
libllvm8 \
62+
libgbm-dev \
63+
ca-certificates \
64+
libappindicator1 \
65+
libnss3 \
66+
lsb-release \
67+
xdg-utils \
68+
wget \
69+
xvfb \
70+
curl &&\
71+
curl --silent --location https://deb.nodesource.com/setup_13.x | bash - &&\
72+
apt-get -y -qq install nodejs &&\
73+
apt-get -y -qq install build-essential &&\
74+
fc-cache -f -v
75+
76+
# Add the browserless user (blessuser)
77+
RUN groupadd -r blessuser && useradd -r -g blessuser -G audio,video blessuser \
78+
&& mkdir -p /home/blessuser/Downloads \
79+
&& chown -R blessuser:blessuser /home/blessuser
80+
81+
# Install deps necessary to build
82+
RUN npm install -g typescript @types/node
83+
84+
# Cleanup
85+
RUN apt-get -qq clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

tools/docker/pupeteer.dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM chromium-base:latest
2+
3+
# Build Args
4+
ARG USE_CHROME_STABLE
5+
ARG PUPPETEER_CHROMIUM_REVISION
6+
ARG PUPPETEER_VERSION
7+
8+
# Application parameters and variables
9+
ENV APP_DIR=/usr/src/app
10+
ENV CONNECTION_TIMEOUT=60000
11+
ENV CHROME_PATH=/usr/bin/google-chrome
12+
ENV HOST=0.0.0.0
13+
ENV IS_DOCKER=true
14+
ENV LANG="C.UTF-8"
15+
ENV NODE_ENV=production
16+
ENV PORT=3000
17+
ENV PUPPETEER_CHROMIUM_REVISION=${PUPPETEER_CHROMIUM_REVISION}
18+
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
19+
ENV USE_CHROME_STABLE=${USE_CHROME_STABLE}
20+
ENV WORKSPACE_DIR=$APP_DIR/workspace
21+
22+
RUN mkdir -p $APP_DIR $WORKSPACE_DIR
23+
24+
WORKDIR $APP_DIR
25+
26+
# Install app dependencies
27+
COPY package.json .
28+
COPY tsconfig.json .
29+
COPY . .
30+
31+
# Install Chrome Stable when specified
32+
RUN if [ "$USE_CHROME_STABLE" = "true" ]; then \
33+
cd /tmp &&\
34+
wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb &&\
35+
dpkg -i google-chrome-stable_current_amd64.deb;\
36+
fi
37+
38+
# Build and install external binaries + assets
39+
RUN if [ "$USE_CHROME_STABLE" = "true" ]; then \
40+
export CHROMEDRIVER_SKIP_DOWNLOAD=false;\
41+
else \
42+
export CHROMEDRIVER_SKIP_DOWNLOAD=true;\
43+
fi &&\
44+
npm i puppeteer@$PUPPETEER_VERSION;\
45+
npm run post-install &&\
46+
npm run build &&\
47+
chown -R blessuser:blessuser $APP_DIR
48+
49+
# Run everything after as non-privileged user.
50+
USER blessuser
51+
52+
# Expose the web-socket and HTTP ports
53+
EXPOSE 3000
54+
55+
CMD ["./start.sh"]

0 commit comments

Comments
 (0)