Skip to content

Commit 5bd7681

Browse files
committed
simplify templates for singleton
1 parent 02417a1 commit 5bd7681

File tree

4 files changed

+403
-20
lines changed

4 files changed

+403
-20
lines changed

entrypoint.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,22 @@ function writeTemplateFile(tplFile, data, outputDir, outputFile, writeConfig) {
103103
const config = JSON.parse(template.render(data, {}));
104104
let dataFile = buildTemplateFile(data, config.input)
105105
if (!argv.simple) {
106-
const templateFilePath = path.resolve(".project-template", writeConfig.env, config.output)
106+
const templateFilePath = path.resolve(".template", config.output)
107107
if (fs.existsSync(templateFilePath)) {
108108
dataFile = buildTemplateFile(data, templateFilePath)
109+
const templateEnvFilePath = path.resolve(".template", `${config.output}.${writeConfig.env}`)
110+
if (fs.existsSync(templateEnvFilePath)) {
111+
dataFile = buildTemplateFile(data, templateEnvFilePath)
112+
}
109113
} else {
110-
const templatePath = path.dirname(path.resolve(templateFilePath))
111-
if (!fs.existsSync(templatePath)) {
112-
mkdirp.sync(templatePath);
114+
const templateEnvFilePath = path.resolve(".template", `${config.output}.${writeConfig.env}`)
115+
if (fs.existsSync(templateEnvFilePath)) {
116+
dataFile = buildTemplateFile(data, templateEnvFilePath)
117+
} else {
118+
const templatePath = path.dirname(path.resolve(templateFilePath))
119+
if (!fs.existsSync(templatePath)) {
120+
mkdirp.sync(templatePath);
121+
}
113122
}
114123
}
115124
}
@@ -270,8 +279,8 @@ yargs.usage('simplify-graphql [template] [options]')
270279
.string('env')
271280
.alias('e', 'env')
272281
.describe('env', 'Environment')
273-
.boolean('simple')
274-
.describe('simple', 'Generate simple code files')
282+
.string('mode')
283+
.describe('mode', 'Generate singleton|multiple code base')
275284
.boolean('merge')
276285
.describe('merge', 'Auto merge files')
277286
.boolean('diff')
@@ -382,9 +391,9 @@ function parseDefaultObjectValue(rootObject, vObj) {
382391

383392
function mainProcessor(typeDefs, schema, projectInfo) {
384393
const templatePath = require("simplify-templates")
385-
const templates = path.join(templatePath, argv.simple ? "graphql-code" : "graphql")
386-
const gqlConfig = require(path.join(templatePath, argv.simple ? "config-graphcode.json" : "config-graphql.json"))
387-
const rootObject = hoganFlatter(schemaParser(typeDefs))
394+
const templates = path.join(templatePath, "graphql")
395+
const gqlConfig = require(path.join(templatePath, argv.mode == "singleton" ? "config-graphql-singleton.json" : "config-graphql.json"))
396+
const rootObject = hoganFlatter(schemaParser(typeDefs), argv.mode == "singleton")
388397
const outputDir = projectInfo.ProjectOutput || '.'
389398
argv.verbose && console.log("Generating Verbal GASM Design Language... (design.txt)")
390399
rootObject.DataTables = []

0 commit comments

Comments
 (0)