bundle-stats 4.0.0-alpha.7 → 4.0.0-rc.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/bin/run.js DELETED
@@ -1,161 +0,0 @@
1
- /* eslint-disable no-console */
2
- const path = require('path');
3
- const { readJSON, outputFile } = require('fs-extra');
4
- const Listr = require('listr');
5
- const { get } = require('lodash');
6
- const boxen = require('boxen');
7
-
8
- require('@bundle-stats/utils/lib/polyfills');
9
- const {
10
- DELTA_TYPE_HIGH_NEGATIVE,
11
- DELTA_TYPE_NEGATIVE,
12
- DELTA_TYPE_LOW_NEGATIVE,
13
- DELTA_TYPE_NO_CHANGE,
14
- DELTA_TYPE_LOW_POSITIVE,
15
- DELTA_TYPE_POSITIVE,
16
- DELTA_TYPE_HIGH_POSITIVE,
17
- createJobs,
18
- createReport,
19
- } = require('@bundle-stats/utils');
20
- const { filter, validate } = require('@bundle-stats/utils/lib/webpack');
21
- const {
22
- TEXT,
23
- createArtifacts,
24
- getBaselineStatsFilepath,
25
- getReportInfo,
26
- readBaseline,
27
- writeBaseline,
28
- } = require('@bundle-stats/cli-utils');
29
- const LOCALES = require('../locales.json');
30
-
31
- const REPORT_INFO_COLORS = {
32
- [DELTA_TYPE_HIGH_NEGATIVE]: 'red',
33
- [DELTA_TYPE_NEGATIVE]: 'red',
34
- [DELTA_TYPE_LOW_NEGATIVE]: 'yellow',
35
- [DELTA_TYPE_NO_CHANGE]: 'gray',
36
- [DELTA_TYPE_LOW_POSITIVE]: 'green',
37
- [DELTA_TYPE_POSITIVE]: 'green',
38
- [DELTA_TYPE_HIGH_POSITIVE]: 'green',
39
- };
40
-
41
- const getReportInfoBorderColor = (reportInfo) => {
42
- const { deltaType } = reportInfo.info;
43
- return REPORT_INFO_COLORS[deltaType];
44
- };
45
-
46
- module.exports = ({ baseline, compare, html, json, outDir, artifactFilepaths }) => {
47
- const tasks = new Listr([
48
- {
49
- title: 'Read Webpack stats files',
50
- task: async (ctx) => {
51
- const sources = await Promise.all(artifactFilepaths.map((filepath) => readJSON(filepath)));
52
-
53
- sources.forEach((source, index) => {
54
- const invalid = validate(source);
55
-
56
- if (invalid) {
57
- throw new Error(
58
- `${invalid}\n${LOCALES.WEBPACK_CONFIGURATION_URL}\nFilepath: ${artifactFilepaths[index]}`,
59
- );
60
- }
61
- });
62
-
63
- ctx.sources = sources.map((source) => ({ webpack: filter(source) }));
64
- },
65
- },
66
- {
67
- title: 'Read baseline data',
68
- task: async (ctx, task) => {
69
- const baselineFilepath = path.relative(process.cwd(), getBaselineStatsFilepath());
70
- // eslint-disable-next-line no-param-reassign
71
- task.title = `${task.title} (${baselineFilepath})`;
72
-
73
- ctx.sources = ctx.sources.concat([{ webpack: filter(ctx.baselineStats) }]);
74
- },
75
- skip: async (ctx) => {
76
- if (!compare) {
77
- return TEXT.CLI_NO_COMPARE_MODE;
78
- }
79
-
80
- if (artifactFilepaths.length !== 1) {
81
- return TEXT.CLI_MULTIPLE_STATS;
82
- }
83
-
84
- let baselineStats = {};
85
-
86
- try {
87
- baselineStats = await readBaseline();
88
- ctx.baselineStats = baselineStats;
89
- } catch (err) {
90
- return TEXT.CLI_BASELINE_MISSING_WARN;
91
- }
92
-
93
- return false;
94
- },
95
- },
96
- {
97
- title: 'Write baseline data',
98
- task: (ctx, task) => {
99
- const stats = get(ctx, 'sources[0]webpack');
100
- const filteredWebpackStats = filter(stats);
101
- const baselineFilepath = path.relative(process.cwd(), getBaselineStatsFilepath());
102
-
103
- return writeBaseline(filteredWebpackStats).then(() => {
104
- // eslint-disable-next-line no-param-reassign
105
- task.title = `${task.title} (${baselineFilepath})`;
106
- });
107
- },
108
- skip: () => !baseline && TEXT.CLI_NO_BASELINE,
109
- },
110
- {
111
- title: 'Process data',
112
- task: (ctx) => {
113
- ctx.jobs = createJobs(ctx.sources);
114
- ctx.report = createReport(ctx.jobs);
115
- },
116
- },
117
- {
118
- title: 'Generate reports',
119
- task: async (ctx) => {
120
- ctx.artifacts = await createArtifacts(ctx.jobs, ctx.report, { html, json });
121
- },
122
- },
123
- {
124
- title: 'Save reports',
125
- task: (ctx) =>
126
- new Listr(
127
- Object.values(ctx.artifacts).map(({ filename, output }) => ({
128
- title: filename,
129
- task: async () => {
130
- const filepath = path.join(outDir, filename);
131
- await outputFile(filepath, output);
132
-
133
- ctx.output = [...(ctx.output ? ctx.output : []), filepath];
134
- },
135
- })),
136
- { concurrent: true },
137
- ),
138
- },
139
- ]);
140
-
141
- tasks
142
- .run()
143
- .then(({ output, report }) => {
144
- const reportInfo = getReportInfo(report);
145
-
146
- if (reportInfo) {
147
- const infoBox = boxen(reportInfo.text, {
148
- padding: 1,
149
- borderColor: getReportInfoBorderColor(reportInfo),
150
- });
151
-
152
- console.log(`\n${infoBox}`);
153
- }
154
-
155
- console.log('\nArtifacts:');
156
- output.map((reportPath) => console.log(`- ${reportPath}`));
157
- })
158
- .catch((err) => {
159
- console.error(err.message);
160
- });
161
- };
package/locales.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "WEBPACK_CONFIGURATION_URL": "https://github.com/relative-ci/bundle-stats/tree/master/packages/cli#webpack-configuration"
3
- }