@abcnews/aunty 14.0.1 → 14.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abcnews/aunty",
3
- "version": "14.0.1",
3
+ "version": "14.0.2",
4
4
  "description": "A toolkit for working with ABC News projects",
5
5
  "repository": "abcnews/aunty",
6
6
  "license": "MIT",
@@ -12,7 +12,8 @@
12
12
  ],
13
13
  "scripts": {
14
14
  "postinstall": "node scripts/postinstall.js",
15
- "release": "release-it"
15
+ "release": "release-it",
16
+ "test": "jest test/test.js"
16
17
  },
17
18
  "files": [
18
19
  "assets",
@@ -94,6 +95,7 @@
94
95
  "babel-eslint": "^10.1.0",
95
96
  "eslint": "^7.7.0",
96
97
  "eslint-config-prettier": "^8.2.0",
97
- "release-it": "^15.1.4"
98
+ "release-it": "^15.1.4",
99
+ "yeoman-automation-adapter": "^2.0.0"
98
100
  }
99
101
  }
@@ -19,77 +19,82 @@ const { command } = require('../');
19
19
  const cleanCommand = require('../clean');
20
20
  const { MESSAGES, OPTIONS } = require('./constants');
21
21
 
22
- module.exports = command(
23
- {
24
- name: 'build',
25
- nodeEnv: 'production',
26
- options: OPTIONS,
27
- usage: MESSAGES.usage
28
- },
29
- async argv => {
30
- const { root } = getProjectConfig();
31
- const webpackConfig = getWebpackConfig();
32
- let deployConfig;
33
-
34
- if (!argv.local) {
35
- deployConfig = getDeployConfig({ id: argv.id });
36
- webpackConfig.forEach(config => {
37
- config.output.publicPath = deployConfig.targets[0].publicPath;
38
- });
39
- }
40
-
41
- if (argv.dry) {
42
- return dry(
43
- combine(
44
- {
45
- 'Webpack config': webpackConfig
46
- },
47
- deployConfig
48
- ? {
49
- 'Deploy config': deployConfig
50
- }
51
- : {}
52
- )
53
- );
54
- }
22
+ const build = async argv => {
23
+ const { root } = getProjectConfig();
24
+ const webpackConfig = getWebpackConfig();
25
+ let deployConfig;
55
26
 
56
- throws(await cleanCommand(['--quiet']));
27
+ if (!argv.local) {
28
+ deployConfig = getDeployConfig({ id: argv.id });
29
+ webpackConfig.forEach(config => {
30
+ config.output.publicPath = deployConfig.targets[0].publicPath;
31
+ });
32
+ }
57
33
 
58
- info(
59
- MESSAGES.build({
60
- id: deployConfig ? deployConfig.id : null,
61
- publicPaths: deployConfig ? deployConfig.targets.map(x => x.publicPath) : [webpackConfig[0].output.publicPath]
62
- })
34
+ if (argv.dry) {
35
+ return dry(
36
+ combine(
37
+ {
38
+ 'Webpack config': webpackConfig
39
+ },
40
+ deployConfig
41
+ ? {
42
+ 'Deploy config': deployConfig
43
+ }
44
+ : {}
45
+ )
63
46
  );
47
+ }
64
48
 
65
- let spinner = spin('Building');
66
- const startTime = Date.now();
67
- const compiler = webpack(webpackConfig);
68
- const stats = unpack(await packs(pify(compiler.run.bind(compiler)))());
49
+ throws(await cleanCommand(['--quiet']));
69
50
 
70
- if (stats.hasErrors()) {
71
- const errors = stats.toJson({}, true).errors;
51
+ info(
52
+ MESSAGES.build({
53
+ id: deployConfig ? deployConfig.id : null,
54
+ publicPaths: deployConfig ? deployConfig.targets.map(x => x.publicPath) : [webpackConfig[0].output.publicPath]
55
+ })
56
+ );
72
57
 
73
- spinner.fail();
58
+ let spinner = spin('Building');
59
+ const startTime = Date.now();
60
+ const compiler = webpack(webpackConfig);
61
+ const stats = unpack(await packs(pify(compiler.run.bind(compiler)))());
74
62
 
75
- if (errors.length > 1) {
76
- throw MESSAGES.multipleErrors(errors.map(error => error.message));
77
- }
63
+ if (stats.hasErrors()) {
64
+ const errors = stats.toJson({}, true).errors;
78
65
 
79
- throw errors[0];
80
- }
66
+ spinner.fail();
81
67
 
82
- if (stats.hasWarnings()) {
83
- spinner.warn();
84
- stats.toJson({}, true).warnings.forEach(warning => warn(warning.message));
85
- } else {
86
- spinner.succeed(`Built in ${((Date.now() - startTime) / 1000).toFixed(2)}s`);
68
+ if (errors.length > 1) {
69
+ throw MESSAGES.multipleErrors(errors.map(error => error.message));
87
70
  }
88
71
 
89
- if (deployConfig) {
90
- spinner = spin('Creating deploy configuration');
91
- writeJsonFile.sync(join(root, OUTPUT_DIRECTORY_NAME, DEPLOY_FILE_NAME), deployConfig);
92
- spinner.succeed('Created deploy configuration');
93
- }
72
+ throw errors[0];
94
73
  }
74
+
75
+ if (stats.hasWarnings()) {
76
+ spinner.warn();
77
+ stats.toJson({}, true).warnings.forEach(warning => warn(warning.message));
78
+ } else {
79
+ spinner.succeed(`Built in ${((Date.now() - startTime) / 1000).toFixed(2)}s`);
80
+ }
81
+
82
+ if (deployConfig) {
83
+ spinner = spin('Creating deploy configuration');
84
+ writeJsonFile.sync(join(root, OUTPUT_DIRECTORY_NAME, DEPLOY_FILE_NAME), deployConfig);
85
+ spinner.succeed('Created deploy configuration');
86
+ }
87
+ };
88
+
89
+ module.exports = command(
90
+ {
91
+ name: 'build',
92
+ nodeEnv: 'production',
93
+ options: OPTIONS,
94
+ usage: MESSAGES.usage
95
+ },
96
+ build
95
97
  );
98
+
99
+ // Expose this for the tests
100
+ module.exports._testBuild = build;
@@ -1,7 +1,6 @@
1
1
  // Ours
2
2
  const { createLogo } = require('../utils/branding');
3
3
  const { cmd, dim, hvy, opt, req, sec } = require('../utils/color');
4
- const { setOfValues } = require('../utils/structures');
5
4
 
6
5
  const COMMAND_ALIASES = (module.exports.COMMAND_ALIASES = {
7
6
  b: 'build',
@@ -14,7 +13,7 @@ const COMMAND_ALIASES = (module.exports.COMMAND_ALIASES = {
14
13
  t: 'test'
15
14
  });
16
15
 
17
- module.exports.COMMANDS = setOfValues(COMMAND_ALIASES);
16
+ module.exports.COMMANDS = new Set(Object.values(COMMAND_ALIASES));
18
17
 
19
18
  module.exports.DEFAULTS = {
20
19
  name: '__command__',
@@ -1,6 +1,5 @@
1
1
  // Ours
2
2
  const { cmd, hvy, opt, req, sec } = require('../../utils/color');
3
- const { setOfValues } = require('../../utils/structures');
4
3
 
5
4
  module.exports.OPTIONS = {
6
5
  boolean: ['announce'],
@@ -14,7 +13,7 @@ const GENERATOR_ALIASES = (module.exports.GENERATOR_ALIASES = {
14
13
  p: 'project'
15
14
  });
16
15
 
17
- module.exports.GENERATORS = setOfValues(GENERATOR_ALIASES);
16
+ module.exports.GENERATORS = new Set(Object.values(GENERATOR_ALIASES));
18
17
 
19
18
  module.exports.MESSAGES = {
20
19
  generatorDoesNotExist: name => `The generator '${name}' does not exist.`,
@@ -10,55 +10,63 @@ const { log } = require('../../utils/logging');
10
10
  const { command } = require('../');
11
11
  const { GENERATOR_ALIASES, GENERATORS, MESSAGES, OPTIONS } = require('./constants');
12
12
 
13
- module.exports = command(
14
- {
15
- name: 'generate',
16
- hasSubcommands: true,
17
- options: OPTIONS
18
- },
19
- async argv => {
20
- if (argv.dry) {
21
- throw MESSAGES.noDryRuns;
22
- }
23
-
24
- const generatorName = GENERATOR_ALIASES[argv._[0]] || argv._[0];
13
+ const generate = async argv => {
14
+ if (argv.dry) {
15
+ throw MESSAGES.noDryRuns;
16
+ }
25
17
 
26
- // If we didn't supply a known generator name, blow up, unless we wanted
27
- // the generate command's usage message (in which case, print it, then exit).
18
+ const generatorName = GENERATOR_ALIASES[argv._[0]] || argv._[0];
28
19
 
29
- if (!GENERATORS.has(generatorName)) {
30
- if (!generatorName || generatorName.indexOf('-') === 0 || argv.help) {
31
- return log(MESSAGES.usage);
32
- }
20
+ // If we didn't supply a known generator name, blow up, unless we wanted
21
+ // the generate command's usage message (in which case, print it, then exit).
33
22
 
34
- throw MESSAGES.generatorDoesNotExist(generatorName);
23
+ if (!GENERATORS.has(generatorName)) {
24
+ if (!generatorName || generatorName.indexOf('-') === 0 || argv.help) {
25
+ return log(MESSAGES.usage);
35
26
  }
36
27
 
37
- log(createCommandLogo(`generate ${generatorName}`));
28
+ throw MESSAGES.generatorDoesNotExist(generatorName);
29
+ }
38
30
 
39
- const env = yeoman.createEnv();
31
+ log(createCommandLogo(`generate ${generatorName}`));
40
32
 
41
- // Register the generator
33
+ // If we're in a test environment, insert the auto adapter with the provided answers
34
+ const env = global.auntyYeomanAnswers
35
+ ? yeoman.createEnv([], {}, new (require('yeoman-automation-adapter').AutoAdapter)(global.auntyYeomanAnswers, true))
36
+ : yeoman.createEnv();
42
37
 
43
- const generatorPath = require.resolve(`../../generators/${generatorName}`);
38
+ // Register the generator
44
39
 
45
- env.register(generatorPath, generatorName);
40
+ const generatorPath = require.resolve(`../../generators/${generatorName}`);
46
41
 
47
- // Run the generator, including known arguments
42
+ env.register(generatorPath, generatorName);
48
43
 
49
- const runArgs = [generatorName]
50
- .concat(argv['--'])
51
- .concat(argv.help ? ['--help'] : [])
52
- .join(' ');
44
+ // Run the generator, including known arguments
53
45
 
54
- const [err] = await pack(env.run(runArgs));
46
+ const runArgs = [generatorName]
47
+ .concat(argv['--'])
48
+ .concat(argv.help ? ['--help'] : [])
49
+ .join(' ');
55
50
 
56
- if (err) {
57
- throw err;
58
- }
51
+ const [err] = await pack(env.run(runArgs));
59
52
 
60
- if (argv.announce) {
61
- announce();
62
- }
53
+ if (err) {
54
+ throw err;
55
+ }
56
+
57
+ if (argv.announce) {
58
+ announce();
63
59
  }
60
+ };
61
+
62
+ module.exports = command(
63
+ {
64
+ name: 'generate',
65
+ hasSubcommands: true,
66
+ options: OPTIONS
67
+ },
68
+ generate
64
69
  );
70
+
71
+ // Expose this for the tests
72
+ module.exports._testGenerate = generate;
@@ -86,6 +86,16 @@ const findPort = async (port, max = port + 100, host = '0.0.0.0') => {
86
86
  // If the connection is refused, it's assumed nothing is listening and the port is available.
87
87
  if (e.code === 'ECONNREFUSED') {
88
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);
89
99
  } else {
90
100
  // Not sure what to do with other errors. Log the code & keep seeking a free port.
91
101
  next(`error code ${e.code}`);
@@ -26,7 +26,7 @@ if (module.hot) {
26
26
  module.hot.accept('./components/App', () => {
27
27
  try {
28
28
  renderApp();
29
- } catch (err) {
29
+ } catch (err<% if (isTS) { %>: any<% } %>) {
30
30
  import('./components/ErrorBox').then(({ default: ErrorBox }) => {
31
31
  if (appMountEl) {
32
32
  render(<ErrorBox error={err} />, appMountEl);
@@ -31,5 +31,3 @@ module.exports.combine = (...sources) => sources.reduce(combine, {});
31
31
  * @see combine
32
32
  */
33
33
  module.exports.merge = (...sources) => sources.reduce(combineDeep, {});
34
-
35
- module.exports.setOfValues = source => new Set(Object.keys(source).map(key => source[key]));