feat(cli): initial cli package
This commit is contained in:
parent
7f1d6ce140
commit
4ac710ca69
10 changed files with 536 additions and 1199 deletions
1573
package-lock.json
generated
1573
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -13,6 +13,7 @@
|
|||
"packages/create-mcfly",
|
||||
"templates/basic",
|
||||
"packages/core",
|
||||
"site"
|
||||
"site",
|
||||
"packages/cli"
|
||||
]
|
||||
}
|
||||
|
|
21
packages/cli/LICENSE
Normal file
21
packages/cli/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2021 Ayo Ayco
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
26
packages/cli/README.md
Normal file
26
packages/cli/README.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
# McFly CLI
|
||||
|
||||
|
||||
The **McFly CLI** is the command-line tooling for [McFly](https://ayco.io/gh/McFly) -- a no-framework framework that assists in leveraging the web platform.
|
||||
|
||||
## Installation
|
||||
|
||||
Install the CLI using npm:
|
||||
|
||||
```
|
||||
npm i -g @mcflyjs/cli
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Commands
|
||||
|
||||
You can the following commands
|
||||
|
||||
| Command | Action |
|
||||
| --- | --- |
|
||||
| `mcfly prepare` | prepare the development environment |
|
||||
|
||||
---
|
||||
*Just keep building*<br />
|
||||
*A project by [Ayo Ayco](https://ayco.io)*
|
5
packages/cli/commands/generate.js
Normal file
5
packages/cli/commands/generate.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const { consola } = require("consola");
|
||||
|
||||
consola.prompt("Name your new custom element");
|
25
packages/cli/commands/new.mjs
Normal file
25
packages/cli/commands/new.mjs
Normal file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import { execSync as exec } from "node:child_process";
|
||||
import { consola } from "consola";
|
||||
import { defineCommand } from "citty";
|
||||
import { commonArgs } from "../common.mjs";
|
||||
|
||||
export default defineCommand({
|
||||
meta: {
|
||||
name: "prepare",
|
||||
description: "Generate types for the project",
|
||||
},
|
||||
args: {
|
||||
...commonArgs,
|
||||
},
|
||||
async run({ args }) {
|
||||
const [directory] = args._;
|
||||
consola.info(directory);
|
||||
// try {
|
||||
// exec("npm create mcfly@latest", { stdio: "inherit" });
|
||||
// } catch (e) {
|
||||
// consola.error(e);
|
||||
// }
|
||||
},
|
||||
});
|
24
packages/cli/commands/prepare.js
Executable file
24
packages/cli/commands/prepare.js
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const { existsSync, writeFileSync, appendFileSync } = require("node:fs");
|
||||
|
||||
const typeDefinition = `\n/// <reference path="./mcfly-imports.d.ts" />`;
|
||||
const globalDefinition = `import {WebComponent as W} from "web-component-base/WebComponent.mjs"; declare global {const WebComponent: typeof W;}export {WebComponent};`;
|
||||
|
||||
if (existsSync(".nitro/types/nitro.d.ts")) {
|
||||
console.log("has directory");
|
||||
try {
|
||||
writeFileSync(".nitro/types/mcfly-imports.d.ts", globalDefinition);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
try {
|
||||
appendFileSync(".nitro/types/nitro.d.ts", typeDefinition);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
"Preparation Failed. Please run:\n> npx nitropack prepare && npx mcfly prepare"
|
||||
);
|
||||
}
|
14
packages/cli/common.mjs
Normal file
14
packages/cli/common.mjs
Normal file
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* @type {import('citty').ArgsDef}
|
||||
*/
|
||||
export const commonArgs = {
|
||||
dir: {
|
||||
type: "string",
|
||||
description: "project root directory",
|
||||
},
|
||||
_dir: {
|
||||
type: "positional",
|
||||
default: ".",
|
||||
description: "project root directory (prefer using `--dir`)",
|
||||
},
|
||||
};
|
18
packages/cli/index.js
Executable file
18
packages/cli/index.js
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env node
|
||||
const { defineCommand, runMain } = require("citty");
|
||||
const pkg = require("./package.json");
|
||||
|
||||
const main = defineCommand({
|
||||
meta: {
|
||||
name: "mcfly",
|
||||
description: "McFly CLI",
|
||||
version: pkg.version,
|
||||
},
|
||||
subCommands: {
|
||||
prepare: () => import("./commands/prepare.js").then((r) => r.default),
|
||||
generate: () => import("./commands/generate.js").then((r) => r.default),
|
||||
new: () => import("./commands/new.mjs").then((r) => r.default),
|
||||
},
|
||||
});
|
||||
|
||||
runMain(main);
|
26
packages/cli/package.json
Normal file
26
packages/cli/package.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "@mcflyjs/cli",
|
||||
"version": "0.0.1",
|
||||
"description": "McFly CLI tools",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"mcfly": "./index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ayoayco/McFly.git"
|
||||
},
|
||||
"author": "Ayo Ayco",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ayoayco/McFly/issues"
|
||||
},
|
||||
"homepage": "https://github.com/ayoayco/McFly#readme",
|
||||
"dependencies": {
|
||||
"citty": "^0.1.4",
|
||||
"consola": "^3.2.3"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue