@shipcli/create 0.1.0
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/package.json +15 -0
- package/src/index.js +66 -0
- package/templates/.github/workflows/ci.yml.tpl +17 -0
- package/templates/.github/workflows/release.yml.tpl +22 -0
- package/templates/gitignore.tpl +7 -0
- package/templates/package.json.tpl +15 -0
- package/templates/shipcli.config.js.tpl +13 -0
- package/templates/src/cli.js.tpl +18 -0
- package/templates/src/commands/index.js.tpl +14 -0
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shipcli/create",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scaffold a new CLI tool powered by shipcli",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-shipcli": "./src/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": ["src", "templates"],
|
|
10
|
+
"keywords": ["cli", "scaffold", "create", "shipcli"],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"kleur": "^4.1.5"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { mkdirSync, writeFileSync, readFileSync, readdirSync, statSync } from "fs";
|
|
4
|
+
import { join, dirname, relative } from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import kleur from "kleur";
|
|
7
|
+
|
|
8
|
+
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
var TEMPLATES_DIR = join(__dirname, "..", "templates");
|
|
10
|
+
|
|
11
|
+
var args = process.argv.slice(2);
|
|
12
|
+
var name = args[0];
|
|
13
|
+
|
|
14
|
+
if (!name) {
|
|
15
|
+
console.error(kleur.red("Usage: create-shipcli <name>"));
|
|
16
|
+
console.error(kleur.dim(" Example: npx create-shipcli codeautopsy"));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var description = args[1] || `A CLI tool built with shipcli`;
|
|
21
|
+
var share = true;
|
|
22
|
+
|
|
23
|
+
console.log(`\n${kleur.bold().cyan("==>")} ${kleur.bold(`Creating ${name}...`)}\n`);
|
|
24
|
+
|
|
25
|
+
var outDir = join(process.cwd(), name);
|
|
26
|
+
mkdirSync(outDir, { recursive: true });
|
|
27
|
+
|
|
28
|
+
function processTemplates(dir, outBase) {
|
|
29
|
+
var entries = readdirSync(dir);
|
|
30
|
+
for (var entry of entries) {
|
|
31
|
+
var srcPath = join(dir, entry);
|
|
32
|
+
var stat = statSync(srcPath);
|
|
33
|
+
|
|
34
|
+
if (stat.isDirectory()) {
|
|
35
|
+
var subOut = join(outBase, entry);
|
|
36
|
+
mkdirSync(subOut, { recursive: true });
|
|
37
|
+
processTemplates(srcPath, subOut);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!entry.endsWith(".tpl")) continue;
|
|
42
|
+
|
|
43
|
+
var content = readFileSync(srcPath, "utf-8");
|
|
44
|
+
content = content
|
|
45
|
+
.replace(/\{\{name\}\}/g, name)
|
|
46
|
+
.replace(/\{\{description\}\}/g, description)
|
|
47
|
+
.replace(/\{\{share\}\}/g, String(share));
|
|
48
|
+
|
|
49
|
+
var outName = entry.replace(".tpl", "");
|
|
50
|
+
// gitignore → .gitignore
|
|
51
|
+
if (outName === "gitignore") outName = ".gitignore";
|
|
52
|
+
|
|
53
|
+
var outPath = join(outBase, outName);
|
|
54
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
55
|
+
writeFileSync(outPath, content);
|
|
56
|
+
console.log(` ${kleur.dim("created")} ${relative(outDir, outPath)}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
processTemplates(TEMPLATES_DIR, outDir);
|
|
61
|
+
|
|
62
|
+
console.log(`\n${kleur.green("-->")} ${kleur.bold(name)} created!\n`);
|
|
63
|
+
console.log(` ${kleur.dim("Next steps:")}`);
|
|
64
|
+
console.log(` cd ${name}`);
|
|
65
|
+
console.log(` npm install`);
|
|
66
|
+
console.log(` node src/cli.js --help\n`);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [main]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
|
+
with:
|
|
15
|
+
node-version: "20"
|
|
16
|
+
- run: npm install
|
|
17
|
+
- run: npm test
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
tags: ["v*"]
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
publish:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
id-token: write
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: "20"
|
|
17
|
+
registry-url: "https://registry.npmjs.org"
|
|
18
|
+
- run: npm install
|
|
19
|
+
- run: npm test
|
|
20
|
+
- run: npm publish --provenance --access public
|
|
21
|
+
env:
|
|
22
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "{{description}}",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"{{name}}": "./src/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": ["src"],
|
|
10
|
+
"keywords": ["cli", "{{name}}"],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@shipcli/core": "^0.1.0"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
name: "{{name}}",
|
|
3
|
+
description: "{{description}}",
|
|
4
|
+
share: {
|
|
5
|
+
enabled: {{share}},
|
|
6
|
+
// OG image template configuration
|
|
7
|
+
// card: "./src/share/card.jsx",
|
|
8
|
+
},
|
|
9
|
+
landing: {
|
|
10
|
+
enabled: false,
|
|
11
|
+
footer: "Built with shipcli",
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createCLI } from "@shipcli/core/cli";
|
|
4
|
+
import { run } from "./commands/index.js";
|
|
5
|
+
|
|
6
|
+
var cli = createCLI({
|
|
7
|
+
name: "{{name}}",
|
|
8
|
+
description: "{{description}}",
|
|
9
|
+
version: "0.1.0",
|
|
10
|
+
configDir: ".{{name}}",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
cli
|
|
14
|
+
.argument("[target]", "Target to analyze")
|
|
15
|
+
.option("--share", "Generate shareable output")
|
|
16
|
+
.action(run);
|
|
17
|
+
|
|
18
|
+
cli.run();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { phase, status, success, fmt } from "@shipcli/core/output";
|
|
2
|
+
|
|
3
|
+
export async function run(target, options) {
|
|
4
|
+
phase(`Analyzing ${fmt.app(target || ".")}`);
|
|
5
|
+
status("Scanning...");
|
|
6
|
+
|
|
7
|
+
// Your CLI logic here
|
|
8
|
+
|
|
9
|
+
success("Done!");
|
|
10
|
+
|
|
11
|
+
if (options.json) {
|
|
12
|
+
console.log(JSON.stringify({ target, status: "ok" }, null, 2));
|
|
13
|
+
}
|
|
14
|
+
}
|