prepare-package 1.1.13 → 1.1.14

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.
Files changed (2) hide show
  1. package/dist/index.js +60 -8
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -42,10 +42,17 @@ module.exports = async function (options) {
42
42
  theirPackageJSON.scripts['prepare:watch'] = `nodemon -w ./src -e '*' --exec 'npm run prepare'`
43
43
 
44
44
  // Log the options
45
- console.log(chalk.blue(`[prepare-package]: Options purge=${options.purge}`));
46
- console.log(chalk.blue(`[prepare-package]: input=${theirPackageJSON.preparePackage.input}`));
47
- console.log(chalk.blue(`[prepare-package]: output=${theirPackageJSON.preparePackage.output}`));
48
- console.log(chalk.blue(`[prepare-package]: main=${theirPackageJSON.main}`));
45
+ // console.log(chalk.blue(`[prepare-package]: Options purge=${options.purge}`));
46
+ // console.log(chalk.blue(`[prepare-package]: input=${theirPackageJSON.preparePackage.input}`));
47
+ // console.log(chalk.blue(`[prepare-package]: output=${theirPackageJSON.preparePackage.output}`));
48
+ // console.log(chalk.blue(`[prepare-package]: main=${theirPackageJSON.main}`));
49
+ logger.log(`Starting...`);
50
+ logger.log({
51
+ purge: options.purge,
52
+ input: theirPackageJSON.preparePackage.input,
53
+ output: theirPackageJSON.preparePackage.output,
54
+ main: theirPackageJSON.main,
55
+ });
49
56
 
50
57
  // Set the paths relative to the cwd
51
58
  const mainPath = path.resolve(options.cwd, theirPackageJSON.main);
@@ -103,11 +110,56 @@ module.exports = async function (options) {
103
110
  response: 'json',
104
111
  tries: 3,
105
112
  })
106
- .then(result => {
107
- console.log(chalk.green(`[prepare-package]: Purged ${theirPackageJSON.name}`));
113
+ .then((r) => {
114
+ // console.log(chalk.green(`[prepare-package]: Purged ${theirPackageJSON.name}`));
115
+ logger.log(chalk.green(`Purged ${theirPackageJSON.name}!`));
108
116
  })
109
- .catch(e => {
110
- console.log(chalk.red(`[prepare-package]: Failed to purge ${theirPackageJSON.name}`, e));
117
+ .catch((e) => {
118
+ // console.log(chalk.red(`[prepare-package]: Failed to purge ${theirPackageJSON.name}`, e));
119
+ logger.error(`Failed to purge ${theirPackageJSON.name}!`, e.stack);
111
120
  })
112
121
  }
113
122
 
123
+ // Setup logger
124
+ const logger = {};
125
+
126
+ // Loop through log, error, warn, and info and make methods that log to console with the name and time [xx:xx:xx] name: message
127
+ ['log', 'error', 'warn', 'info'].forEach((method) => {
128
+ logger[method] = function () {
129
+ // Get time
130
+ const time = new Date().toLocaleTimeString('en-US', {
131
+ hour12: false,
132
+ hour: '2-digit',
133
+ minute: '2-digit',
134
+ second: '2-digit'
135
+ });
136
+
137
+ // Determine color based on method
138
+ let color;
139
+ switch (method) {
140
+ case 'warn':
141
+ color = chalk.yellow;
142
+ break;
143
+ case 'error':
144
+ color = chalk.red;
145
+ break;
146
+ default:
147
+ color = (text) => text; // No color
148
+ }
149
+
150
+ // Convert arguments to array and prepend time and name
151
+ const args = [`[${chalk.magenta(time)}] '${chalk.cyan('prepare-package')}':`, ...Array.from(arguments).map(arg => {
152
+ return typeof arg === 'string'
153
+ ? color(arg)
154
+ : (
155
+ arg instanceof Error
156
+ ? color(arg.stack)
157
+ : arg
158
+ );
159
+ })];
160
+
161
+ // Log
162
+ console[method].apply(console, args);
163
+ };
164
+ });
165
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prepare-package",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "description": "Prepare a Node.js package before being published",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "chalk": "^4.1.2",
39
39
  "fs-jetpack": "^4.3.1",
40
- "wonderful-fetch": "^1.1.11"
40
+ "wonderful-fetch": "^1.3.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "mocha": "^8.4.0"