Skip to content

Commit 40a3fce

Browse files
authored
format package.json and generate INSTALL.md (#267)
* format package.json * cleanup * mv * mv * generate install instructions * bring install instructions back up to date
1 parent 9aec456 commit 40a3fce

File tree

71 files changed

+2879
-1805
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2879
-1805
lines changed

.github/ISSUE_TEMPLATE/css-issue.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ body:
9595
- PostCSS Replace Overflow Wrap
9696
- PostCSS Selector Not
9797
- PostCSS System Ui Font Family
98-
- PostCSS Plugins Values Parser
9998
- type: input
10099
id: version
101100
attributes:

.github/ISSUE_TEMPLATE/plugin-issue.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ body:
9797
- PostCSS Replace Overflow Wrap
9898
- PostCSS Selector Not
9999
- PostCSS System Ui Font Family
100-
- PostCSS Plugins Values Parser
101100
- type: input
102101
id: version
103102
attributes:
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
import { promises as fsp, constants } from 'fs';
2+
3+
const packageJSONInfo = JSON.parse(await fsp.readFile('./package.json', 'utf8'));
4+
const packageJSONInfoCopy = JSON.stringify(packageJSONInfo, null, 2);
5+
const formatted = {};
6+
7+
// Main info
8+
{
9+
formatted.name = packageJSONInfo.name;
10+
delete packageJSONInfo.name;
11+
12+
formatted.description = packageJSONInfo.description;
13+
delete packageJSONInfo.description;
14+
15+
formatted.version = packageJSONInfo.version;
16+
delete packageJSONInfo.version;
17+
18+
formatted.author = packageJSONInfo.author;
19+
delete packageJSONInfo.author;
20+
21+
formatted.contributors = packageJSONInfo.contributors;
22+
delete packageJSONInfo.contributors;
23+
24+
if (formatted.contributors && formatted.contributors.length) {
25+
formatted.contributors.sort();
26+
}
27+
28+
formatted.license = packageJSONInfo.license;
29+
delete packageJSONInfo.license;
30+
}
31+
32+
// Status and runtime info
33+
{
34+
formatted.private = packageJSONInfo.private;
35+
delete packageJSONInfo.private;
36+
37+
formatted.engines = packageJSONInfo.engines;
38+
delete packageJSONInfo.engines;
39+
40+
formatted.type = packageJSONInfo.type;
41+
delete packageJSONInfo.type;
42+
}
43+
44+
// Exports and packaged
45+
{
46+
formatted.main = packageJSONInfo.main;
47+
delete packageJSONInfo.main;
48+
49+
formatted.module = packageJSONInfo.module;
50+
delete packageJSONInfo.module;
51+
52+
formatted.bin = packageJSONInfo.bin;
53+
delete packageJSONInfo.bin;
54+
55+
formatted.types = packageJSONInfo.types;
56+
delete packageJSONInfo.types;
57+
58+
formatted.jsdelivr = packageJSONInfo.jsdelivr;
59+
delete packageJSONInfo.jsdelivr;
60+
61+
formatted.unpkg = packageJSONInfo.unpkg;
62+
delete packageJSONInfo.unpkg;
63+
64+
formatted.exports = packageJSONInfo.exports;
65+
delete packageJSONInfo.exports;
66+
67+
formatted.files = packageJSONInfo.files;
68+
delete packageJSONInfo.files;
69+
70+
if (formatted.files && formatted.files.length) {
71+
formatted.files.sort();
72+
}
73+
}
74+
75+
// Dependencies
76+
{
77+
if (Object.keys(packageJSONInfo.dependencies ?? {}).length) {
78+
let dependencyKeys = Object.keys(packageJSONInfo.dependencies);
79+
dependencyKeys.sort((a, b) => a.localeCompare(b));
80+
81+
formatted.dependencies = {};
82+
for (let i = 0; i < dependencyKeys.length; i++) {
83+
formatted.dependencies[dependencyKeys[i]] = packageJSONInfo.dependencies[dependencyKeys[i]];
84+
}
85+
delete packageJSONInfo.dependencies;
86+
}
87+
88+
if (Object.keys(packageJSONInfo.peerDependencies ?? {}).length) {
89+
let dependencyKeys = Object.keys(packageJSONInfo.peerDependencies);
90+
dependencyKeys.sort((a, b) => a.localeCompare(b));
91+
92+
formatted.peerDependencies = {};
93+
for (let i = 0; i < dependencyKeys.length; i++) {
94+
formatted.peerDependencies[dependencyKeys[i]] = packageJSONInfo.peerDependencies[dependencyKeys[i]];
95+
}
96+
delete packageJSONInfo.peerDependencies;
97+
}
98+
99+
if (Object.keys(packageJSONInfo.devDependencies ?? {}).length) {
100+
let dependencyKeys = Object.keys(packageJSONInfo.devDependencies);
101+
dependencyKeys.sort((a, b) => a.localeCompare(b));
102+
103+
formatted.devDependencies = {};
104+
for (let i = 0; i < dependencyKeys.length; i++) {
105+
formatted.devDependencies[dependencyKeys[i]] = packageJSONInfo.devDependencies[dependencyKeys[i]];
106+
}
107+
delete packageJSONInfo.devDependencies;
108+
}
109+
}
110+
111+
// Scripts
112+
{
113+
if (Object.keys(packageJSONInfo.scripts ?? {}).length) {
114+
let scriptKeys = Object.keys(packageJSONInfo.scripts);
115+
scriptKeys.sort((a, b) => {
116+
let aa = a;
117+
let bb = b;
118+
119+
if (aa === 'prepublishOnly') {
120+
aa = 'prepublish';
121+
}
122+
if (bb === 'prepublishOnly') {
123+
bb = 'prepublish';
124+
}
125+
126+
if (aa.indexOf('pre') === 0) {
127+
aa = aa.slice(3) + '-a';
128+
} else if (aa.indexOf('post') === 0) {
129+
aa = aa.slice(4) + '-c';
130+
} else {
131+
aa = aa+ '-b';
132+
}
133+
134+
if (bb.indexOf('pre') === 0) {
135+
bb = bb.slice(3) + '-a';
136+
} else if (bb.indexOf('post') === 0) {
137+
bb = bb.slice(4) + '-c';
138+
} else {
139+
bb = bb + '-b';
140+
}
141+
142+
143+
return aa.localeCompare(bb);
144+
});
145+
146+
formatted.scripts = {};
147+
for (let i = 0; i < scriptKeys.length; i++) {
148+
formatted.scripts[scriptKeys[i]] = packageJSONInfo.scripts[scriptKeys[i]];
149+
}
150+
delete packageJSONInfo.scripts;
151+
152+
try {
153+
await fsp.access('./stryker.conf.json', constants.R_OK | constants.W_OK);
154+
} catch (_) {
155+
delete formatted.scripts.stryker;
156+
}
157+
}
158+
}
159+
160+
// Metadata
161+
{
162+
formatted.homepage = packageJSONInfo.homepage;
163+
delete packageJSONInfo.homepage;
164+
165+
formatted.repository = packageJSONInfo.repository;
166+
delete packageJSONInfo.repository;
167+
168+
formatted.bugs = packageJSONInfo.bugs;
169+
delete packageJSONInfo.bugs;
170+
171+
formatted.keywords = packageJSONInfo.keywords;
172+
delete packageJSONInfo.keywords;
173+
174+
if (formatted.keywords && formatted.keywords.length) {
175+
formatted.keywords.sort();
176+
}
177+
178+
if (Object.keys(packageJSONInfo.csstools ?? {}).length) {
179+
let csstoolsKeys = Object.keys(packageJSONInfo.csstools);
180+
csstoolsKeys.sort((a, b) => a.localeCompare(b));
181+
182+
formatted.csstools = {};
183+
for (let i = 0; i < csstoolsKeys.length; i++) {
184+
formatted.csstools[csstoolsKeys[i]] = packageJSONInfo.csstools[csstoolsKeys[i]];
185+
}
186+
delete packageJSONInfo.csstools;
187+
}
188+
}
189+
190+
// Config
191+
{
192+
formatted.volta = packageJSONInfo.volta;
193+
delete packageJSONInfo.volta;
194+
}
195+
196+
Object.assign(formatted, packageJSONInfo);
197+
198+
if (process.env.GITHUB_ACTIONS && JSON.stringify(formatted, null, 2) !== packageJSONInfoCopy) {
199+
console.error('package.json has an incorrect field order. Run "npm run lint" to resolve.')
200+
process.exit(1);
201+
}
202+
203+
await fsp.writeFile('./package.json', JSON.stringify(formatted, null, 2) + '\n');
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Installing <humanReadableName>
2+
3+
[<humanReadableName>] runs in all Node environments, with special instructions for:
4+
5+
| [Node](#node) | [PostCSS CLI](#postcss-cli) | [Webpack](#webpack) | [Create React App](#create-react-app) | [Gulp](#gulp) | [Grunt](#grunt) |
6+
| --- | --- | --- | --- | --- | --- |
7+
8+
## Node
9+
10+
Add [<humanReadableName>] to your project:
11+
12+
```bash
13+
npm install postcss <packageName> --save-dev
14+
```
15+
16+
Use it as a [PostCSS] plugin:
17+
18+
```js
19+
const postcss = require('postcss');
20+
const <exportName> = require('<packageName>');
21+
22+
postcss([
23+
<exportName>(/* pluginOptions */)
24+
]).process(YOUR_CSS /*, processOptions */);
25+
```
26+
27+
## PostCSS CLI
28+
29+
Add [PostCSS CLI] to your project:
30+
31+
```bash
32+
npm install postcss-cli <packageName> --save-dev
33+
```
34+
35+
Use [<humanReadableName>] in your `postcss.config.js` configuration file:
36+
37+
```js
38+
const <exportName> = require('<packageName>');
39+
40+
module.exports = {
41+
plugins: [
42+
<exportName>(/* pluginOptions */)
43+
]
44+
}
45+
```
46+
47+
## Webpack
48+
49+
_Webpack version 5_
50+
51+
Add [PostCSS Loader] to your project:
52+
53+
```bash
54+
npm install postcss-loader <packageName> --save-dev
55+
```
56+
57+
Use [<humanReadableName>] in your Webpack configuration:
58+
59+
```js
60+
module.exports = {
61+
module: {
62+
rules: [
63+
{
64+
test: /\.css$/i,
65+
use: [
66+
"style-loader",
67+
{
68+
loader: "css-loader",
69+
options: { importLoaders: 1 },
70+
},
71+
{
72+
loader: "postcss-loader",
73+
options: {
74+
postcssOptions: {
75+
plugins: [
76+
[
77+
"<packageName>",
78+
{
79+
// Options
80+
},
81+
],
82+
],
83+
},
84+
},
85+
},
86+
],
87+
},
88+
],
89+
},
90+
};
91+
```
92+
93+
## Create React App
94+
95+
Add [React App Rewired] and [React App Rewire PostCSS] to your project:
96+
97+
```bash
98+
npm install react-app-rewired react-app-rewire-postcss <packageName> --save-dev
99+
```
100+
101+
Use [React App Rewire PostCSS] and [<humanReadableName>] in your
102+
`config-overrides.js` file:
103+
104+
```js
105+
const reactAppRewirePostcss = require('react-app-rewire-postcss');
106+
const <exportName> = require('<packageName>');
107+
108+
module.exports = config => reactAppRewirePostcss(config, {
109+
plugins: () => [
110+
<exportName>(/* pluginOptions */)
111+
]
112+
});
113+
```
114+
115+
## Gulp
116+
117+
Add [Gulp PostCSS] to your project:
118+
119+
```bash
120+
npm install gulp-postcss <packageName> --save-dev
121+
```
122+
123+
Use [<humanReadableName>] in your Gulpfile:
124+
125+
```js
126+
const postcss = require('gulp-postcss');
127+
const <exportName> = require('<packageName>');
128+
129+
gulp.task('css', function () {
130+
var plugins = [
131+
<exportName>(/* pluginOptions */)
132+
];
133+
134+
return gulp.src('./src/*.css')
135+
.pipe(postcss(plugins))
136+
.pipe(gulp.dest('.'));
137+
});
138+
```
139+
140+
## Grunt
141+
142+
Add [Grunt PostCSS] to your project:
143+
144+
```bash
145+
npm install grunt-postcss <packageName> --save-dev
146+
```
147+
148+
Use [<humanReadableName>] in your Gruntfile:
149+
150+
```js
151+
const <exportName> = require('<packageName>');
152+
153+
grunt.loadNpmTasks('grunt-postcss');
154+
155+
grunt.initConfig({
156+
postcss: {
157+
options: {
158+
processors: [
159+
<exportName>(/* pluginOptions */)
160+
]
161+
},
162+
dist: {
163+
src: '*.css'
164+
}
165+
}
166+
});
167+
```
168+
169+
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
170+
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
171+
[PostCSS]: https://github.com/postcss/postcss
172+
[PostCSS CLI]: https://github.com/postcss/postcss-cli
173+
[PostCSS Loader]: https://github.com/postcss/postcss-loader
174+
[<humanReadableName>]: https://github.com/csstools/postcss-plugins/tree/main/<packagePath>
175+
[React App Rewire PostCSS]: https://github.com/csstools/react-app-rewire-postcss
176+
[React App Rewired]: https://github.com/timarney/react-app-rewired

0 commit comments

Comments
 (0)