@abcnews/aunty 16.0.1 → 17.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -160
- package/package.json +39 -82
- package/src/bin/aunty.ts +60 -0
- package/assets/done.mp3 +0 -0
- package/scripts/postinstall.js +0 -44
- package/src/api/index.js +0 -5
- package/src/bin/aunty.js +0 -27
- package/src/cli/build/constants.js +0 -46
- package/src/cli/build/index.js +0 -100
- package/src/cli/clean/constants.js +0 -10
- package/src/cli/clean/index.js +0 -40
- package/src/cli/constants.js +0 -114
- package/src/cli/deploy/constants.js +0 -40
- package/src/cli/deploy/index.js +0 -151
- package/src/cli/generate/constants.js +0 -39
- package/src/cli/generate/index.js +0 -72
- package/src/cli/index.js +0 -154
- package/src/cli/release/constants.js +0 -67
- package/src/cli/release/index.js +0 -162
- package/src/cli/serve/constants.js +0 -33
- package/src/cli/serve/index.js +0 -128
- package/src/cli/sign-cert/constants.js +0 -42
- package/src/cli/sign-cert/index.js +0 -50
- package/src/cli/test/constants.js +0 -15
- package/src/cli/test/index.js +0 -30
- package/src/config/babel.js +0 -75
- package/src/config/build.js +0 -39
- package/src/config/deploy.js +0 -143
- package/src/config/jest/index.js +0 -20
- package/src/config/jest/transformer-default.js +0 -27
- package/src/config/jest/transformer-svelte-preprocess.js +0 -8
- package/src/config/jest/transformer-svelte.js +0 -32
- package/src/config/project.js +0 -57
- package/src/config/serve.js +0 -144
- package/src/config/webpack.js +0 -325
- package/src/config/webpackDevServer.js +0 -46
- package/src/constants.js +0 -7
- package/src/generators/component/index.js +0 -172
- package/src/generators/component/templates/_non_sfc/styles.scss +0 -6
- package/src/generators/component/templates/basic/component-with-d3.test.ts +0 -7
- package/src/generators/component/templates/basic/component-with-d3.ts +0 -30
- package/src/generators/component/templates/basic/component.test.ts +0 -7
- package/src/generators/component/templates/basic/component.ts +0 -11
- package/src/generators/component/templates/preact/component-with-d3.test.tsx +0 -16
- package/src/generators/component/templates/preact/component-with-d3.tsx +0 -45
- package/src/generators/component/templates/preact/component.test.tsx +0 -18
- package/src/generators/component/templates/preact/component.tsx +0 -14
- package/src/generators/component/templates/react/component-with-d3.test.tsx +0 -13
- package/src/generators/component/templates/react/component-with-d3.tsx +0 -44
- package/src/generators/component/templates/react/component.test.tsx +0 -13
- package/src/generators/component/templates/react/component.tsx +0 -14
- package/src/generators/component/templates/svelte/component-with-d3.svelte +0 -46
- package/src/generators/component/templates/svelte/component-with-d3.test.ts +0 -10
- package/src/generators/component/templates/svelte/component.svelte +0 -17
- package/src/generators/component/templates/svelte/component.test.ts +0 -10
- package/src/generators/project/index.js +0 -244
- package/src/generators/project/templates/_common/.editorconfig +0 -12
- package/src/generators/project/templates/_common/.prettierrc +0 -6
- package/src/generators/project/templates/_common/LICENSE +0 -21
- package/src/generators/project/templates/_common/README.md +0 -3
- package/src/generators/project/templates/_common/_.gitignore +0 -12
- package/src/generators/project/templates/_common/package.json +0 -18
- package/src/generators/project/templates/_common/public/index.html +0 -21
- package/src/generators/project/templates/_common/src/components/Worm/worm.svg +0 -4
- package/src/generators/project/templates/_common/tsconfig.json +0 -4
- package/src/generators/project/templates/_non_sfc/src/components/App/styles.scss +0 -23
- package/src/generators/project/templates/_non_sfc/src/components/ErrorBox/styles.scss +0 -16
- package/src/generators/project/templates/_non_sfc/src/components/Worm/styles.scss +0 -4
- package/src/generators/project/templates/basic/src/components/App/index.test.ts +0 -9
- package/src/generators/project/templates/basic/src/components/App/index.ts +0 -22
- package/src/generators/project/templates/basic/src/components/ErrorBox/index.ts +0 -24
- package/src/generators/project/templates/basic/src/components/Worm/index.test.ts +0 -7
- package/src/generators/project/templates/basic/src/components/Worm/index.ts +0 -12
- package/src/generators/project/templates/basic/src/index.ts +0 -50
- package/src/generators/project/templates/preact/src/components/App/index.test.tsx +0 -21
- package/src/generators/project/templates/preact/src/components/App/index.tsx +0 -21
- package/src/generators/project/templates/preact/src/components/ErrorBox/index.tsx +0 -15
- package/src/generators/project/templates/preact/src/components/Worm/index.test.tsx +0 -14
- package/src/generators/project/templates/preact/src/components/Worm/index.tsx +0 -9
- package/src/generators/project/templates/preact/src/index.tsx +0 -42
- package/src/generators/project/templates/react/src/components/App/index.test.tsx +0 -14
- package/src/generators/project/templates/react/src/components/App/index.tsx +0 -21
- package/src/generators/project/templates/react/src/components/ErrorBox/index.tsx +0 -14
- package/src/generators/project/templates/react/src/components/Worm/index.test.tsx +0 -13
- package/src/generators/project/templates/react/src/components/Worm/index.tsx +0 -9
- package/src/generators/project/templates/react/src/index.tsx +0 -40
- package/src/generators/project/templates/svelte/src/components/App/App.svelte +0 -37
- package/src/generators/project/templates/svelte/src/components/App/App.test.ts +0 -18
- package/src/generators/project/templates/svelte/src/components/Worm/Worm.svelte +0 -12
- package/src/generators/project/templates/svelte/src/components/Worm/Worm.test.ts +0 -16
- package/src/generators/project/templates/svelte/src/index.ts +0 -26
- package/src/utils/async.js +0 -13
- package/src/utils/audio.js +0 -30
- package/src/utils/branding.js +0 -57
- package/src/utils/color.js +0 -12
- package/src/utils/ftp.js +0 -80
- package/src/utils/git.js +0 -127
- package/src/utils/logging.js +0 -74
- package/src/utils/npm.js +0 -59
- package/src/utils/remote.js +0 -81
- package/src/utils/structures.js +0 -33
- package/src/utils/text.js +0 -64
- package/ts/config.json +0 -22
- package/ts/custom.d.ts +0 -120
package/src/config/deploy.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
// Native
|
|
2
|
-
const { join } = require('path');
|
|
3
|
-
|
|
4
|
-
// External
|
|
5
|
-
const importLazy = require('import-lazy')(require);
|
|
6
|
-
const loadJsonFile = importLazy('load-json-file');
|
|
7
|
-
|
|
8
|
-
// Ours
|
|
9
|
-
const { VALID_TYPES } = require('../cli/deploy/constants');
|
|
10
|
-
const { isRepoSync, getCurrentLabelSync } = require('../utils/git');
|
|
11
|
-
const { warn } = require('../utils/logging');
|
|
12
|
-
const { combine } = require('../utils/structures');
|
|
13
|
-
const { getBuildConfig } = require('./build');
|
|
14
|
-
const { getProjectConfig } = require('./project');
|
|
15
|
-
|
|
16
|
-
const DEFAULT_PROFILES_FILE_PATH = join(
|
|
17
|
-
process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE,
|
|
18
|
-
'.abc-credentials'
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
const KNOWN_PROFILES_CONFIG = {
|
|
22
|
-
contentftp: {
|
|
23
|
-
to: '/www/res/sites/news-projects/<name>/<id>',
|
|
24
|
-
resolvePublicPath: config => `${config.to.replace('/www', 'https://www.abc.net.au')}/`
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const MESSAGES = {
|
|
29
|
-
incomplete: 'Your deploy configuration may be missing required properties.',
|
|
30
|
-
noProfile: () => `Your profiles file doesn't contain a "${profile}" profile. ${MESSAGES.incomplete}`,
|
|
31
|
-
noProfilesFile: path => `Could not load a profiles file from "${path}". ${MESSAGES.incomplete}`
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
module.exports.getDeployConfig = ({ id } = {}) => {
|
|
35
|
-
let { deploy: projectDeployTargetsConfigs } = getProjectConfig();
|
|
36
|
-
const { to } = getBuildConfig();
|
|
37
|
-
|
|
38
|
-
id = id || (isRepoSync() && getCurrentLabelSync()) || 'unversioned';
|
|
39
|
-
|
|
40
|
-
// Ensure projectDeployTargetsConfigs is not a primitive
|
|
41
|
-
if (typeof projectDeployTargetsConfigs !== 'object') {
|
|
42
|
-
projectDeployTargetsConfigs = {};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ## DEPRECATED ##
|
|
46
|
-
// Convert old profile key-based config objects to array
|
|
47
|
-
else if (!Array.isArray(projectDeployTargetsConfigs)) {
|
|
48
|
-
const projectDeployTargetsConfigsKeys = Object.keys(projectDeployTargetsConfigs);
|
|
49
|
-
const expectedProps = VALID_TYPES.get('ftp').REQUIRED_PROPERTIES;
|
|
50
|
-
// We assume that if we find an prop that references an object and
|
|
51
|
-
// isn't in the expected props for an FTP target, it was a profile name
|
|
52
|
-
if (
|
|
53
|
-
projectDeployTargetsConfigsKeys.filter(
|
|
54
|
-
key => typeof projectDeployTargetsConfigs[key] === 'object' && !expectedProps.includes(key)
|
|
55
|
-
).length > 0
|
|
56
|
-
) {
|
|
57
|
-
projectDeployTargetsConfigs = projectDeployTargetsConfigsKeys.map(profile =>
|
|
58
|
-
combine({ profile }, projectDeployTargetsConfigs[profile])
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// ## END DEPRECATED ##
|
|
63
|
-
|
|
64
|
-
// Ensure projectDeployConfig is an array
|
|
65
|
-
if (!Array.isArray(projectDeployTargetsConfigs)) {
|
|
66
|
-
projectDeployTargetsConfigs = [projectDeployTargetsConfigs];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const deployTargetConfigInputProperties = {
|
|
70
|
-
id,
|
|
71
|
-
from: to,
|
|
72
|
-
files: '**'
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
id,
|
|
77
|
-
targets: projectDeployTargetsConfigs.map(projectDeployTargetConfig =>
|
|
78
|
-
combine(
|
|
79
|
-
deployTargetConfigInputProperties,
|
|
80
|
-
addKnownProfileProperties,
|
|
81
|
-
projectDeployTargetConfig,
|
|
82
|
-
resolveProperties,
|
|
83
|
-
removeExtraneousProperties
|
|
84
|
-
)
|
|
85
|
-
)
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const addKnownProfileProperties = config => {
|
|
90
|
-
const profile = config.profile || 'contentftp'; // default
|
|
91
|
-
|
|
92
|
-
return combine(config, { profile }, KNOWN_PROFILES_CONFIG[profile]);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
function resolveProperties(config) {
|
|
96
|
-
const { pkg, root } = getProjectConfig();
|
|
97
|
-
const { name } = pkg;
|
|
98
|
-
// Package name may be in `@scope/name` format
|
|
99
|
-
const unscopedName = name.split('/').reverse()[0];
|
|
100
|
-
|
|
101
|
-
config.from = join(root, config.from);
|
|
102
|
-
config.to = config.to.replace('<name>', unscopedName).replace('<id>', config.id);
|
|
103
|
-
config.publicPath = typeof config.resolvePublicPath === 'function' ? config.resolvePublicPath(config) : '/';
|
|
104
|
-
|
|
105
|
-
return config;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function removeExtraneousProperties(config) {
|
|
109
|
-
delete config.id;
|
|
110
|
-
delete config.resolvePublicPath;
|
|
111
|
-
|
|
112
|
-
return Object.keys(config)
|
|
113
|
-
.sort()
|
|
114
|
-
.reduce((memo, prop) => {
|
|
115
|
-
memo[prop] = config[prop];
|
|
116
|
-
|
|
117
|
-
return memo;
|
|
118
|
-
}, {});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
module.exports.addProfileProperties = config => {
|
|
122
|
-
const { profile } = config;
|
|
123
|
-
const profilesFilePath = config.profilesFilePath || DEFAULT_PROFILES_FILE_PATH;
|
|
124
|
-
let profiles;
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
profiles = loadJsonFile.sync(profilesFilePath);
|
|
128
|
-
} catch (err) {
|
|
129
|
-
warn(MESSAGES.noProfilesFile(profilesFilePath));
|
|
130
|
-
|
|
131
|
-
return config;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const profileProps = profiles[profile];
|
|
135
|
-
|
|
136
|
-
if (!profileProps) {
|
|
137
|
-
warn(MESSAGES.noProfile(profile));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return combine(config, profileProps);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
module.exports.addKnownProfileProperties = addKnownProfileProperties;
|
package/src/config/jest/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Ours
|
|
2
|
-
const { merge } = require('../../utils/structures');
|
|
3
|
-
const { getProjectConfig } = require('../project');
|
|
4
|
-
|
|
5
|
-
module.exports.getJestConfig = () => {
|
|
6
|
-
const { jest: projectJestConfig, root } = getProjectConfig();
|
|
7
|
-
const defaultTransformerPath = require.resolve('./transformer-default');
|
|
8
|
-
|
|
9
|
-
return merge(
|
|
10
|
-
{
|
|
11
|
-
rootDir: root,
|
|
12
|
-
verbose: true,
|
|
13
|
-
transform: {
|
|
14
|
-
'^.+\\.svelte$': require.resolve('./transformer-svelte'),
|
|
15
|
-
'.*': defaultTransformerPath
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
projectJestConfig
|
|
19
|
-
);
|
|
20
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Native
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
// External
|
|
5
|
-
const importLazy = require('import-lazy')(require);
|
|
6
|
-
const babelJest = importLazy('babel-jest');
|
|
7
|
-
|
|
8
|
-
// Ours
|
|
9
|
-
const { getBabelConfig } = require('../babel');
|
|
10
|
-
|
|
11
|
-
const MEDIA_RESOURCE_PATTERN = /\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$/;
|
|
12
|
-
const STYLE_RESOURCE_PATTERN = /\.s?css$/;
|
|
13
|
-
const STYLE_RESOURCE_REPLACEMENT = 'module.exports = new Proxy({}, { get: (styles, method) => method });';
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
process(src, filename, config) {
|
|
17
|
-
// Mock media & style resources
|
|
18
|
-
if (filename.match(MEDIA_RESOURCE_PATTERN)) {
|
|
19
|
-
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';';
|
|
20
|
-
} else if (filename.match(STYLE_RESOURCE_PATTERN)) {
|
|
21
|
-
return STYLE_RESOURCE_REPLACEMENT;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Run everything else through babel
|
|
25
|
-
return babelJest.createTransformer(getBabelConfig()).process(src, filename, config, { sourceMaps: false });
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// Native
|
|
2
|
-
const { execSync } = require('child_process');
|
|
3
|
-
const { basename } = require('path');
|
|
4
|
-
|
|
5
|
-
// External
|
|
6
|
-
const importLazy = require('import-lazy')(require);
|
|
7
|
-
const svelte = importLazy('svelte/compiler');
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
process(src, filename) {
|
|
11
|
-
const preprocessor = require.resolve('./transformer-svelte-preprocess.js');
|
|
12
|
-
|
|
13
|
-
const processed = execSync(`node --unhandled-rejections=strict --abort-on-uncaught-exception ${preprocessor}`, {
|
|
14
|
-
env: { PATH: process.env.PATH, src, filename }
|
|
15
|
-
}).toString();
|
|
16
|
-
|
|
17
|
-
const result = svelte.compile(processed, {
|
|
18
|
-
filename: basename(filename),
|
|
19
|
-
css: true,
|
|
20
|
-
accessors: true,
|
|
21
|
-
dev: true,
|
|
22
|
-
format: 'cjs'
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const esInterop = 'Object.defineProperty(exports, "__esModule", { value: true });';
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
code: result.js.code + esInterop,
|
|
29
|
-
map: result.js.map
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
};
|
package/src/config/project.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Global
|
|
2
|
-
const { existsSync } = require('fs');
|
|
3
|
-
const { join } = require('path');
|
|
4
|
-
|
|
5
|
-
// External
|
|
6
|
-
const importLazy = require('import-lazy')(require);
|
|
7
|
-
const guessRootPath = importLazy('guess-root-path');
|
|
8
|
-
const mem = require('mem');
|
|
9
|
-
|
|
10
|
-
// Ours
|
|
11
|
-
const { hvy } = require('../utils/color');
|
|
12
|
-
const { pretty } = require('../utils/logging');
|
|
13
|
-
const { combine } = require('../utils/structures');
|
|
14
|
-
const { PROJECT_CONFIG_FILE_NAME } = require('../constants');
|
|
15
|
-
|
|
16
|
-
function ensureProjectConfigShape(x) {
|
|
17
|
-
return typeof x === 'object' ? x : typeof x === 'string' ? { type: x } : {};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports.getProjectConfig = mem(() => {
|
|
21
|
-
const root = guessRootPath();
|
|
22
|
-
|
|
23
|
-
if (root === null) {
|
|
24
|
-
throw new Error(`Aunty doesn't work if your project doesn't have a ${hvy('package.json')} file.`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let pkg;
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
pkg = require(`${root}/package.json`);
|
|
31
|
-
} catch (err) {
|
|
32
|
-
throw pretty(err);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let projectConfigModule;
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
projectConfigModule = require(`${root}/${PROJECT_CONFIG_FILE_NAME}`);
|
|
39
|
-
} catch (err) {
|
|
40
|
-
// The standalone config file is optional, but it may have syntax problems
|
|
41
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
42
|
-
throw pretty(err);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const hasTS = existsSync(join(root, 'tsconfig.json'));
|
|
47
|
-
|
|
48
|
-
return combine(
|
|
49
|
-
{
|
|
50
|
-
root,
|
|
51
|
-
pkg,
|
|
52
|
-
hasTS
|
|
53
|
-
},
|
|
54
|
-
ensureProjectConfigShape(pkg.aunty),
|
|
55
|
-
ensureProjectConfigShape(projectConfigModule)
|
|
56
|
-
);
|
|
57
|
-
});
|
package/src/config/serve.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
// Native
|
|
2
|
-
const { homedir, hostname } = require('os');
|
|
3
|
-
const { readFileSync } = require('fs');
|
|
4
|
-
const { join } = require('path');
|
|
5
|
-
const { Socket } = require('net');
|
|
6
|
-
|
|
7
|
-
// External
|
|
8
|
-
const { probe } = require('tcp-ping-sync');
|
|
9
|
-
|
|
10
|
-
// Ours
|
|
11
|
-
const { combine } = require('../utils/structures');
|
|
12
|
-
const { getProjectConfig } = require('./project');
|
|
13
|
-
const { info } = require('../utils/logging');
|
|
14
|
-
const { MESSAGES } = require('../cli/serve/constants');
|
|
15
|
-
const { INTERNAL_TEST_HOST } = require('../constants');
|
|
16
|
-
|
|
17
|
-
const HOME_DIR = homedir();
|
|
18
|
-
const SSL_DIR = '.aunty/ssl';
|
|
19
|
-
const SERVER_CERT_FILENAME = (module.exports.SERVER_CERT_FILENAME = 'server.crt');
|
|
20
|
-
const SERVER_KEY_FILENAME = (module.exports.SERVER_KEY_FILENAME = 'server.key');
|
|
21
|
-
const INTERNAL_SUFFIX = '.aus.aunty.abc.net.au';
|
|
22
|
-
const DEFAULT_HOST = (module.exports.DEFAULT_HOST = probe(INTERNAL_TEST_HOST)
|
|
23
|
-
? `${hostname().toLowerCase().split('.')[0]}${INTERNAL_SUFFIX}` // hostname _may_ include INTERNAL_SUFFIX
|
|
24
|
-
: 'localhost');
|
|
25
|
-
const DEFAULT_PORT = 8000;
|
|
26
|
-
|
|
27
|
-
const addEnvironmentVariables = config => {
|
|
28
|
-
if (process.env.AUNTY_HOST) {
|
|
29
|
-
config.host = process.env.AUNTY_HOST;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (process.env.AUNTY_PORT) {
|
|
33
|
-
config.port = process.env.AUNTY_PORT;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return config;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const getSSLPath = (module.exports.getSSLPath = (host, name) => join(HOME_DIR, SSL_DIR, host, name || '.'));
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Set config.https to cert & key generated with `aunty sign-cert` (if they both exist)
|
|
43
|
-
* We expect them to be in: ~/.aunty/ssl/<host>/server.{cert|key}
|
|
44
|
-
*/
|
|
45
|
-
const addUserSSLConfig = config => {
|
|
46
|
-
if (config.https === true) {
|
|
47
|
-
try {
|
|
48
|
-
config.https = {
|
|
49
|
-
cert: readFileSync(getSSLPath(config.host, SERVER_CERT_FILENAME)),
|
|
50
|
-
key: readFileSync(getSSLPath(config.host, SERVER_KEY_FILENAME))
|
|
51
|
-
};
|
|
52
|
-
} catch (e) {}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return config;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Find an open port, or keep incrementing until we get one
|
|
60
|
-
*/
|
|
61
|
-
const findPort = async (port, max = port + 100, host = '0.0.0.0') => {
|
|
62
|
-
return new Promise((resolve, reject) => {
|
|
63
|
-
const socket = new Socket();
|
|
64
|
-
|
|
65
|
-
const next = errorType => {
|
|
66
|
-
socket.destroy();
|
|
67
|
-
info(MESSAGES.port({ port, errorType }));
|
|
68
|
-
if (port <= max) resolve(findPort(port + 1, max, host));
|
|
69
|
-
else reject(new Error('Could not find an available port'));
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const found = () => {
|
|
73
|
-
socket.destroy();
|
|
74
|
-
resolve(port);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// Port is taken if connection can be made
|
|
78
|
-
socket.once('connect', () => next('in use'));
|
|
79
|
-
|
|
80
|
-
// Port is open if connection attempt times out
|
|
81
|
-
socket.setTimeout(500);
|
|
82
|
-
socket.once('timeout', found);
|
|
83
|
-
|
|
84
|
-
// If an error occurs, it's assumed the port is available.
|
|
85
|
-
socket.once('error', e => {
|
|
86
|
-
// If the connection is refused, it's assumed nothing is listening and the port is available.
|
|
87
|
-
if (e.code === 'ECONNREFUSED') {
|
|
88
|
-
found();
|
|
89
|
-
} else if (e.code === 'ENOTFOUND' && e.syscall === 'getaddrinfo' && e.hostname?.includes(INTERNAL_SUFFIX)) {
|
|
90
|
-
console.error(
|
|
91
|
-
[
|
|
92
|
-
'Could not resolve hostname ' + e.hostname,
|
|
93
|
-
'You appear to be on the ABC network without a hostname attached to your computer.',
|
|
94
|
-
"Aunty can't continue. Consider reconnecting, or add your hostname to your hosts file.",
|
|
95
|
-
''
|
|
96
|
-
].join('\n')
|
|
97
|
-
);
|
|
98
|
-
process.exit(1);
|
|
99
|
-
} else {
|
|
100
|
-
// Not sure what to do with other errors. Log the code & keep seeking a free port.
|
|
101
|
-
next(`error code ${e.code}`);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
socket.connect(port, host);
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const _getServeConfig = async () => {
|
|
110
|
-
const { serve } = getProjectConfig();
|
|
111
|
-
|
|
112
|
-
const config = combine(
|
|
113
|
-
{
|
|
114
|
-
hasBundleAnalysis: false,
|
|
115
|
-
host: DEFAULT_HOST,
|
|
116
|
-
hot: process.env.NODE_ENV === 'development',
|
|
117
|
-
https: true,
|
|
118
|
-
port: DEFAULT_PORT
|
|
119
|
-
},
|
|
120
|
-
serve,
|
|
121
|
-
addEnvironmentVariables,
|
|
122
|
-
addUserSSLConfig
|
|
123
|
-
);
|
|
124
|
-
const port = await findPort(config.port, config.port + 100, config.host);
|
|
125
|
-
config.port = port;
|
|
126
|
-
|
|
127
|
-
return config;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
let _serveConfigPromiseSingleton;
|
|
131
|
-
|
|
132
|
-
// getServeConfig is called twice during server startup, because the `serve`
|
|
133
|
-
// command calls it directly, then indirectly, via getWebpackDevServerConfig.
|
|
134
|
-
// Because it won't change during a single `serve` command, and because we
|
|
135
|
-
// don't want to waste time doing port lookups with `findPort` multiple times
|
|
136
|
-
// we just cache the promise created on the first run, and return that later.
|
|
137
|
-
|
|
138
|
-
module.exports.getServeConfig = async () => {
|
|
139
|
-
if (!_serveConfigPromiseSingleton) {
|
|
140
|
-
_serveConfigPromiseSingleton = _getServeConfig();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return _serveConfigPromiseSingleton;
|
|
144
|
-
};
|