@abcnews/aunty 12.2.1 → 13.0.1

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": "12.2.1",
3
+ "version": "13.0.1",
4
4
  "description": "A toolkit for working with ABC News projects",
5
5
  "repository": "abcnews/aunty",
6
6
  "license": "MIT",
@@ -11,10 +11,12 @@
11
11
  "Joshua Byrd <byrd.joshua@abc.net.au>"
12
12
  ],
13
13
  "scripts": {
14
+ "postinstall": "node scripts/postinstall.js",
14
15
  "release": "release-it"
15
16
  },
16
17
  "files": [
17
18
  "assets",
19
+ "scripts",
18
20
  "src",
19
21
  "ts"
20
22
  ],
@@ -80,7 +82,7 @@
80
82
  "svelte-preprocess": "^4.1.1",
81
83
  "tcp-ping-sync": "^1.0.0",
82
84
  "typescript": "^4.0.2",
83
- "update-notifier": "^5.1.0",
85
+ "update-notifier": "^6.0.2",
84
86
  "url-loader": "^4.1.1",
85
87
  "webpack": "^5.33.2",
86
88
  "webpack-bundle-analyzer": "^4.5.0",
@@ -95,6 +97,6 @@
95
97
  "devDependencies": {
96
98
  "eslint": "^7.7.0",
97
99
  "eslint-config-prettier": "^8.2.0",
98
- "release-it": "^14.6.1"
100
+ "release-it": "^15.1.4"
99
101
  }
100
102
  }
@@ -0,0 +1,44 @@
1
+ /*
2
+ Aunty v13 changes how build artefacts are created. When building a project,
3
+ pre-v13, a .build folder and .deploy files were created inside your project
4
+ directory. In v13, this was changed to a single .aunty directory, which
5
+ contains a build filder and deploy.json file.
6
+
7
+ This script runs after aunty is installed inside a project directory, and
8
+ if the project was upgraded from a pre-v13 aunty, it will delete any old
9
+ build artefacts, and update the .gitignore file to make sure the .aunty
10
+ directory isn't committed, and remove the .build & .deploy references.
11
+ */
12
+
13
+ const { existsSync, readFileSync, rmSync, rmdirSync, writeFileSync } = require('fs');
14
+ const { join } = require('path');
15
+
16
+ const INSTALLATION_DIRECTORY = process.env.INIT_CWD || '.';
17
+
18
+ const PRE_AUNTY_13_GITIGNORE_PATTERN = /\/\.build\n\/\.deploy/;
19
+ const POST_AUNTY_13_GITIGNORE_REPLACEMENT = `/.aunty`;
20
+
21
+ const PRE_AUNTY_13_BUILD_DIR_PATH = join(INSTALLATION_DIRECTORY, '.build');
22
+ const PRE_AUNTY_13_DEPLOY_CONFIG_FILE_PATH = join(INSTALLATION_DIRECTORY, '.deploy');
23
+ const GITIGNORE_PATH = join(INSTALLATION_DIRECTORY, '.gitignore');
24
+
25
+ if (existsSync(PRE_AUNTY_13_BUILD_DIR_PATH)) {
26
+ rmdirSync(PRE_AUNTY_13_BUILD_DIR_PATH, { recursive: true });
27
+ }
28
+
29
+ if (existsSync(PRE_AUNTY_13_DEPLOY_CONFIG_FILE_PATH)) {
30
+ rmSync(PRE_AUNTY_13_DEPLOY_CONFIG_FILE_PATH);
31
+ }
32
+
33
+ if (existsSync(GITIGNORE_PATH)) {
34
+ const fileContents = readFileSync(GITIGNORE_PATH, 'utf8');
35
+
36
+ if (PRE_AUNTY_13_GITIGNORE_PATTERN.test(fileContents)) {
37
+ const updatedFileContents = fileContents.replace(
38
+ PRE_AUNTY_13_GITIGNORE_PATTERN,
39
+ POST_AUNTY_13_GITIGNORE_REPLACEMENT
40
+ );
41
+
42
+ writeFileSync(GITIGNORE_PATH, updatedFileContents);
43
+ }
44
+ }
@@ -11,7 +11,7 @@ const writeJsonFile = importLazy('write-json-file');
11
11
  const { getDeployConfig } = require('../../config/deploy');
