mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-08 01:46:28 +01:00
feat: init
This commit is contained in:
5
packages/goodwrites-cli/.gitignore
vendored
Normal file
5
packages/goodwrites-cli/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
/node_modules/
|
||||
/*.logs
|
||||
/.yarn/
|
||||
/dist/
|
||||
2
packages/goodwrites-cli/bin/index.js
Executable file
2
packages/goodwrites-cli/bin/index.js
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
require('../dist/index.js');
|
||||
20
packages/goodwrites-cli/package.json
Normal file
20
packages/goodwrites-cli/package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@morten-olsen/goodwrites-cli",
|
||||
"packageManager": "yarn@3.1.0",
|
||||
"bin": {
|
||||
"goodwrites": "./bin/index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"cli": "./bin/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@morten-olsen/goodwrites": "workspace:^",
|
||||
"@morten-olsen/goodwrites-viewer": "workspace:^",
|
||||
"commander": "^9.4.1",
|
||||
"fs-extra": "^11.1.0",
|
||||
"yaml": "^2.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^9.0.13"
|
||||
}
|
||||
}
|
||||
31
packages/goodwrites-cli/src/index.ts
Normal file
31
packages/goodwrites-cli/src/index.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { program } from 'commander';
|
||||
import { resolve, dirname } from 'path';
|
||||
import { createServer } from '@morten-olsen/goodwrites-viewer';
|
||||
import { readFile } from 'fs-extra';
|
||||
import yaml from 'yaml';
|
||||
import { parseDocument } from '@morten-olsen/goodwrites';
|
||||
|
||||
const dev = program.command('dev <file>');
|
||||
dev.action(async (file) => {
|
||||
const fileLocation = resolve(process.cwd(), file);
|
||||
const server = createServer({
|
||||
dev: true,
|
||||
documentLocation: resolve(fileLocation),
|
||||
});
|
||||
server.listen(4005);
|
||||
});
|
||||
|
||||
const build = program.command('build <file>');
|
||||
build.action(async (file) => {
|
||||
const fileLocation = resolve(process.cwd(), file);
|
||||
const location = dirname(fileLocation);
|
||||
const content = await readFile(fileLocation, 'utf-8');
|
||||
const document = yaml.parse(content);
|
||||
const parsed = await parseDocument({
|
||||
document,
|
||||
location,
|
||||
});
|
||||
console.log(parsed.content);
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
9
packages/goodwrites-cli/tsconfig.json
Normal file
9
packages/goodwrites-cli/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"include": [
|
||||
"./src"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user