-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- feature: new cli command: clean, build, dev
- Loading branch information
Showing
31 changed files
with
2,877 additions
and
820 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,4 @@ spike.ts | |
build | ||
dist | ||
*.tgz | ||
src/code-object/*.ts | ||
src/core/*.ts | ||
src/dsl/*.ts | ||
src/plug-in/*.ts | ||
src/transcript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,72 @@ | ||
#!/usr/bin/env node | ||
import * as program from "commander"; | ||
import { | ||
ComposeFile, | ||
ComposeDirectory, | ||
InspectDirectory, | ||
InspectFile, | ||
ITypeDraftConfig, | ||
} from "./literator"; | ||
import { ComposeFile } from "./literator"; | ||
import { resolve } from "path"; | ||
import { readJSONSync, lstatSync } from "fs-extra"; | ||
import { cosmiconfig } from "cosmiconfig"; | ||
import { default as tsLoader } from "@endemolshinegroup/cosmiconfig-typescript-loader"; | ||
import { readJSONSync } from "fs-extra"; | ||
import { build, clean, dev, IDevConfig } from "cli-common"; | ||
import { withConfig } from "./cosmiconfig"; | ||
|
||
const package_json = readJSONSync(resolve(__dirname, "../../package.json")); | ||
program.version(package_json.version); | ||
program.option("-w, --watch", "compose file or files in directory in watch mode"); | ||
program.parse(process.argv); | ||
|
||
const args = program.args; | ||
|
||
if (args.length === 0) { | ||
program.command("help").action(() => { | ||
program.help(); | ||
} else { | ||
const working_directory = process.cwd(); | ||
const [target] = args; | ||
if (target) { | ||
const path = resolve(working_directory, target); | ||
}); | ||
|
||
// find config | ||
const explorer = cosmiconfig("typedraft", { | ||
searchPlaces: [`typedraft.config.ts`], | ||
loaders: { | ||
".ts": tsLoader, | ||
}, | ||
program.command("dev").action(() => { | ||
withConfig(config => { | ||
config.Targets.forEach(({ src, dest, baseDir }) => { | ||
const devConfig: IDevConfig = { | ||
rename: { | ||
extension: ".ts", | ||
}, | ||
transform(path, code) { | ||
if (path.endsWith(".tsx")) { | ||
const result = ComposeFile(code, config); | ||
return result; | ||
} else { | ||
return code; | ||
} | ||
}, | ||
}; | ||
if (baseDir) { | ||
devConfig.baseDir = baseDir; | ||
} | ||
dev(src, dest, devConfig); | ||
}); | ||
}); | ||
}); | ||
|
||
explorer.search().then(config_info => { | ||
let config: ITypeDraftConfig = { DSLs: [], DraftPlugins: [] }; | ||
if (config_info && !config_info.isEmpty) { | ||
config = { ...config, ...config_info.config }; | ||
program.command("build").action(() => { | ||
withConfig(config => { | ||
config.Targets.forEach(({ src, dest, baseDir }) => { | ||
const devConfig: IDevConfig = { | ||
rename: { | ||
extension: ".ts", | ||
}, | ||
transform(path, code) { | ||
if (path.endsWith(".tsx")) { | ||
const result = ComposeFile(code, config); | ||
return result; | ||
} else { | ||
return code; | ||
} | ||
}, | ||
}; | ||
if (baseDir) { | ||
devConfig.baseDir = baseDir; | ||
} | ||
build(src, dest, devConfig); | ||
}); | ||
}); | ||
}); | ||
|
||
// | ||
if (lstatSync(path).isDirectory()) { | ||
program.watch ? InspectDirectory(path, config) : ComposeDirectory(path, config); | ||
} else { | ||
program.watch ? InspectFile(path, config) : ComposeFile(path, config); | ||
} | ||
program.command("clean").action(() => { | ||
withConfig(config => { | ||
config.Targets.forEach(({ dest }) => { | ||
clean(dest); | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
program.parse(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env node | ||
import { ITypeDraftConfig } from "./literator"; | ||
import { cosmiconfig } from "cosmiconfig"; | ||
import { default as tsLoader } from "@endemolshinegroup/cosmiconfig-typescript-loader"; | ||
|
||
// find config | ||
const explorer = cosmiconfig("typedraft", { | ||
searchPlaces: [`typedraft.config.ts`], | ||
loaders: { | ||
".ts": tsLoader, | ||
}, | ||
}); | ||
|
||
export function withConfig(callback: (config: ITypeDraftConfig) => void) { | ||
explorer.search().then(configInfo => { | ||
let config: ITypeDraftConfig = { DSLs: [], DraftPlugins: [], Targets: [] }; | ||
if (configInfo && !configInfo.isEmpty) { | ||
config = { ...config, ...configInfo.config }; | ||
} | ||
callback(config); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 13 additions & 22 deletions
35
src/code-object/export-class.tsx → draft/code-object/export-class.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,30 @@ | ||
/** | ||
* # Export Class | ||
* Exported class will be represented as `ExportClassCode`: | ||
*/ | ||
import { ExportNamedDeclaration, ClassDeclaration, ClassMethod } from "@babel/types"; | ||
import { NodePath } from "@babel/core"; | ||
|
||
export class ExportClassCode { | ||
m_Path: NodePath<ExportNamedDeclaration>; | ||
|
||
constructor(path: NodePath<ExportNamedDeclaration>) { | ||
this.m_Path = path; | ||
} | ||
|
||
get m_Code() { | ||
return this.m_Path.node; | ||
} | ||
|
||
get m_Class() { | ||
return this.m_Code.declaration as ClassDeclaration; | ||
} | ||
|
||
get m_Members() { | ||
return this.m_Class.body.body; | ||
} | ||
|
||
get m_Name() { | ||
return this.m_Class.id.name as string; | ||
} | ||
} | ||
|
||
/** | ||
* ## AddMember | ||
*/ | ||
<ExportClassCode /> + | ||
function AddMember(this: ExportClassCode, member: ClassMethod) { | ||
AddMember(member: ClassMethod) { | ||
this.m_Members.push(member); | ||
}; | ||
|
||
/** | ||
* # Trivial | ||
*/ | ||
<ExportClassCode /> + | ||
function constructor(this: ExportClassCode, path: NodePath<ExportNamedDeclaration>) { | ||
this.m_Path = path; | ||
}; | ||
|
||
import { ExportNamedDeclaration, ClassDeclaration, ClassMethod } from "@babel/types"; | ||
import { NodePath } from "@babel/core"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from "./export-class"; | ||
export * from "./inline-context"; | ||
export * from "./local-context"; | ||
export * from "./method"; | ||
export * from "./module"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.