milkee-plugin-prettier 0.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/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/main.js +187 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 [otoneko.]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# milkee-plugin-prettier
|
|
2
|
+
|
|
3
|
+
A Milkee plugin for working with Prettier for CoffeeScript without version conflicts.
|
|
4
|
+
|
|
5
|
+
- Uses [Optimized-Prettier](https://github.com/helixbass/prettier/releases/tag/prettier-v2.1.0-dev.100-gitpkg) (by [helixbass](https://github.com/helixbass)) and [prettier-plugin-coffeescript](https://www.npmjs.com/package/prettier-plugin-coffeescript) (by [helixbass](https://github.com/helixbass)) to format CoffeeScript files.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Recursively finds `.coffee` files in the build output directory and formats them with Prettier.
|
|
10
|
+
- Supports a `prettierrc` (object or a path to a config file) and `.prettierignore` to exclude files.
|
|
11
|
+
- Automatically resolves config via `prettier.resolveConfig()` or `package.json#prettier` when `prettierrc` is not provided.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### coffee.config.cjs
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const prettierPlugin = require('milkee-plugin-prettier');
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
entry: 'src',
|
|
22
|
+
output: 'dist',
|
|
23
|
+
milkee: {
|
|
24
|
+
plugins: [
|
|
25
|
+
// Pass options (optional)
|
|
26
|
+
prettierPlugin({
|
|
27
|
+
prettierrc: { tabWidth: 2 }, // or a path to a config file
|
|
28
|
+
prettierignore: '.prettierignore' // optional, resolved from cwd
|
|
29
|
+
})
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Notes
|
|
36
|
+
|
|
37
|
+
- `.prettierignore` is resolved relative to `process.cwd()` by default. You can pass an absolute or relative path via the `prettierignore` option.
|
|
38
|
+
- When `config.options.join` is used and a single output file is emitted, the plugin will use the directory of the output file as the search root for `.coffee` files.
|
|
39
|
+
|
|
40
|
+
## Development
|
|
41
|
+
|
|
42
|
+
- Build: `npm run build`
|
|
43
|
+
- Link for local testing: `npm link` → in another project: `npm link milkee-plugin-prettier`
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
MIT
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var PREFIX, c, collectCoffeeFiles, consola, fs, i, ignore, len, main, method, path, pkg, prettier, ref;
|
|
3
|
+
|
|
4
|
+
fs = require('fs');
|
|
5
|
+
|
|
6
|
+
path = require('path');
|
|
7
|
+
|
|
8
|
+
consola = require('consola');
|
|
9
|
+
|
|
10
|
+
prettier = require('prettier');
|
|
11
|
+
|
|
12
|
+
ignore = require('ignore');
|
|
13
|
+
|
|
14
|
+
pkg = require('../package.json');
|
|
15
|
+
|
|
16
|
+
PREFIX = `[${pkg.name}]`;
|
|
17
|
+
|
|
18
|
+
// Create a custom logger with prefix
|
|
19
|
+
c = {};
|
|
20
|
+
|
|
21
|
+
ref = ['log', 'info', 'success', 'warn', 'error', 'debug', 'start', 'box'];
|
|
22
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
|
23
|
+
method = ref[i];
|
|
24
|
+
(function(method) {
|
|
25
|
+
return c[method] = function(...args) {
|
|
26
|
+
if (typeof args[0] === 'string') {
|
|
27
|
+
args[0] = `${PREFIX} ${args[0]}`;
|
|
28
|
+
}
|
|
29
|
+
return consola[method](...args);
|
|
30
|
+
};
|
|
31
|
+
})(method);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Helper: recursively collect .coffee files
|
|
35
|
+
collectCoffeeFiles = function(dir, list = []) {
|
|
36
|
+
var ent, entries, error, full, j, len1;
|
|
37
|
+
try {
|
|
38
|
+
entries = fs.readdirSync(dir, {
|
|
39
|
+
withFileTypes: true
|
|
40
|
+
});
|
|
41
|
+
} catch (error1) {
|
|
42
|
+
error = error1;
|
|
43
|
+
return list;
|
|
44
|
+
}
|
|
45
|
+
for (j = 0, len1 = entries.length; j < len1; j++) {
|
|
46
|
+
ent = entries[j];
|
|
47
|
+
full = path.join(dir, ent.name);
|
|
48
|
+
if (ent.isDirectory()) {
|
|
49
|
+
collectCoffeeFiles(full, list);
|
|
50
|
+
} else if (path.extname(ent.name) === '.coffee') {
|
|
51
|
+
list.push(full);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return list;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Export a plugin factory
|
|
58
|
+
main = function(opts = {}) {
|
|
59
|
+
return async function(compilationResult) {
|
|
60
|
+
var compiledFiles, config, defaultIgnore, err, error, file, files, formatted, formattedCount, ig, ignorePath, ignorePatterns, info, j, len1, outDir, output, pkgPath, prettierOptions, prettierrc, projectRoot, rcPath, ref1, rel, text;
|
|
61
|
+
({config, compiledFiles} = compilationResult);
|
|
62
|
+
// Determine output directory
|
|
63
|
+
output = (config != null ? config.output : void 0) || 'dist';
|
|
64
|
+
outDir = (config != null ? (ref1 = config.options) != null ? ref1.join : void 0 : void 0) ? path.dirname(output) : output;
|
|
65
|
+
projectRoot = process.cwd();
|
|
66
|
+
// Handle prettierignore: can be a path (string) or an array of patterns
|
|
67
|
+
ignorePath = null;
|
|
68
|
+
ignorePatterns = null;
|
|
69
|
+
ig = null;
|
|
70
|
+
if (Array.isArray(opts != null ? opts.prettierignore : void 0)) {
|
|
71
|
+
ignorePatterns = opts.prettierignore.filter(function(p) {
|
|
72
|
+
return typeof p === 'string';
|
|
73
|
+
});
|
|
74
|
+
if (ignorePatterns.length > 0) {
|
|
75
|
+
ig = ignore().add(ignorePatterns);
|
|
76
|
+
}
|
|
77
|
+
} else if (typeof (opts != null ? opts.prettierignore : void 0) === 'string') {
|
|
78
|
+
ignorePath = path.isAbsolute(opts.prettierignore) ? opts.prettierignore : path.join(projectRoot, opts.prettierignore);
|
|
79
|
+
if (!fs.existsSync(ignorePath)) {
|
|
80
|
+
c.warn(`prettierignore not found at ${ignorePath}`);
|
|
81
|
+
ignorePath = null;
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
defaultIgnore = path.join(projectRoot, '.prettierignore');
|
|
85
|
+
if (fs.existsSync(defaultIgnore)) {
|
|
86
|
+
ignorePath = defaultIgnore;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Load prettierrc: opts.prettierrc can be an object or a path to a file. If not provided, try resolveConfig, then package.json
|
|
90
|
+
prettierrc = null;
|
|
91
|
+
if ((opts != null ? opts.prettierrc : void 0) != null) {
|
|
92
|
+
if (typeof opts.prettierrc === 'object') {
|
|
93
|
+
prettierrc = opts.prettierrc;
|
|
94
|
+
} else if (typeof opts.prettierrc === 'string') {
|
|
95
|
+
rcPath = path.isAbsolute(opts.prettierrc) ? opts.prettierrc : path.join(projectRoot, opts.prettierrc);
|
|
96
|
+
try {
|
|
97
|
+
prettierrc = JSON.parse(fs.readFileSync(rcPath, 'utf8'));
|
|
98
|
+
} catch (error1) {
|
|
99
|
+
error = error1;
|
|
100
|
+
c.warn(`Failed to read prettierrc at ${rcPath}: ${error.message}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (prettierrc == null) {
|
|
105
|
+
try {
|
|
106
|
+
prettierrc = (await prettier.resolveConfig(projectRoot));
|
|
107
|
+
} catch (error1) {
|
|
108
|
+
error = error1;
|
|
109
|
+
prettierrc = null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (prettierrc == null) {
|
|
113
|
+
try {
|
|
114
|
+
pkgPath = path.join(projectRoot, 'package.json');
|
|
115
|
+
if (fs.existsSync(pkgPath)) {
|
|
116
|
+
pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
117
|
+
if ((pkg != null ? pkg.prettier : void 0) != null) {
|
|
118
|
+
prettierrc = pkg.prettier;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} catch (error1) {
|
|
122
|
+
error = error1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// ignore
|
|
126
|
+
c.info(`Searching .coffee files in ${outDir}`);
|
|
127
|
+
if (!fs.existsSync(outDir)) {
|
|
128
|
+
c.warn(`Output directory not found: ${outDir}`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
files = collectCoffeeFiles(outDir);
|
|
132
|
+
if (files.length === 0) {
|
|
133
|
+
c.info(`No .coffee files found in ${outDir}`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
c.info(`Found ${files.length} .coffee file(s)`);
|
|
137
|
+
formattedCount = 0;
|
|
138
|
+
for (j = 0, len1 = files.length; j < len1; j++) {
|
|
139
|
+
file = files[j];
|
|
140
|
+
try {
|
|
141
|
+
// Ensure we only format CoffeeScript files
|
|
142
|
+
if (path.extname(file) !== '.coffee') {
|
|
143
|
+
c.debug(`Skip non-coffee file: ${file}`);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
// Check ignore via patterns or ignore file
|
|
147
|
+
if (ig != null) {
|
|
148
|
+
rel = path.relative(projectRoot, file).split(path.sep).join('/');
|
|
149
|
+
if (ig.ignores(rel)) {
|
|
150
|
+
c.info(`Ignored by prettierignore patterns: ${file}`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
} else if (ignorePath != null) {
|
|
154
|
+
try {
|
|
155
|
+
info = (await prettier.getFileInfo(file, {ignorePath}));
|
|
156
|
+
if (info != null ? info.ignored : void 0) {
|
|
157
|
+
c.info(`Ignored by .prettierignore: ${file}`);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
} catch (error1) {
|
|
161
|
+
err = error1;
|
|
162
|
+
c.debug(`Failed to check ignore for ${file}: ${err.message}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
text = fs.readFileSync(file, 'utf8');
|
|
166
|
+
prettierOptions = Object.assign({}, prettierrc || {}, {
|
|
167
|
+
filepath: file,
|
|
168
|
+
plugins: [require.resolve('prettier-plugin-coffeescript')]
|
|
169
|
+
});
|
|
170
|
+
formatted = prettier.format(text, prettierOptions);
|
|
171
|
+
if (formatted !== text) {
|
|
172
|
+
fs.writeFileSync(file, formatted, 'utf8');
|
|
173
|
+
formattedCount += 1;
|
|
174
|
+
c.success(`Formatted: ${file}`);
|
|
175
|
+
} else {
|
|
176
|
+
c.debug(`Already formatted: ${file}`);
|
|
177
|
+
}
|
|
178
|
+
} catch (error1) {
|
|
179
|
+
error = error1;
|
|
180
|
+
c.error(`Failed to format ${file}: ${error.message}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return c.success(`Prettier formatted ${formattedCount} file(s)`);
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
module.exports = main;
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "milkee-plugin-prettier",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A Milkee plugin for working with Prettier for CoffeeScript without version conflicts.",
|
|
5
|
+
"main": "dist/main.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 0",
|
|
8
|
+
"build": "milkee"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/otoneko1102/coffeescript-milkee-plugin-prettier.git"
|
|
13
|
+
},
|
|
14
|
+
"author": "otoneko.",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/otoneko1102/coffeescript-milkee-plugin-prettier/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/otoneko1102/coffeescript-milkee-plugin-prettier#readme",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"consola": "^3.4.2",
|
|
22
|
+
"ignore": "^7.0.5",
|
|
23
|
+
"prettier": "github:helixbass/prettier#prettier-v2.1.0-dev.100-gitpkg",
|
|
24
|
+
"prettier-plugin-coffeescript": "^0.1.5"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"coffeescript": "^2.7.0",
|
|
28
|
+
"milkee": "^3.1.2"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"milkee",
|
|
32
|
+
"coffeescript",
|
|
33
|
+
"coffee",
|
|
34
|
+
"prettier",
|
|
35
|
+
"format",
|
|
36
|
+
"formatter",
|
|
37
|
+
"plugin",
|
|
38
|
+
"milkee-plugin"
|
|
39
|
+
]
|
|
40
|
+
}
|