Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): initial commit for cli - it runs but still issues with goo… #2

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/xyd-cli/bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

import './dist/index.js';
15 changes: 15 additions & 0 deletions packages/xyd-cli/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node

import {run} from "./src/run";

console.log("test")

run().then(
() => {
process.exit(0);
},
(error: unknown) => {
if (error) console.error(error);
process.exit(1);
}
);
28 changes: 28 additions & 0 deletions packages/xyd-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@xydjs/cli",
"version": "0.0.1-pre.0",
"keywords": [],
"author": "",
"description": "",
"type": "module",
"main": "./dist/index.js",
"bin": {
"xyd": "bin.js"
},
"files": [
"dist/",
"bin.js",
"README.md"
],
"scripts": {
"build": "tsup"
},
"dependencies": {
"@xyd/documan": "workspace:*",
"arg": "^5.0.2",
"colors": "^1.4.0",
"semver": "^7.6.3"
},
"devDependencies": {
}
}
5 changes: 5 additions & 0 deletions packages/xyd-cli/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pnpm run build

pnpm link --global

xyd
13 changes: 13 additions & 0 deletions packages/xyd-cli/src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as documan from "@xyd/documan"

export async function build(root: string, options: any = {}) {

}

export async function dev(root: string, options: any = {}) {
await documan.dev()

// keep `xyd dev` alive
await new Promise(() => {
});
}
99 changes: 99 additions & 0 deletions packages/xyd-cli/src/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import arg from "arg";
import semver from "semver";
import colors from "picocolors";

import * as commands from "./commands";

const helpText = `
${colors.blueBright("xyd")}

${colors.underline("Usage")}:
$ xyd build [${colors.yellowBright("projectDir")}]
$ xyd dev [${colors.yellowBright("projectDir")}]

${colors.underline("Options")}:
--help, -h Print this help message and exit
--version, -v Print the CLI version and exit
--no-color Disable ANSI colors in console output
\`build\` Options:
--logLevel, -l Info | warn | error | silent (string)
\`dev\` Options:
--port Specify port (number)

${colors.underline("Build your project")}:

$ xyd build

${colors.underline("Run your project locally in development")}:

$ xyd dev
`;

/**
* Programmatic interface for running the xyd CLI with the given command line
* arguments.
*/
export async function run(argv: string[] = process.argv.slice(2)) {
// Check the node version
let versions = process.versions;
let MINIMUM_NODE_VERSION = 20;
if (
versions &&
versions.node &&
semver.major(versions.node) < MINIMUM_NODE_VERSION
) {
console.warn(
`️⚠️ Oops, Node v${versions.node} detected. xyd requires ` +
`a Node version greater than ${MINIMUM_NODE_VERSION}.`
);
}

let args = arg(
{
"--help": Boolean,
"-h": "--help",
"--version": Boolean,
"-v": "--version",
"--port": Number,
"-p": "--port",
"--logLevel": String,
"-l": "--logLevel",
},
{
argv,
}
);

let input = args._;

let flags: any = Object.entries(args).reduce((acc, [key, value]) => {
key = key.replace(/^--/, "");
acc[key] = value;
return acc;
}, {} as any);

if (flags.help) {
console.log(helpText);
return;
}
if (flags.version) {
let version = require("../package.json").version;
console.log(version);
return;
}

let command = input[0];

// Note: Keep each case in this switch statement small.
switch (command) {
case "build":
await commands.build(input[1], flags);
break;
case "dev":
await commands.dev(input[1], flags);
break;
default:
// `xyd ./my-project` is shorthand for `xyd dev ./my-project`
await commands.dev(input[0], flags);
}
}
24 changes: 24 additions & 0 deletions packages/xyd-cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist",
"declaration": true,
"declarationMap": true,
"incremental": true,
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo"
},
"include": [
"index.ts",
"src/**/*.ts"
],
"exclude": [
"node_modules",
"dist"
]
}
81 changes: 81 additions & 0 deletions packages/xyd-cli/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// import * as fsp from "fs/promises";

import {defineConfig} from "tsup";

// import {createBanner} from "../../build.utils.js";
// import pkg from "./package.json";

const entry = ["index.ts"];

const external = [];

