@abcnews/aunty 16.0.1 → 17.0.0-next.0
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/dist/bin/aunty.js +3 -0
- package/dist/lib/constants.js +8 -0
- package/package.json +25 -82
- 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/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
|
-
};
|
package/src/config/webpack.js
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
// Native
|
|
2
|
-
const { existsSync } = require('fs');
|
|
3
|
-
const { join, resolve } = require('path');
|
|
4
|
-
|
|
5
|
-
// External
|
|
6
|
-
const importLazy = require('import-lazy')(require);
|
|
7
|
-
const CopyPlugin = importLazy('copy-webpack-plugin');
|
|
8
|
-
const Dotenv = importLazy('dotenv-webpack');
|
|
9
|
-
const ForkTsCheckerWebpackPlugin = importLazy('fork-ts-checker-webpack-plugin');
|
|
10
|
-
const MiniCssExtractPlugin = importLazy('mini-css-extract-plugin');
|
|
11
|
-
const sveltePreprocess = importLazy('svelte-preprocess');
|
|
12
|
-
const EnvironmentPlugin = importLazy('webpack/lib/EnvironmentPlugin');
|
|
13
|
-
|
|
14
|
-
// Ours
|
|
15
|
-
const { combine, merge } = require('../utils/structures');
|
|
16
|
-
const { getBabelConfig } = require('./babel');
|
|
17
|
-
const { getBuildConfig } = require('./build');
|
|
18
|
-
const { getProjectConfig } = require('./project');
|
|
19
|
-
|
|
20
|
-
const JSX_RESOLVE_EXTENSIONS = ['.jsx', '.tsx'];
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Project types to override the Webpack config.
|
|
24
|
-
*/
|
|
25
|
-
const PROJECT_TYPES_CONFIG = {
|
|
26
|
-
preact: {
|
|
27
|
-
resolve: {
|
|
28
|
-
alias: {
|
|
29
|
-
react: 'preact',
|
|
30
|
-
'react-dom': 'preact/compat'
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
extensions: JSX_RESOLVE_EXTENSIONS
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
react: {
|
|
37
|
-
resolve: {
|
|
38
|
-
extensions: JSX_RESOLVE_EXTENSIONS
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Svelte uses a function to modify the existing config, rather than just merging in.
|
|
44
|
-
* @see combine
|
|
45
|
-
*/
|
|
46
|
-
svelte: config => {
|
|
47
|
-
config.resolve = {
|
|
48
|
-
extensions: [...config.resolve.extensions, '.svelte'],
|
|
49
|
-
mainFields: ['svelte', 'browser', 'module', 'main'],
|
|
50
|
-
conditionNames: ['svelte', 'browser', 'import']
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const { include, loader, options } = getHintedRule(config, 'scripts');
|
|
54
|
-
const extractCSS = getHintedRule(config, 'styles').use[0].loader === MiniCssExtractPlugin.loader;
|
|
55
|
-
|
|
56
|
-
include.push(/(node_modules\/svelte)/);
|
|
57
|
-
|
|
58
|
-
// options from https://github.com/sveltejs/svelte-loader
|
|
59
|
-
config.module.rules.push(
|
|
60
|
-
...[
|
|
61
|
-
{
|
|
62
|
-
test: /\.svelte\.ts$/,
|
|
63
|
-
use: [
|
|
64
|
-
{
|
|
65
|
-
loader,
|
|
66
|
-
options
|
|
67
|
-
},
|
|
68
|
-
{ loader: require.resolve('ts-loader'), options: { transpileOnly: true } },
|
|
69
|
-
{
|
|
70
|
-
loader: require.resolve('svelte-loader'),
|
|
71
|
-
options: {
|
|
72
|
-
dev: config.mode === 'development',
|
|
73
|
-
emitCss: extractCSS,
|
|
74
|
-
preprocess: sveltePreprocess()
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
]
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
test: /(?<!\.svelte)\.ts$/,
|
|
81
|
-
loader: require.resolve('ts-loader'),
|
|
82
|
-
options: {
|
|
83
|
-
transpileOnly: true // you should use svelte-check for type checking
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
// Svelte 5+:
|
|
88
|
-
test: /\.(svelte|svelte\.js)$/,
|
|
89
|
-
include,
|
|
90
|
-
use: [
|
|
91
|
-
{
|
|
92
|
-
loader,
|
|
93
|
-
options
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
loader: require.resolve('svelte-loader'),
|
|
97
|
-
options: {
|
|
98
|
-
dev: config.mode === 'development',
|
|
99
|
-
emitCss: extractCSS,
|
|
100
|
-
preprocess: sveltePreprocess()
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
// required to prevent errors from Svelte on Webpack 5+, omit on Webpack 4
|
|
107
|
-
test: /node_modules\/svelte\/.*\.mjs$/,
|
|
108
|
-
resolve: {
|
|
109
|
-
fullySpecified: false
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
]
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
return config;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
const WEBPACK_CONFIG_FILE = 'webpack.config.js';
|
|
119
|
-
|
|
120
|
-
module.exports.getWebpackConfig = () => {
|
|
121
|
-
const { root } = getProjectConfig();
|
|
122
|
-
const { addModernJS, showDeprecations } = getBuildConfig();
|
|
123
|
-
const customWebpackConfigFilePath = join(root, WEBPACK_CONFIG_FILE);
|
|
124
|
-
|
|
125
|
-
if (showDeprecations) {
|
|
126
|
-
process.traceDeprecation = true;
|
|
127
|
-
} else {
|
|
128
|
-
process.noDeprecation = true;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
let config;
|
|
132
|
-
|
|
133
|
-
// If the project has a webpack config file, use it, otherwise create our own
|
|
134
|
-
if (existsSync(customWebpackConfigFilePath)) {
|
|
135
|
-
config = require(customWebpackConfigFilePath);
|
|
136
|
-
|
|
137
|
-
if (!Array.isArray(config)) {
|
|
138
|
-
config = [config];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Ensure functions are resolved to objects
|
|
142
|
-
config = config.map(combine);
|
|
143
|
-
} else {
|
|
144
|
-
config = [createWebpackConfig()];
|
|
145
|
-
|
|
146
|
-
// Duplicate the config if the project expects an additional modern JS build
|
|
147
|
-
if (addModernJS) {
|
|
148
|
-
config.push(createWebpackConfig({ isModernJS: true }));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return config;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const createEntriesDictionary = (root, from, entry) =>
|
|
156
|
-
(Array.isArray(entry) ? entry : [entry]).reduce(
|
|
157
|
-
(memo, _entry) => ({ ...memo, [_entry]: [join(root, from, _entry)] }),
|
|
158
|
-
{}
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
const resolveIncludedDependencies = (includedDependencies, root) => {
|
|
162
|
-
if (!Array.isArray(includedDependencies)) {
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return includedDependencies.map(packageNameOrPattern => {
|
|
167
|
-
if (typeof packageNameOrPattern === 'string') {
|
|
168
|
-
return resolve(root, 'node_modules', packageNameOrPattern);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (packageNameOrPattern instanceof RegExp) {
|
|
172
|
-
return new RegExp(join('node_modules', packageNameOrPattern.source), packageNameOrPattern.flags);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return null;
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
function createWebpackConfig({ isModernJS } = {}) {
|
|
180
|
-
const { pkg, root, hasTS, type, webpack: projectWebpackConfig } = getProjectConfig();
|
|
181
|
-
const { entry, extractCSS, from, includedDependencies, staticDir, to, useCSSModules } = getBuildConfig();
|
|
182
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
183
|
-
const hasEnvFile = existsSync(join(root, '.env'));
|
|
184
|
-
const hasEnvExampleFile = existsSync(join(root, '.env.example'));
|
|
185
|
-
|
|
186
|
-
const config = merge(
|
|
187
|
-
{
|
|
188
|
-
mode: isProd ? 'production' : 'development',
|
|
189
|
-
target: isModernJS ? 'web' : ['web', 'es5'],
|
|
190
|
-
cache: true,
|
|
191
|
-
entry: createEntriesDictionary(root, from, entry),
|
|
192
|
-
devtool: 'source-map',
|
|
193
|
-
output: {
|
|
194
|
-
path: join(root, to),
|
|
195
|
-
publicPath: '/',
|
|
196
|
-
filename: isModernJS ? '[name]_modern.js' : '[name].js'
|
|
197
|
-
},
|
|
198
|
-
resolve: {
|
|
199
|
-
extensions: ['.mjs', '.js', '.json', '.ts']
|
|
200
|
-
},
|
|
201
|
-
module: {
|
|
202
|
-
rules: [
|
|
203
|
-
{
|
|
204
|
-
/**
|
|
205
|
-
* hints are used by PROJECT_TYPES_CONFIGs to quickly select the right config.
|
|
206
|
-
* @see PROJECT_TYPES_CONFIG
|
|
207
|
-
*/
|
|
208
|
-
__hint__: 'scripts',
|
|
209
|
-
test: hasTS ? /\.m?[jt]sx?$/ : /\.m?jsx?$/,
|
|
210
|
-
include: [resolve(root, from)].concat(resolveIncludedDependencies(includedDependencies, root)),
|
|
211
|
-
loader: require.resolve('babel-loader'),
|
|
212
|
-
options: getBabelConfig({ isModernJS })
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
__hint__: 'styles',
|
|
216
|
-
test: /\.(css|scss)$/,
|
|
217
|
-
use: [
|
|
218
|
-
extractCSS
|
|
219
|
-
? {
|
|
220
|
-
loader: MiniCssExtractPlugin.loader
|
|
221
|
-
}
|
|
222
|
-
: {
|
|
223
|
-
loader: require.resolve('style-loader')
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
loader: require.resolve('css-loader'),
|
|
227
|
-
options: {
|
|
228
|
-
modules: useCSSModules && {
|
|
229
|
-
exportLocalsConvention: 'camelCase',
|
|
230
|
-
localIdentContext: __dirname,
|
|
231
|
-
// ^^^ https://github.com/webpack-contrib/css-loader/issues/413#issuecomment-299578180
|
|
232
|
-
localIdentHashSalt: `${pkg.name}@${pkg.version}`,
|
|
233
|
-
localIdentName: `${isProd ? '' : '[folder]-[name]__[local]--'}[hash:base64:6]`
|
|
234
|
-
},
|
|
235
|
-
sourceMap: !isProd
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
loader: require.resolve('sass-loader')
|
|
240
|
-
}
|
|
241
|
-
]
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
__hint__: 'data',
|
|
245
|
-
test: /\.[tc]sv$/,
|
|
246
|
-
loader: 'csv-loader',
|
|
247
|
-
options: {
|
|
248
|
-
dynamicTyping: true,
|
|
249
|
-
header: true,
|
|
250
|
-
skipEmptyLines: true
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
test: /\.(jpg|png|gif|mp4|m4v|flv|mp3|wav|m4a|eot|ttf|woff|woff2|webm|webp|avif)$/,
|
|
255
|
-
type: 'asset'
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
test: /\.svg$/,
|
|
259
|
-
resourceQuery: { not: [/raw/] },
|
|
260
|
-
type: 'asset'
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
resourceQuery: /raw/,
|
|
264
|
-
type: 'asset/source'
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
test: /\.html$/,
|
|
268
|
-
type: 'asset/source'
|
|
269
|
-
}
|
|
270
|
-
]
|
|
271
|
-
},
|
|
272
|
-
plugins: [
|
|
273
|
-
new EnvironmentPlugin(Object.keys(process.env)),
|
|
274
|
-
hasEnvFile || hasEnvExampleFile
|
|
275
|
-
? new Dotenv({
|
|
276
|
-
safe: hasEnvExampleFile
|
|
277
|
-
})
|
|
278
|
-
: null,
|
|
279
|
-
hasTS
|
|
280
|
-
? new ForkTsCheckerWebpackPlugin({
|
|
281
|
-
logger: { infrastructure: 'silent', issues: 'silent' },
|
|
282
|
-
typescript: {
|
|
283
|
-
diagnosticOptions: {
|
|
284
|
-
semantic: true,
|
|
285
|
-
syntactic: true
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
})
|
|
289
|
-
: null,
|
|
290
|
-
extractCSS
|
|
291
|
-
? new MiniCssExtractPlugin({
|
|
292
|
-
filename: `[name].css`
|
|
293
|
-
})
|
|
294
|
-
: null,
|
|
295
|
-
new CopyPlugin({
|
|
296
|
-
patterns: (Array.isArray(staticDir) ? staticDir : [staticDir]).map(dirName => ({
|
|
297
|
-
from: join(root, dirName)
|
|
298
|
-
}))
|
|
299
|
-
})
|
|
300
|
-
].filter(x => x),
|
|
301
|
-
optimization: {
|
|
302
|
-
moduleIds: isProd ? 'deterministic' : 'named'
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
PROJECT_TYPES_CONFIG[type],
|
|
306
|
-
projectWebpackConfig
|
|
307
|
-
);
|
|
308
|
-
|
|
309
|
-
if (isProd) {
|
|
310
|
-
config.optimization.minimize = true;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// Cleanup hints
|
|
314
|
-
config.module.rules.forEach(rule => {
|
|
315
|
-
if (rule.__hint__) {
|
|
316
|
-
delete rule.__hint__;
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
return config;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function getHintedRule(config, hint) {
|
|
324
|
-
return config.module.rules.find(rule => rule.__hint__ === hint);
|
|
325
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Native
|
|
2
|
-
const { join } = require('path');
|
|
3
|
-
|
|
4
|
-
// Ours
|
|
5
|
-
const { combine } = require('../utils/structures');
|
|
6
|
-
const { getBuildConfig } = require('./build');
|
|
7
|
-
const { getProjectConfig } = require('./project');
|
|
8
|
-
const { getServeConfig } = require('./serve');
|
|
9
|
-
|
|
10
|
-
module.exports.getWebpackDevServerConfig = async () => {
|
|
11
|
-
const { root, webpackDevServer: projectWebpackDevServerConfig } = getProjectConfig();
|
|
12
|
-
const { staticDir } = getBuildConfig();
|
|
13
|
-
const { host, hot, https, port } = await getServeConfig();
|
|
14
|
-
|
|
15
|
-
return combine(
|
|
16
|
-
{
|
|
17
|
-
allowedHosts: 'all',
|
|
18
|
-
client: {
|
|
19
|
-
logging: 'warn',
|
|
20
|
-
overlay: true,
|
|
21
|
-
webSocketURL: `ws${https ? 's' : ''}://${host}:${port}/ws`
|
|
22
|
-
},
|
|
23
|
-
devMiddleware: {
|
|
24
|
-
publicPath: `http${https ? 's' : ''}://${host}:${port}/`
|
|
25
|
-
},
|
|
26
|
-
headers: {
|
|
27
|
-
'Access-Control-Allow-Origin': '*'
|
|
28
|
-
},
|
|
29
|
-
host: '0.0.0.0',
|
|
30
|
-
hot,
|
|
31
|
-
port,
|
|
32
|
-
server: https
|
|
33
|
-
? typeof https === 'object'
|
|
34
|
-
? {
|
|
35
|
-
type: 'https',
|
|
36
|
-
options: https
|
|
37
|
-
}
|
|
38
|
-
: 'https'
|
|
39
|
-
: 'http',
|
|
40
|
-
static: (Array.isArray(staticDir) ? staticDir : [staticDir]).map(dirName => ({
|
|
41
|
-
directory: join(root, dirName)
|
|
42
|
-
}))
|
|
43
|
-
},
|
|
44
|
-
projectWebpackDevServerConfig
|
|
45
|
-
);
|
|
46
|
-
};
|
package/src/constants.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
// External
|
|
2
|
-
const Inflect = require('i')();
|
|
3
|
-
const Generator = require('yeoman-generator');
|
|
4
|
-
|
|
5
|
-
// Ours
|
|
6
|
-
const { getProjectConfig } = require('../../config/project');
|
|
7
|
-
const { cmd, hvy, opt } = require('../../utils/color');
|
|
8
|
-
const { success } = require('../../utils/logging');
|
|
9
|
-
const { installDependencies } = require('../../utils/npm');
|
|
10
|
-
const { combine } = require('../../utils/structures');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Generate a Component
|
|
14
|
-
*/
|
|
15
|
-
module.exports = class extends Generator {
|
|
16
|
-
constructor(args, opts) {
|
|
17
|
-
super(args, {
|
|
18
|
-
...opts,
|
|
19
|
-
localConfigOnly: true
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
this.argument('name', { required: false });
|
|
23
|
-
|
|
24
|
-
this.option('template', {
|
|
25
|
-
description: 'Type of project [basic|preact|react|svelte]'
|
|
26
|
-
});
|
|
27
|
-
this.option('d3', { description: 'This component will use D3' });
|
|
28
|
-
|
|
29
|
-
this.dependencies = [];
|
|
30
|
-
this.devDependencies = [];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
usage() {
|
|
34
|
-
return `${cmd('aunty generate component')} -- ${opt('[options] [<name>]')}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
initializing() {
|
|
38
|
-
try {
|
|
39
|
-
const { root, type, hasTS } = getProjectConfig();
|
|
40
|
-
|
|
41
|
-
process.chdir(root);
|
|
42
|
-
this.destinationRoot(root);
|
|
43
|
-
this.options.template = type;
|
|
44
|
-
this.options.typescript = hasTS;
|
|
45
|
-
} catch (err) {}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async prompting() {
|
|
49
|
-
let prompts = [];
|
|
50
|
-
|
|
51
|
-
if (!this.options.template) {
|
|
52
|
-
prompts.push({
|
|
53
|
-
type: 'list',
|
|
54
|
-
name: 'template',
|
|
55
|
-
message: 'What type of project is it again?',
|
|
56
|
-
choices: [
|
|
57
|
-
{ name: 'Preact', value: 'preact' },
|
|
58
|
-
{ name: 'Basic', value: 'basic' },
|
|
59
|
-
{ name: 'React', value: 'react' },
|
|
60
|
-
{ name: 'Svelte', value: 'svelte' }
|
|
61
|
-
]
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!this.options.name) {
|
|
66
|
-
prompts.push({
|
|
67
|
-
type: 'input',
|
|
68
|
-
name: 'name',
|
|
69
|
-
message: 'Component name?',
|
|
70
|
-
default: 'NewComponent'
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!this.options.d3) {
|
|
75
|
-
prompts.push({
|
|
76
|
-
type: 'confirm',
|
|
77
|
-
name: 'd3',
|
|
78
|
-
message: 'Is this a D3 component?',
|
|
79
|
-
default: false
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (prompts.length > 0) {
|
|
84
|
-
const answers = await this.prompt(prompts);
|
|
85
|
-
this.options = combine(this.options, answers);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.options.name = Inflect.camelize(this.options.name.replace(' ', '_'));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
writing() {
|
|
92
|
-
const isSFC = this.options.template === 'svelte';
|
|
93
|
-
const isJSX = this.options.template === 'preact' || this.options.template === 'react';
|
|
94
|
-
const sourceName = `component${this.options.d3 ? '-with-d3' : ''}`;
|
|
95
|
-
const sourceScriptExt = isJSX ? 'tsx' : 'ts';
|
|
96
|
-
const destinationScriptExt = this.options.typescript ? sourceScriptExt : 'js';
|
|
97
|
-
const context = {
|
|
98
|
-
className: this.options.name,
|
|
99
|
-
isTS: this.options.typescript
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
if (isSFC) {
|
|
103
|
-
this.fs.copyTpl(
|
|
104
|
-
this.templatePath(this.options.template, `${sourceName}.${this.options.template}`),
|
|
105
|
-
this.destinationPath(`src/components/${this.options.name}/${this.options.name}.${this.options.template}`),
|
|
106
|
-
context
|
|
107
|
-
);
|
|
108
|
-
} else {
|
|
109
|
-
this.fs.copyTpl(
|
|
110
|
-
this.templatePath(this.options.template, `${sourceName}.${sourceScriptExt}`),
|
|
111
|
-
this.destinationPath(`src/components/${this.options.name}/index.${destinationScriptExt}`),
|
|
112
|
-
context,
|
|
113
|
-
{ globOptions: { noext: true } }
|
|
114
|
-
);
|
|
115
|
-
this.fs.copy(
|
|
116
|
-
this.templatePath(`_non_sfc/styles.scss`),
|
|
117
|
-
this.destinationPath(`src/components/${this.options.name}/styles.scss`),
|
|
118
|
-
context
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
this.fs.copyTpl(
|
|
123
|
-
this.templatePath(this.options.template, `${sourceName}.test.${sourceScriptExt}`),
|
|
124
|
-
this.destinationPath(
|
|
125
|
-
`src/components/${this.options.name}/${isSFC ? this.options.name : 'index'}.test.${destinationScriptExt}`
|
|
126
|
-
),
|
|
127
|
-
context,
|
|
128
|
-
{ globOptions: { noext: true } }
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async install() {
|
|
133
|
-
if (this.options.typescript) {
|
|
134
|
-
this.devDependencies.push('@types/jest', '@types/webpack-env');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (this.options.d3) {
|
|
138
|
-
this.dependencies.push('d3-selection');
|
|
139
|
-
|
|
140
|
-
if (this.options.typescript) {
|
|
141
|
-
this.devDependencies.push('@types/d3-selection');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
switch (this.options.template) {
|
|
146
|
-
case 'preact':
|
|
147
|
-
this.devDependencies.push('html-looks-like', 'preact-render-to-string');
|
|
148
|
-
this.dependencies.push('preact');
|
|
149
|
-
break;
|
|
150
|
-
case 'react':
|
|
151
|
-
this.devDependencies.push(
|
|
152
|
-
'react-test-renderer',
|
|
153
|
-
...(this.options.typescript ? ['@types/react', '@types/react-dom', '@types/react-test-renderer'] : [])
|
|
154
|
-
);
|
|
155
|
-
this.dependencies.push('react', 'react-dom');
|
|
156
|
-
break;
|
|
157
|
-
case 'svelte':
|
|
158
|
-
this.devDependencies.push('@testing-library/svelte');
|
|
159
|
-
this.dependencies.push('svelte');
|
|
160
|
-
break;
|
|
161
|
-
default:
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
await installDependencies(this.devDependencies.sort(), ['--save-dev'], this.log);
|
|
166
|
-
await installDependencies(this.dependencies.sort(), null, this.log);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
end() {
|
|
170
|
-
success(`Created ${hvy(this.options.name)} component`);
|
|
171
|
-
}
|
|
172
|
-
};
|