12
12
  const { getProjectConfig } = require('../../config/project');
13
13
  const { getWebpackConfig } = require('../../config/webpack');
14
- const { DEPLOY_FILE_NAME } = require('../../constants');
14
+ const { DEPLOY_FILE_NAME, OUTPUT_DIRECTORY_NAME } = require('../../constants');
15
15
  const { packs, throws, unpack } = require('../../utils/async');
16
16
  const { dry, info, spin, warn } = require('../../utils/logging');
17
17
  const { combine } = require('../../utils/structures');
@@ -71,7 +71,7 @@ module.exports = command(
71
71
  const errors = stats.toJson({}, true).errors;
72
72
 
73
73
  spinner.fail();
74
-
74
+
75
75
  if (errors.length > 1) {
76
76
  throw MESSAGES.multipleErrors(errors.map(error => error.message));
77
77
  }
@@ -88,7 +88,7 @@ module.exports = command(
88
88
 
89
89
  if (deployConfig) {
90
90
  spinner = spin('Creating deploy configuration');
91
- writeJsonFile.sync(join(root, DEPLOY_FILE_NAME), deployConfig);
91
+ writeJsonFile.sync(join(root, OUTPUT_DIRECTORY_NAME, DEPLOY_FILE_NAME), deployConfig);
92
92
  spinner.succeed('Created deploy configuration');
93
93
  }
94
94
  }
@@ -3,9 +3,8 @@ const importLazy = require('import-lazy')(require);
3
3
  const del = importLazy('del');
4
4
 
5
5
  // Ours
6
- const { getBuildConfig } = require('../../config/build');
7
6
  const { getProjectConfig } = require('../../config/project');
8
- const { DEPLOY_FILE_NAME } = require('../../constants');
7
+ const { OUTPUT_DIRECTORY_NAME } = require('../../constants');
9
8
  const { hvy } = require('../../utils/color');
10
9
  const { dry, info, spin } = require('../../utils/logging');
11
10
  const { inlineList } = require('../../utils/text');
@@ -19,8 +18,7 @@ module.exports = command(
19
18
  },
20
19
  async argv => {
21
20
  const { root } = getProjectConfig();
22
- const { to } = getBuildConfig();
23
- const globs = [to, DEPLOY_FILE_NAME];
21
+ const globs = [OUTPUT_DIRECTORY_NAME];
24
22
 
25
23
  if (argv.dry) {
26
24
  return dry({
@@ -10,7 +10,7 @@ const loadJsonFile = importLazy('load-json-file');
10
10
  const { command } = require('../');
11
11
  const { addProfileProperties } = require('../../config/deploy');
12
12
  const { getProjectConfig } = require('../../config/project');
13
- const { DEPLOY_FILE_NAME } = require('../../constants');
13
+ const { DEPLOY_FILE_NAME, OUTPUT_DIRECTORY_NAME } = require('../../constants');
14
14
  const { packs, throws, unpack } = require('../../utils/async');
15
15
  const { dry, info, spin, warn } = require('../../utils/logging');
16
16
  const { ftp, rsync } = require('../../utils/remote');
@@ -29,7 +29,7 @@ module.exports = command(
29
29
  // 1) Load the deploy configuration (created by the build process)
30
30
 
31
31
  try {
32
- deployConfig = loadJsonFile.sync(join(root, DEPLOY_FILE_NAME));
32
+ deployConfig = loadJsonFile.sync(join(root, OUTPUT_DIRECTORY_NAME, DEPLOY_FILE_NAME));
33
33
  } catch (err) {
34
34
  throw new Error(MESSAGES.noDeployConfigFile);
35
35
  }
package/src/cli/index.js CHANGED
@@ -4,7 +4,6 @@ const { resolve } = require('path');
4
4
  // External
5
5
  const importLazy = require('import-lazy')(require);
6
6
  const minimist = importLazy('minimist');
7
- const updateNotifier = importLazy('update-notifier');
8
7
 
9
8
  // Ours
10
9
  const pkg = require('../../package');
@@ -27,6 +26,8 @@ const {
27
26
  module.exports.cli = packs(async args => {
28
27
  const __DEBUG__stopTimer = timer('CLI');
29
28
 
29
+ const updateNotifier = (await import('update-notifier')).default;
30
+
30
31
  updateNotifier({ pkg, updateCheckInterval: 36e5 }).notify();
31
32
 
32
33
  // If we just want aunty's version number, print it, then exit
@@ -1,4 +1,5 @@
1
1
  // External
2
+ const importLazy = require('import-lazy')(require);
2
3
  const mem = require('mem');
3
4
  const semver = importLazy('semver');
4
5
 
@@ -1,8 +1,11 @@
1
+ // Native
2
+ const { join } = require('path');
3
+
1
4
  // External
2
5
  const mem = require('mem');
3
6
 
4
7
  // Ours
5
- const { BUILD_DIRECTORY_NAME } = require('../constants');
8
+ const { BUILD_DIRECTORY_NAME, OUTPUT_DIRECTORY_NAME } = require('../constants');
6
9
  const { combine } = require('../utils/structures');
7
10
  const { getProjectConfig } = require('./project');
8
11
 
@@ -22,7 +25,7 @@ module.exports.getBuildConfig = mem(() => {
22
25
  {
23
26
  entry: DEFAULT_ENTRY_FILE_NAME,
24
27
  from: DEFAULT_SOURCE_DIRECTORY_NAME,
25
- to: BUILD_DIRECTORY_NAME,
28
+ to: join(OUTPUT_DIRECTORY_NAME, BUILD_DIRECTORY_NAME),
26
29
  staticDir: DEFAULT_STATIC_DIRECTORY_NAME,
27
30
  addModernJS: false,
28
31
  includedDependencies: [],
@@ -23,32 +23,7 @@ const DEFAULT_HOST = (module.exports.DEFAULT_HOST = probe(`nucwed${INTERNAL_SUFF
23
23
  : 'localhost');
24
24
  const DEFAULT_PORT = 8000;
25
25
 
26
- const serveConfigPromise = getServeConfigPromise();
27
-
28
- module.exports.getServeConfig = () => serveConfigPromise;
29
-
30
- async function getServeConfigPromise() {
31
- const { serve } = getProjectConfig();
32
-
33
- const config = combine(
34
- {
35
- hasBundleAnalysis: false,
36
- host: DEFAULT_HOST,
37
- hot: process.env.NODE_ENV === 'development',
38
- https: true,
39
- port: DEFAULT_PORT
40
- },
41
- serve,
42
- addEnvironmentVariables,
43
- addUserSSLConfig
44
- );
45
- const port = await findPort(config.port, config.port + 100, config.host);
46
- config.port = port;
47
-
48
- return config;
49
- }
50
-
51
- function addEnvironmentVariables(config) {
26
+ const addEnvironmentVariables = config => {
52
27
  if (process.env.AUNTY_HOST) {
53
28
  config.host = process.env.AUNTY_HOST;
54
29
  }
@@ -58,7 +33,7 @@ function addEnvironmentVariables(config) {
58
33
  }
59
34
 
60
35
  return config;
61
- }
36
+ };
62
37
 
63
38
  const getSSLPath = (module.exports.getSSLPath = (host, name) => join(HOME_DIR, SSL_DIR, host, name || '.'));
64
39
 
@@ -66,7 +41,7 @@ const getSSLPath = (module.exports.getSSLPath = (host, name) => join(HOME_DIR, S
66
41
  Set config.https to cert & key generated with `aunty sign-cert` (if they both exist)
67
42
  We expect them to be in: ~/.aunty/ssl/<host>/server.{cert|key}
68
43
  */
69
- function addUserSSLConfig(config) {
44
+ const addUserSSLConfig = config => {
70
45
  if (config.https === true) {
71
46
  try {
72
47
  config.https = {
@@ -77,9 +52,9 @@ function addUserSSLConfig(config) {
77
52
  }
78
53
 
79
54
  return config;
80
- }
55
+ };
81
56
 
82
- async function findPort(port, max = port + 100, host = '0.0.0.0') {
57
+ const findPort = async (port, max = port + 100, host = '0.0.0.0') => {
83
58
  return new Promise((resolve, reject) => {
84
59
  const socket = new Socket();
85
60
 
@@ -115,4 +90,41 @@ async function findPort(port, max = port + 100, host = '0.0.0.0') {
115
90
 
116
91
  socket.connect(port, host);
117
92
  });
118
- }
93
+ };
94
+
95
+ const _getServeConfig = async () => {
96
+ const { serve } = getProjectConfig();
97
+
98
+ const config = combine(
99
+ {
100
+ hasBundleAnalysis: false,
101
+ host: DEFAULT_HOST,
102
+ hot: process.env.NODE_ENV === 'development',
103
+ https: true,
104
+ port: DEFAULT_PORT
105
+ },
106
+ serve,
107
+ addEnvironmentVariables,
108
+ addUserSSLConfig
109
+ );
110
+ const port = await findPort(config.port, config.port + 100, config.host);
111
+ config.port = port;
112
+
113
+ return config;
114
+ };
115
+
116
+ let _serveConfigPromiseSingleton;
117
+
118
+ // getServeConfig is called twice during server startup, because the `serve`
119
+ // command calls it directly, then indirectly, via getWebpackDevServerConfig.
120
+ // Because it won't change during a single `serve` command, and because we
121
+ // don't want to waste time doing port lookups with `findPort` multiple times
122
+ // we just cache the promise created on the first run, and return that later.
123
+
124
+ module.exports.getServeConfig = async () => {
125
+ if (!_serveConfigPromiseSingleton) {
126
+ _serveConfigPromiseSingleton = _getServeConfig();
127
+ }
128
+
129
+ return _serveConfigPromiseSingleton;
130
+ };
package/src/constants.js CHANGED
@@ -1,5 +1,6 @@
1
1
  module.exports = {
2
- BUILD_DIRECTORY_NAME: '.build',
3
- DEPLOY_FILE_NAME: '.deploy',
2
+ OUTPUT_DIRECTORY_NAME: '.aunty',
3
+ BUILD_DIRECTORY_NAME: 'build',
4
+ DEPLOY_FILE_NAME: 'deploy.json',
4
5
  PROJECT_CONFIG_FILE_NAME: 'aunty.config.js'
5
6
  };
@@ -8,7 +8,7 @@ const requireg = require('requireg');
8
8
  const Generator = require('yeoman-generator');
9
9
 
10
10
  // Ours
11
- const { BUILD_DIRECTORY_NAME, DEPLOY_FILE_NAME } = require('../../constants');
11
+ const { OUTPUT_DIRECTORY_NAME } = require('../../constants');
12
12
  const { cmd, hvy, opt, sec } = require('../../utils/color');
13
13
  const { success } = require('../../utils/logging');
14
14
  const { installDependencies } = require('../../utils/npm');
@@ -114,8 +114,7 @@ Shorthand examples (assuming xyz is your project name):
114
114
 
115
115
  writing() {
116
116
  const context = {
117
- BUILD_DIRECTORY_NAME,
118
- DEPLOY_FILE_NAME,
117
+ OUTPUT_DIRECTORY_NAME,
119
118
  projectName: this.options.projectName,
120
119
  projectNameSlug: this.options.projectNameSlug,
121
120
  projectNameFlat: this.options.projectNameFlat,
@@ -2,8 +2,7 @@
2
2
  /node_modules
3
3
 
4
4
  # output
5
- /<%= BUILD_DIRECTORY_NAME %>
6
- /<%= DEPLOY_FILE_NAME %>
5
+ /<%= OUTPUT_DIRECTORY_NAME %>
7
6
 
8
7
  # misc
9
8
  .DS_Store