@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/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
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { select<% if (isTS) { %>, Selection<% } %> } from 'd3-selection';
|
|
2
|
-
import styles from './styles.scss';
|
|
3
|
-
|
|
4
|
-
export default class <%= className %> {<% if (isTS) { %>
|
|
5
|
-
el: Element;
|
|
6
|
-
svg: Selection<SVGSVGElement, unknown, null, undefined>;
|
|
7
|
-
g: Selection<SVGGElement, unknown, null, undefined>;
|
|
8
|
-
rect: Selection<SVGRectElement, any, any, any>;
|
|
9
|
-
<% } %>
|
|
10
|
-
constructor() {
|
|
11
|
-
this.el = document.createElement('div');
|
|
12
|
-
this.el.className = styles.root;
|
|
13
|
-
|
|
14
|
-
this.svg = select(this.el)
|
|
15
|
-
.append('svg')
|
|
16
|
-
.attr('width', 400)
|
|
17
|
-
.attr('height', 300);
|
|
18
|
-
|
|
19
|
-
this.g = this.svg.append('g').attr('fill', 'black');
|
|
20
|
-
|
|
21
|
-
this.rect = this.g
|
|
22
|
-
.append('rect')
|
|
23
|
-
.attr('x', 0)
|
|
24
|
-
.attr('y', 0)
|
|
25
|
-
.attr('rx', 3)
|
|
26
|
-
.attr('ry', 3)
|
|
27
|
-
.attr('width', '100%')
|
|
28
|
-
.attr('height', '100%');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import styles from './styles.scss';
|
|
2
|
-
|
|
3
|
-
export default class <%= className %> {<% if (isTS) { %>
|
|
4
|
-
el: Element;
|
|
5
|
-
<% } %>
|
|
6
|
-
constructor() {
|
|
7
|
-
this.el = document.createElement('div');
|
|
8
|
-
this.el.className = styles.root;
|
|
9
|
-
this.el.innerHTML = `Find me in <strong>src/components/<%= className %></strong>`;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { h } from 'preact';
|
|
2
|
-
import render from 'preact-render-to-string';
|
|
3
|
-
import htmlLooksLike from 'html-looks-like';
|
|
4
|
-
|
|
5
|
-
import <%= className %> from '.';
|
|
6
|
-
|
|
7
|
-
describe('<%= className %>', () => {
|
|
8
|
-
test('It renders', () => {
|
|
9
|
-
const actual = render(<<%= className %> />);
|
|
10
|
-
const expected = `
|
|
11
|
-
<div></div>
|
|
12
|
-
`;
|
|
13
|
-
|
|
14
|
-
htmlLooksLike(actual, expected);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { select<% if (isTS) { %>, Selection<% } %> } from 'd3-selection';
|
|
2
|
-
import { h<% if (isTS) { %>, FunctionalComponent<% } %> } from 'preact';
|
|
3
|
-
import { useEffect, useRef } from 'preact/hooks';
|
|
4
|
-
import styles from './styles.scss';
|
|
5
|
-
<% if (isTS) { %>
|
|
6
|
-
type <%= className %>Props = {
|
|
7
|
-
color?: string;
|
|
8
|
-
}
|
|
9
|
-
<% } %>
|
|
10
|
-
const <%= className %><% if (isTS) { %>: FunctionalComponent<<%= className %>Props><% } %> = ({ color = 'black' }) => {
|
|
11
|
-
const root = useRef<% if (isTS) { %><Element | null><% } %>(null);
|
|
12
|
-
const svg = useRef<% if (isTS) { %><Selection<SVGSVGElement, unknown, null, undefined> | null><% } %>(null);
|
|
13
|
-
const g = useRef<% if (isTS) { %><Selection<SVGGElement, unknown, null, undefined> | null><% } %>(null);
|
|
14
|
-
const rect = useRef<% if (isTS) { %><Selection<SVGRectElement, unknown, null, undefined> | null><% } %>(null);
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
svg.current = select(root.current)
|
|
18
|
-
.append('svg')
|
|
19
|
-
.attr('width', 400)
|
|
20
|
-
.attr('height', 300);
|
|
21
|
-
|
|
22
|
-
g.current = svg.current.append('g');
|
|
23
|
-
|
|
24
|
-
rect.current = g.current
|
|
25
|
-
.append('rect')
|
|
26
|
-
.attr('x', 0)
|
|
27
|
-
.attr('y', 0)
|
|
28
|
-
.attr('rx', 3)
|
|
29
|
-
.attr('ry', 3)
|
|
30
|
-
.attr('width', '100%')
|
|
31
|
-
.attr('height', '100%');
|
|
32
|
-
}, []);
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
if (!g.current) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
g.current.attr('fill', color);
|
|
40
|
-
}, [color]);
|
|
41
|
-
|
|
42
|
-
return <div ref={root} className={styles.root}></div>;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default <%= className %>;
|