milkee 2.3.1 → 2.4.0-dev.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/dist/commands/plugin.js +208 -0
- package/dist/main.js +9 -1
- package/package.json +1 -1
- package/temp/plugin/_gitattributes +2 -0
- package/temp/plugin/_gitignore +2 -0
- package/temp/plugin/_npmignore +4 -0
- package/temp/plugin/coffee.config.cjs +35 -0
- package/temp/plugin/main.coffee +25 -0
- package/temp/plugin/publish.yml +47 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var CONFIG_FILE, CWD, PLUGIN_KEYWORDS, TEMPLATES, TEMPLATE_DIR, confirmContinue, consola, copyTemplate, ensureDir, execSync, fs, initPackageJson, path, plugin, updatePackageJson,
|
|
3
|
+
indexOf = [].indexOf;
|
|
4
|
+
|
|
5
|
+
fs = require('fs');
|
|
6
|
+
|
|
7
|
+
path = require('path');
|
|
8
|
+
|
|
9
|
+
({execSync} = require('child_process'));
|
|
10
|
+
|
|
11
|
+
consola = require('consola');
|
|
12
|
+
|
|
13
|
+
({CWD, CONFIG_FILE} = require('../constants'));
|
|
14
|
+
|
|
15
|
+
confirmContinue = require('../options/confirm');
|
|
16
|
+
|
|
17
|
+
TEMPLATE_DIR = path.join(__dirname, '..', '..', 'temp', 'plugin');
|
|
18
|
+
|
|
19
|
+
TEMPLATES = [
|
|
20
|
+
{
|
|
21
|
+
src: 'main.coffee',
|
|
22
|
+
dest: 'src/main.coffee'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
src: 'coffee.config.cjs',
|
|
26
|
+
dest: CONFIG_FILE
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
src: 'publish.yml',
|
|
30
|
+
dest: '.github/workflows/publish.yml'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
src: '_gitignore',
|
|
34
|
+
dest: '.gitignore'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
src: '_gitattributes',
|
|
38
|
+
dest: '.gitattributes'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
src: '_npmignore',
|
|
42
|
+
dest: '.npmignore'
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
// Create directory if not exists
|
|
47
|
+
ensureDir = function(filePath) {
|
|
48
|
+
var dir;
|
|
49
|
+
dir = path.dirname(filePath);
|
|
50
|
+
if (!fs.existsSync(dir)) {
|
|
51
|
+
return fs.mkdirSync(dir, {
|
|
52
|
+
recursive: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Copy template file
|
|
58
|
+
copyTemplate = function(src, dest) {
|
|
59
|
+
var content, destPath, srcPath;
|
|
60
|
+
srcPath = path.join(TEMPLATE_DIR, src);
|
|
61
|
+
destPath = path.join(CWD, dest);
|
|
62
|
+
if (!fs.existsSync(srcPath)) {
|
|
63
|
+
consola.error(`Template file not found: ${srcPath}`);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
ensureDir(destPath);
|
|
67
|
+
content = fs.readFileSync(srcPath, 'utf-8');
|
|
68
|
+
fs.writeFileSync(destPath, content);
|
|
69
|
+
consola.success(`Created \`${dest}\``);
|
|
70
|
+
return true;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
PLUGIN_KEYWORDS = ['milkee', 'coffeescript', 'coffee', 'ext', 'plugin', 'milkee-plugin'];
|
|
74
|
+
|
|
75
|
+
// Update package.json
|
|
76
|
+
updatePackageJson = function() {
|
|
77
|
+
var base, error, i, keyword, len, pkg, pkgPath;
|
|
78
|
+
pkgPath = path.join(CWD, 'package.json');
|
|
79
|
+
try {
|
|
80
|
+
pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
81
|
+
// Update main
|
|
82
|
+
pkg.main = 'dist/main.js';
|
|
83
|
+
// Update scripts
|
|
84
|
+
if (pkg.scripts == null) {
|
|
85
|
+
pkg.scripts = {};
|
|
86
|
+
}
|
|
87
|
+
if ((base = pkg.scripts).test == null) {
|
|
88
|
+
base.test = 'echo "Error: no test specified" && exit 0';
|
|
89
|
+
}
|
|
90
|
+
pkg.scripts.build = 'milkee';
|
|
91
|
+
// Update keywords
|
|
92
|
+
if (pkg.keywords == null) {
|
|
93
|
+
pkg.keywords = [];
|
|
94
|
+
}
|
|
95
|
+
for (i = 0, len = PLUGIN_KEYWORDS.length; i < len; i++) {
|
|
96
|
+
keyword = PLUGIN_KEYWORDS[i];
|
|
97
|
+
if (indexOf.call(pkg.keywords, keyword) < 0) {
|
|
98
|
+
pkg.keywords.push(keyword);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
102
|
+
consola.success("Updated `package.json`");
|
|
103
|
+
return true;
|
|
104
|
+
} catch (error1) {
|
|
105
|
+
error = error1;
|
|
106
|
+
consola.error("Failed to update package.json:", error);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Initialize package.json if not exists
|
|
112
|
+
initPackageJson = function() {
|
|
113
|
+
var error, pkgPath;
|
|
114
|
+
pkgPath = path.join(CWD, 'package.json');
|
|
115
|
+
if (!fs.existsSync(pkgPath)) {
|
|
116
|
+
consola.start("Initializing package.json...");
|
|
117
|
+
try {
|
|
118
|
+
execSync('npm init -y', {
|
|
119
|
+
cwd: CWD,
|
|
120
|
+
stdio: 'inherit'
|
|
121
|
+
});
|
|
122
|
+
consola.success("Created `package.json`");
|
|
123
|
+
} catch (error1) {
|
|
124
|
+
error = error1;
|
|
125
|
+
consola.error("Failed to create package.json:", error);
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// Main plugin setup function
|
|
133
|
+
plugin = async function() {
|
|
134
|
+
var confirmed, destPath, error, i, j, len, len1, overwrite, pkgPath, template;
|
|
135
|
+
consola.box("Milkee Plugin Setup");
|
|
136
|
+
consola.info("This will set up your project as a Milkee plugin.");
|
|
137
|
+
consola.info("");
|
|
138
|
+
consola.info("The following actions will be performed:");
|
|
139
|
+
pkgPath = path.join(CWD, 'package.json');
|
|
140
|
+
if (!fs.existsSync(pkgPath)) {
|
|
141
|
+
consola.info(" 0. Initialize package.json (npm init -y)");
|
|
142
|
+
}
|
|
143
|
+
consola.info(" 1. Install dependencies (consola, coffeescript, milkee)");
|
|
144
|
+
consola.info(" 2. Create template files:");
|
|
145
|
+
for (i = 0, len = TEMPLATES.length; i < len; i++) {
|
|
146
|
+
template = TEMPLATES[i];
|
|
147
|
+
consola.info(` - ${template.dest}`);
|
|
148
|
+
}
|
|
149
|
+
consola.info(" 3. Update package.json (main, scripts, keywords)");
|
|
150
|
+
consola.info("");
|
|
151
|
+
// Confirm before proceeding
|
|
152
|
+
confirmed = (await confirmContinue());
|
|
153
|
+
if (!confirmed) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
consola.info("");
|
|
157
|
+
// Initialize package.json if not exists
|
|
158
|
+
if (!initPackageJson()) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
// Install dependencies
|
|
163
|
+
consola.start("Installing dependencies...");
|
|
164
|
+
execSync('npm install consola', {
|
|
165
|
+
cwd: CWD,
|
|
166
|
+
stdio: 'inherit'
|
|
167
|
+
});
|
|
168
|
+
execSync('npm install -D coffeescript milkee', {
|
|
169
|
+
cwd: CWD,
|
|
170
|
+
stdio: 'inherit'
|
|
171
|
+
});
|
|
172
|
+
consola.success("Dependencies installed!");
|
|
173
|
+
} catch (error1) {
|
|
174
|
+
error = error1;
|
|
175
|
+
consola.error("Failed to install dependencies:", error);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
consola.info("");
|
|
179
|
+
// Create template files
|
|
180
|
+
consola.start("Creating template files...");
|
|
181
|
+
for (j = 0, len1 = TEMPLATES.length; j < len1; j++) {
|
|
182
|
+
template = TEMPLATES[j];
|
|
183
|
+
destPath = path.join(CWD, template.dest);
|
|
184
|
+
if (fs.existsSync(destPath)) {
|
|
185
|
+
overwrite = (await consola.prompt(`${template.dest} already exists. Overwrite?`, {
|
|
186
|
+
type: "confirm"
|
|
187
|
+
}));
|
|
188
|
+
if (!overwrite) {
|
|
189
|
+
consola.info(`Skipped \`${template.dest}\``);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
copyTemplate(template.src, template.dest);
|
|
194
|
+
}
|
|
195
|
+
consola.info("");
|
|
196
|
+
// Update package.json
|
|
197
|
+
consola.start("Updating package.json...");
|
|
198
|
+
updatePackageJson();
|
|
199
|
+
consola.info("");
|
|
200
|
+
consola.success("Milkee plugin setup complete!");
|
|
201
|
+
consola.info("");
|
|
202
|
+
consola.info("Next steps:");
|
|
203
|
+
consola.info(" 1. Edit `src/main.coffee` to implement your plugin");
|
|
204
|
+
consola.info(" 2. Run `npm run build` to compile");
|
|
205
|
+
return consola.info(" 3. Test your plugin locally");
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
module.exports = plugin;
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
|
2
|
-
var argv, compile, hideBin, pkg, setup, yargs;
|
|
2
|
+
var argv, compile, hideBin, pkg, plugin, setup, yargs;
|
|
3
3
|
|
|
4
4
|
yargs = require('yargs');
|
|
5
5
|
|
|
@@ -11,6 +11,8 @@ setup = require('./commands/setup');
|
|
|
11
11
|
|
|
12
12
|
compile = require('./commands/compile');
|
|
13
13
|
|
|
14
|
+
plugin = require('./commands/plugin');
|
|
15
|
+
|
|
14
16
|
argv = yargs(hideBin(process.argv)).scriptName('milkee').usage('$0 [command]').option('setup', {
|
|
15
17
|
alias: 's',
|
|
16
18
|
describe: "Generate a default config file",
|
|
@@ -19,10 +21,16 @@ argv = yargs(hideBin(process.argv)).scriptName('milkee').usage('$0 [command]').o
|
|
|
19
21
|
alias: 'c',
|
|
20
22
|
describe: "Compile CoffeeScript (default)",
|
|
21
23
|
type: 'boolean'
|
|
24
|
+
}).option('plugin', {
|
|
25
|
+
alias: 'p',
|
|
26
|
+
describe: "Set up a new Milkee plugin project",
|
|
27
|
+
type: 'boolean'
|
|
22
28
|
}).version('version', pkg.version).alias('v', 'version').help('help').alias('h', 'help').argv;
|
|
23
29
|
|
|
24
30
|
if (argv.setup) {
|
|
25
31
|
setup();
|
|
32
|
+
} else if (argv.plugin) {
|
|
33
|
+
plugin();
|
|
26
34
|
} else {
|
|
27
35
|
compile();
|
|
28
36
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** @type {import('@milkee/d').Config} */
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
// The entry point for compilation.
|
|
5
|
+
// This can be a single file or a directory (e.g., 'src/' or 'src/app.coffee').
|
|
6
|
+
entry: 'src',
|
|
7
|
+
// The output for the compiled JavaScript files.
|
|
8
|
+
// If 'options.join' is true, this should be a single file path (e.g., 'dist/app.js').
|
|
9
|
+
// If 'options.join' is false, this should be a directory (e.g., 'dist').
|
|
10
|
+
output: 'dist',
|
|
11
|
+
// (Optional) Additional options for the CoffeeScript compiler.
|
|
12
|
+
// See `coffee --help` for all available options.
|
|
13
|
+
// Web: https://coffeescript.org/annotated-source/command.html
|
|
14
|
+
options: {
|
|
15
|
+
// The following options are supported:
|
|
16
|
+
bare: true,
|
|
17
|
+
// join: false,
|
|
18
|
+
// map: false,
|
|
19
|
+
// inlineMap: false,
|
|
20
|
+
// noHeader: false,
|
|
21
|
+
// transpile: false,
|
|
22
|
+
// literate: false,
|
|
23
|
+
// watch: false,
|
|
24
|
+
},
|
|
25
|
+
// (Optional) Additional options/plugins for the Milkee builder.
|
|
26
|
+
milkee: {
|
|
27
|
+
options: {
|
|
28
|
+
// Before compiling, reset the directory.
|
|
29
|
+
// refresh: false,
|
|
30
|
+
// Before compiling, confirm "Do you want to Continue?"
|
|
31
|
+
// confirm: false,
|
|
32
|
+
},
|
|
33
|
+
plugins: []
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
fs = require 'fs'
|
|
2
|
+
path = require 'path'
|
|
3
|
+
consola = require 'consola'
|
|
4
|
+
|
|
5
|
+
pkg = require '../package.json'
|
|
6
|
+
PREFIX = "[#{pkg.name}]"
|
|
7
|
+
|
|
8
|
+
# Create a custom logger with prefix
|
|
9
|
+
c = {}
|
|
10
|
+
for method in ['log', 'info', 'success', 'warn', 'error', 'debug', 'start', 'box']
|
|
11
|
+
do (method) ->
|
|
12
|
+
c[method] = (args...) ->
|
|
13
|
+
if typeof args[0] is 'string'
|
|
14
|
+
args[0] = "#{PREFIX} #{args[0]}"
|
|
15
|
+
consola[method] args...
|
|
16
|
+
|
|
17
|
+
# Main plugin function
|
|
18
|
+
main = (compilationResult) ->
|
|
19
|
+
{ config, compiledFiles, stdout, stderr } = compilationResult
|
|
20
|
+
|
|
21
|
+
c.info "Compiled #{compiledFiles.length} file(s)"
|
|
22
|
+
for file in compiledFiles
|
|
23
|
+
c.log " - #{file}"
|
|
24
|
+
|
|
25
|
+
module.exports = main
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: Manual Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
publish-npm:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
permissions:
|
|
10
|
+
id-token: write
|
|
11
|
+
contents: write
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout repository
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Setup Node.js
|
|
17
|
+
uses: actions/setup-node@v4
|
|
18
|
+
with:
|
|
19
|
+
node-version: "20.x"
|
|
20
|
+
registry-url: "https://registry.npmjs.org"
|
|
21
|
+
|
|
22
|
+
- name: Install, Build, and Test
|
|
23
|
+
run: |
|
|
24
|
+
npm ci
|
|
25
|
+
npm run build
|
|
26
|
+
npm test
|
|
27
|
+
|
|
28
|
+
- name: Commit dist directory (if changed)
|
|
29
|
+
run: |
|
|
30
|
+
git config --global user.name "github-actions[bot]"
|
|
31
|
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
32
|
+
git add dist
|
|
33
|
+
# The following command creates a commit ONLY if there are staged changes.
|
|
34
|
+
git diff --staged --quiet || git commit -m "chore: update build artifacts"
|
|
35
|
+
git push
|
|
36
|
+
|
|
37
|
+
- name: Publish to npm
|
|
38
|
+
run: npm publish --provenance --access public
|
|
39
|
+
env:
|
|
40
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
41
|
+
|
|
42
|
+
- name: Create and Push Git Tag
|
|
43
|
+
run: |
|
|
44
|
+
# This step now runs after the dist commit, ensuring the tag points to the correct commit.
|
|
45
|
+
VERSION=$(node -p "require('./package.json').version")
|
|
46
|
+
git tag "v$VERSION"
|
|
47
|
+
git push origin "v$VERSION"
|