-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.app-lint.js
144 lines (121 loc) · 5.03 KB
/
script.app-lint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const fs = require('node:fs');
const semver = require('semver');
const childProcess = require('node:child_process');
const weblog = require('webpack-log');
const logger = weblog({ name: 'app-lint' });
const APP = require('./app.config');
const PACKAGE = require('./package.json');
const lintWarns = [];
const lintErrors = [];
if (process.platform === 'win32') {
childProcess.execSync('chcp 65001');
}
if (PACKAGE.name === 'Intecmedia.Webpack') {
lintErrors.push('`Intecmedia.Webpack` not allowed in production. Please rename `name` in `package.json`.');
}
const NAME_PATTERN = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/i;
if (!NAME_PATTERN.test(PACKAGE.name)) {
lintErrors.push(
`Expected to match pattern "${NAME_PATTERN.toString()}". Please rename \`name\` in \`package.json\`.`
);
}
if (APP.TITLE === '$APP.TITLE$') {
lintErrors.push('`$APP.TITLE$` not allowed in production. Please rename `TITLE` in `app.config.js`.');
}
if (APP.TITLE.trim() === '') {
lintErrors.push('Empty `TITLE` not allowed in production. Please fill `TITLE` in `app.config.js`.');
}
if (APP.SHORT_NAME === '$APP.SHORT_NAME$') {
lintErrors.push('`$APP.SHORT_NAME$` not allowed in production. Please rename `SHORT_NAME` in `app.config.js`.');
}
if (APP.SHORT_NAME.trim() === '') {
lintErrors.push('Empty `SHORT_NAME` not allowed in production. Please fill `SHORT_NAME` in `app.config.js`.');
}
if (APP.DESCRIPTION === '$APP.DESCRIPTION$') {
lintErrors.push('`$APP.DESCRIPTION$` not allowed in production. Please rename `DESCRIPTION in `app.config.js`.');
}
if (APP.DESCRIPTION.trim() === '') {
lintErrors.push('Empty `DESCRIPTION` not allowed in production. Please fill `DESCRIPTION` in `app.config.js`.');
}
if (APP.TITLE.length && (APP.TITLE === APP.SHORT_NAME || APP.TITLE === APP.DESCRIPTION)) {
lintErrors.push('`TITLE` is equal `SHORT_NAME` or `DESCRIPTION`. Please rename something.');
}
if (APP.SHORT_NAME.length && (APP.SHORT_NAME === APP.TITLE || APP.SHORT_NAME === APP.DESCRIPTION)) {
lintErrors.push('`SHORT_NAME` is equal `TITLE` or `DESCRIPTION`. Please rename something.');
}
if (APP.DESCRIPTION.length && (APP.DESCRIPTION === APP.TITLE || APP.DESCRIPTION === APP.SHORT_NAME)) {
lintErrors.push('`DESCRIPTION` is equal `TITLE` or `SHORT_NAME`. Please rename something.');
}
const npmVersion = JSON.parse(childProcess.execSync('npm version --json').toString() || '{}');
if (!semver.satisfies(npmVersion.npm, PACKAGE.engines.npm)) {
lintErrors.push(`Required \`npm@${PACKAGE.engines.npm}\` version (current is \`npm@${npmVersion.npm}\`).`);
}
if (!semver.satisfies(process.version, PACKAGE.engines.node)) {
lintErrors.push(`Required \`node@${PACKAGE.engines.node}\` version (current is \`node@${process.version}\`).`);
}
let fonttoolsVersion = null;
try {
[, fonttoolsVersion] = childProcess
.execSync('pip show fonttools')
.toString()
.match(/Version: (.+)/);
childProcess.execSync('pyftsubset --help');
} catch (fonttoolsError) {
logger.error(fonttoolsError);
fonttoolsVersion = null;
}
if (!fonttoolsVersion) {
lintErrors.push(
`Required python fonttools@${PACKAGE.engines['@pip/fonttools']} version. Please run \`pip install fonttools\`.`
);
} else if (!semver.satisfies(fonttoolsVersion, PACKAGE.engines['@pip/fonttools'])) {
lintErrors.push(
`Required python fonttools@${PACKAGE.engines['@pip/fonttools']} version (current is \`${fonttoolsVersion}\`).`
);
}
let bashVersion = null;
try {
bashVersion = childProcess.execSync('bash --version').toString();
} catch (bashError) {
logger.error(bashError);
bashVersion = null;
}
if (!bashVersion) {
if (process.platform === 'win32') {
lintErrors.push('Required bash. Please install: `Git Bash` or `MinGW` or `Cygwin`.');
} else {
lintErrors.push('Required bash.');
}
}
const yarnLock = fs.existsSync('./yarn.lock');
if (yarnLock) {
lintErrors.push(
[
'`yarn.lock` found.',
'Your project contains lock files generated by tools other than NPM.',
'It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files.',
'To clear this error, remove `yarn.lock`.',
].join('\n')
);
}
const pnpmLock = fs.existsSync('./pnpm-lock.yaml');
if (pnpmLock) {
lintErrors.push(
[
'`pnpm-lock.yaml` found.',
'Your project contains lock files generated by tools other than NPM.',
'It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files.',
'To clear this error, remove `pnpm-lock.yaml`.',
].join('\n')
);
}
if (!APP.PUBLIC_PATH.endsWith('/')) {
lintErrors.push('`PUBLIC_PATH` required trailing slash.');
}
lintWarns.forEach((i) => logger.warn(i));
lintErrors.forEach((i) => logger.error(i));
console.log('');
logger.info(`errors: ${lintErrors.length} warnings: ${lintWarns.length}\n`);
if (lintErrors.length > 0) {
process.exitCode = 1;
}