@imagexmedia/cli 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 +1 -0
- package/configs/default.package.json +24 -0
- package/dist/bin/swat-dev.d.ts +2 -0
- package/dist/bin/swat-dev.js +3 -0
- package/dist/bin/swat-eslint.d.ts +2 -0
- package/dist/bin/swat-eslint.js +8 -0
- package/dist/bin/swat-stylelint.d.ts +2 -0
- package/dist/bin/swat-stylelint.js +8 -0
- package/dist/bin/swat.d.ts +2 -0
- package/dist/bin/swat.js +3 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +16 -0
- package/dist/commands/lint.d.ts +2 -0
- package/dist/commands/lint.js +84 -0
- package/dist/commands/turbo.d.ts +2 -0
- package/dist/commands/turbo.js +29 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -0
- package/dist/utils/helpers.d.ts +1 -0
- package/dist/utils/helpers.js +17 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [year] [fullname]
|
|
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 @@
|
|
|
1
|
+
# SWAT CLI
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "repo",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"private": true,
|
|
5
|
+
"workspaces": [
|
|
6
|
+
"*/{modules,themes}/custom/**/components/*"
|
|
7
|
+
],
|
|
8
|
+
"packageManager": "npm@11.6.0",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "swat turbo build",
|
|
11
|
+
"build:production": "swat turbo build --production",
|
|
12
|
+
"watch": "swat turbo build --watch",
|
|
13
|
+
"lint": "swat lint",
|
|
14
|
+
"lint:fix": "swat lint --fix"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@imagexmedia/cli": "*",
|
|
18
|
+
"@imagexmedia/eslint": "*",
|
|
19
|
+
"@imagexmedia/stylelint": "*",
|
|
20
|
+
"@imagexmedia/turbo": "*",
|
|
21
|
+
"@imagexmedia/typescript": "*",
|
|
22
|
+
"@imagexmedia/vite": "*"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import execute from '@imagexmedia/cli';
|
|
4
|
+
const argv = [process.argv[0], process.argv[1], 'lint', 'stylelint'];
|
|
5
|
+
if (process.argv.includes('--fix'))
|
|
6
|
+
argv.push('--fix');
|
|
7
|
+
process.argv = argv;
|
|
8
|
+
execute();
|
package/dist/bin/swat.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { $ } from 'execa';
|
|
2
|
+
import { getFile } from "../utils/helpers.js";
|
|
3
|
+
export default function execute(app) {
|
|
4
|
+
app
|
|
5
|
+
.command('build')
|
|
6
|
+
.description('Build frontend components')
|
|
7
|
+
.option('--production', 'Use production mode')
|
|
8
|
+
.option('--watch', 'Use watch mode')
|
|
9
|
+
.action(async (options) => {
|
|
10
|
+
const config = getFile('vite.config.js');
|
|
11
|
+
const cmd = ['npx', 'vite', 'build', '-c', config, '-m', options.production ? 'production' : 'dev'];
|
|
12
|
+
if (options.watch)
|
|
13
|
+
cmd.push('--watch');
|
|
14
|
+
await $({ stdio: 'inherit' }) `${cmd}`;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { Argument } from 'commander';
|
|
4
|
+
import { $ } from 'execa';
|
|
5
|
+
import { Listr } from 'listr2';
|
|
6
|
+
import { getFile } from "../utils/helpers.js";
|
|
7
|
+
const types = ['all', 'eslint', 'stylelint', 'typescript'];
|
|
8
|
+
export default function execute(app) {
|
|
9
|
+
app
|
|
10
|
+
.command('lint')
|
|
11
|
+
.description('Run linters')
|
|
12
|
+
.addArgument(new Argument('[type]', 'Type of linter to run').choices(types).default('all'))
|
|
13
|
+
.option('--fix', 'Attempt to automatically fix issues')
|
|
14
|
+
.action(async (type, options) => {
|
|
15
|
+
const ops = {};
|
|
16
|
+
// ESLint.
|
|
17
|
+
try {
|
|
18
|
+
const config = getFile('eslint.config.js', true);
|
|
19
|
+
ops.eslint = async () => {
|
|
20
|
+
const cmd = ['npx', 'eslint', '-c', config, '--no-error-on-unmatched-pattern', '--color'];
|
|
21
|
+
if (options.fix === true)
|
|
22
|
+
cmd.push('--fix');
|
|
23
|
+
await $ `${cmd} **/*.{js,ts,jsx,tsx,cjs,cts,mjs,mts,vue,html,xml,svg,json,jsonc,yml,yaml,toml}`;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
catch { }
|
|
27
|
+
// Stylelint.
|
|
28
|
+
try {
|
|
29
|
+
const config = getFile('stylelint.config.js', true);
|
|
30
|
+
ops.stylelint = async () => {
|
|
31
|
+
const cmd = ['npx', 'stylelint', '-c', config, '-i', '.gitignore', '--allow-empty-input', '--color'];
|
|
32
|
+
if (options.fix === true)
|
|
33
|
+
cmd.push('--fix');
|
|
34
|
+
await $ `${cmd} **/*.{css,scss}`;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch { }
|
|
38
|
+
// TypeScript.
|
|
39
|
+
try {
|
|
40
|
+
const config = getFile('tsconfig.json');
|
|
41
|
+
ops.typescript = async () => {
|
|
42
|
+
const cmd = ['npx', 'tsc', '-p', config, '--noEmit', '--pretty'];
|
|
43
|
+
await $ `${cmd}`;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch { }
|
|
47
|
+
// Run all linters in parallel.
|
|
48
|
+
if (type === 'all') {
|
|
49
|
+
const tasks = new Listr([], {
|
|
50
|
+
collectErrors: 'minimal',
|
|
51
|
+
concurrent: true,
|
|
52
|
+
exitOnError: false,
|
|
53
|
+
rendererOptions: { showErrorMessage: false },
|
|
54
|
+
});
|
|
55
|
+
Object.entries(ops).forEach(([title, func]) => {
|
|
56
|
+
tasks.add([{ title, task: async () => func() }]);
|
|
57
|
+
});
|
|
58
|
+
await tasks.run();
|
|
59
|
+
if (tasks.errors.length > 0) {
|
|
60
|
+
tasks.errors.forEach((listrError) => {
|
|
61
|
+
const error = listrError.error;
|
|
62
|
+
let lines = (error.stdout || error.stderr || error.message).trim().split(/\r\n?|\n/);
|
|
63
|
+
if (listrError.task.title.includes('eslint'))
|
|
64
|
+
lines = lines.slice(1, -1);
|
|
65
|
+
console.error(chalk.yellow(`\n${listrError.task.title}`));
|
|
66
|
+
console.error(chalk.yellow(`${'='.repeat(listrError.task.title.length)}\n`));
|
|
67
|
+
console.error(lines.join('\n'));
|
|
68
|
+
});
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Run individual linter.
|
|
73
|
+
else {
|
|
74
|
+
try {
|
|
75
|
+
if (Object.keys(ops).includes(type))
|
|
76
|
+
await ops[type]();
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error(error.stderr || error.stdout || error.message);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { $ } from 'execa';
|
|
2
|
+
export default function execute(app) {
|
|
3
|
+
app
|
|
4
|
+
.command('turbo')
|
|
5
|
+
.description('Run turbo tasks')
|
|
6
|
+
.argument('<task>', 'Task to run')
|
|
7
|
+
.argument('[workspace]', 'Run task on a specific workspace')
|
|
8
|
+
.option('--force', 'Ignore cache')
|
|
9
|
+
.option('--production', 'Use production mode')
|
|
10
|
+
.option('--watch', 'Use watch mode')
|
|
11
|
+
.action(async (task, workspace, options) => {
|
|
12
|
+
const cmd = ['npx', 'turbo', 'run', task];
|
|
13
|
+
const opt = [];
|
|
14
|
+
// Set default workspace when using watch mode.
|
|
15
|
+
if (options.watch && !workspace)
|
|
16
|
+
workspace = '@theme/global';
|
|
17
|
+
if (workspace)
|
|
18
|
+
cmd.push('--filter', workspace);
|
|
19
|
+
if (options.force)
|
|
20
|
+
cmd.push('--force');
|
|
21
|
+
if (!options.production)
|
|
22
|
+
cmd.push('--continue');
|
|
23
|
+
if (options.production)
|
|
24
|
+
opt.push('--production');
|
|
25
|
+
if (options.watch)
|
|
26
|
+
opt.push('--watch');
|
|
27
|
+
await $({ stdio: 'inherit' }) `${cmd} -- ${opt}`;
|
|
28
|
+
});
|
|
29
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function execute(): Promise<void>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import registerBuild from "./commands/build.js";
|
|
3
|
+
import registerLint from "./commands/lint.js";
|
|
4
|
+
import registerTurbo from "./commands/turbo.js";
|
|
5
|
+
export default async function execute() {
|
|
6
|
+
const app = new Command();
|
|
7
|
+
app
|
|
8
|
+
.helpOption('-h, --help', 'Show help')
|
|
9
|
+
.helpCommand(false);
|
|
10
|
+
registerBuild(app);
|
|
11
|
+
registerLint(app);
|
|
12
|
+
registerTurbo(app);
|
|
13
|
+
await app.parseAsync();
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getFile(name: string, rootOnly?: boolean): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
export function getFile(name, rootOnly = false) {
|
|
5
|
+
const root = String(process.env.npm_config_local_prefix || process.env.PWD);
|
|
6
|
+
const workspace = String(process.env.INIT_CWD || process.env.PWD);
|
|
7
|
+
let filepath;
|
|
8
|
+
// Check for workspace-specific file.
|
|
9
|
+
if (!rootOnly && fs.existsSync(path.join(workspace, name)))
|
|
10
|
+
filepath = path.join(workspace, name);
|
|
11
|
+
// Check for root file.
|
|
12
|
+
else if (fs.existsSync(path.join(root, name)))
|
|
13
|
+
filepath = path.join(root, name);
|
|
14
|
+
if (!filepath)
|
|
15
|
+
throw new Error(`Missing ${name} file.`);
|
|
16
|
+
return filepath;
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@imagexmedia/cli",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "The ImageX SWAT CLI package.",
|
|
6
|
+
"author": "ImageX Media",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"bin": {
|
|
14
|
+
"swat": "dist/bin/swat.js",
|
|
15
|
+
"swat-eslint": "dist/bin/swat-eslint.js",
|
|
16
|
+
"swat-stylelint": "dist/bin/swat-stylelint.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"README.md",
|
|
21
|
+
"configs",
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "rm -rf dist && tsc -b && chmod +x dist/bin/*.js && mkdir -p packs && npm pack --pack-destination packs"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"chalk": "^5.6.2",
|
|
29
|
+
"commander": "^14.0.2",
|
|
30
|
+
"execa": "^9.6.1",
|
|
31
|
+
"listr2": "^9.0.5"
|
|
32
|
+
}
|
|
33
|
+
}
|