export default defineConfig([
{
clean: true,
bundle: true,
entry,
format: ['esm'], // Output both ESM and CJS formats
outDir: "dist",
dts: true,
external,
// banner: {
// js: createBanner(pkg.name, pkg.version),
// },
plugins: [],
},
]);

// export default defineConfig({
// // // TODO: does not work
// // // format: ['esm'],
// // // entry: ['./index.ts'],
// // // dts: false,
// // // shims: true,
// // // skipNodeModulesBundle: true,
// // // clean: true,
// // // target: 'node20',
// // // platform: 'node',
// // // minify: true,
// // // bundle: true,
// // // external: [
// // // "lightningcss"
// // // ],
// // // // https://github.com/egoist/tsup/issues/619
// // // noExternal: [/(.*)/, "lightningcss"],
// // // splitting: false,
// //
// // // format: ["esm"],
// // // entry: ['./index.ts'],
// // // platform: 'node',
// // // shims: false,
// // // splitting: false,
// // // sourcemap: true,
// // // clean: true,
// // // external: [
// // // // "lightningcss"
// // // ],
// //
// //
// format: ["esm"],
// entry: ['./index.ts'],
// platform: 'node',
// shims: false,
// splitting: false,
// sourcemap: true,
// clean: true,
// bundle: true, // Enable bundling
// external: [
// "lightningcss",
// "vite",
// "vite-tsconfig-paths",
// "react-router",
// "@react-router/serve",
// "@react-router/dev",
// "@mdx-js/rollup",
// "@graphql-markdown",
//
// "@xydjs/react-router-dev",
// "@xyd/documan",
// "@xyd/openapi",
// ], // Ensure no dependencies are marked as external
// });
28 changes: 28 additions & 0 deletions packages/xyd-components/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {defineConfig} from 'tsup';

export default defineConfig({
entry: {
index: 'index.ts',
wiki: 'src/wiki.ts',
content: 'src/content.ts'
},
format: ['esm'], // Output both ESM and CJS formats
target: 'node16', // Ensure compatibility with Node.js 16
dts: {
entry: {
index: 'index.ts',
wiki: 'src/wiki.ts',
content: 'src/content.ts'
},
resolve: true, // Resolve external types
},
splitting: false, // Disable code splitting
sourcemap: true, // Generate source maps
clean: true, // Clean the output directory before each build
esbuildOptions: (options) => {
options.platform = 'node'; // Ensure the platform is set to Node.js
options.external = ['node:fs/promises']; // Mark 'node:fs/promises' as external
options.loader = {'.js': 'jsx'}; // Ensure proper handling of .js files
},
ignoreWatch: ['node_modules', 'dist', '.git', 'build'] // Exclude unnecessary directories
});
2 changes: 1 addition & 1 deletion packages/xyd-core/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {defineConfig, Options} from 'tsup';

const config: Options = {
entry: ['index.ts'],
format: ['esm', 'cjs'], // Output both ESM and CJS formats
format: ['esm'], // Output both ESM and CJS formats
target: 'node16', // Ensure compatibility with Node.js 16
dts: {
entry: 'index.ts', // Specify the entry for DTS
Expand Down
8 changes: 5 additions & 3 deletions packages/xyd-documan-example/docs/api/graphql/createTodo.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
title: Create Todo
---
## !!references createTodo

### !canonical createTodo
## !description


Create a new todo

## !!references createTodo

### !canonical createTodo

### !category graphql

### !type graphql_mutation
Expand Down
8 changes: 5 additions & 3 deletions packages/xyd-documan-example/docs/api/graphql/createUser.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
title: Create User
---
## !!references createUser

### !canonical createUser
## !description


Create a new user

## !!references createUser

### !canonical createUser

### !category graphql

### !type graphql_mutation
Expand Down
8 changes: 5 additions & 3 deletions packages/xyd-documan-example/docs/api/graphql/deleteTodo.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
title: Delete Todo
---
## !!references deleteTodo

### !canonical deleteTodo
## !description


Delete a todo by ID

## !!references deleteTodo

### !canonical deleteTodo

### !category graphql

### !type graphql_mutation
Expand Down
8 changes: 5 additions & 3 deletions packages/xyd-documan-example/docs/api/graphql/todo.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
title: Todo
---
## !!references todo

### !canonical todo
## !description


Get a todo by ID

## !!references todo

### !canonical todo

### !category graphql

### !type graphql_query
Expand Down
Loading