@journeyapps/cloudcode-build
Advanced tools
Comparing version 0.0.1-dev7 to 1.9.1-dev.953da0e.49da882
@@ -8,7 +8,10 @@ #!/usr/bin/env node | ||
const ProcessError_1 = require("./ProcessError"); | ||
// path to /schema.xml from /cloudcode/task | ||
const DEFAULT_SCHEMA_PATH = '../../schema.xml'; | ||
const DEFAULT_DATAMODEL_OUT = 'gen/datamodel.d.ts'; | ||
yargs | ||
.command('build', 'build a task', yargs => { | ||
return yargs.option('datamodel', { default: '../../schema.xml' }); | ||
return yargs.option('datamodel', { default: DEFAULT_SCHEMA_PATH }); | ||
}, handled(async (argv) => { | ||
await datamodel_1.fileToDefinitions(argv.datamodel, 'gen/datamodel.d.ts'); | ||
await datamodel_1.fileToDefinitions(argv.datamodel, DEFAULT_DATAMODEL_OUT); | ||
await build_1.buildTypescript(); | ||
@@ -18,4 +21,4 @@ })) | ||
return yargs | ||
.option('datamodel', { default: '../../schema.xml' }) | ||
.option('out', { default: 'gen/datamodel.d.ts' }); | ||
.option('datamodel', { default: DEFAULT_SCHEMA_PATH }) | ||
.option('out', { default: DEFAULT_DATAMODEL_OUT }); | ||
}, handled(async (argv) => { | ||
@@ -22,0 +25,0 @@ await datamodel_1.fileToDefinitions(argv.datamodel, argv.out); |
@@ -49,11 +49,20 @@ "use strict"; | ||
} | ||
function indent(levels, text) { | ||
let lines; | ||
if (typeof text == 'string') { | ||
lines = text.trim().split('\n'); | ||
function trimEnd(line) { | ||
let i = line.length; | ||
while (i > 0) { | ||
if (line.charAt(i - 1) == ' ') { | ||
i -= 1; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
else { | ||
lines = text; | ||
return line.substring(0, i); | ||
} | ||
function indent(text, levels = 1) { | ||
if (Array.isArray(text)) { | ||
return indent(text.join('\n'), levels); | ||
} | ||
return lines.map(line => indentation(levels) + line.trim()).join('\n'); | ||
const lines = text.split('\n'); | ||
return lines.map(line => trimEnd(indentation(levels) + line)).join('\n'); | ||
} | ||
@@ -82,6 +91,6 @@ async function schemaToDefinitions(schema) { | ||
const modelTs = ` | ||
interface ${modelName} extends DatabaseObject { | ||
${indent(3, attrs)} | ||
} | ||
`; | ||
interface ${modelName} extends DatabaseObject { | ||
${indent(attrs)} | ||
} | ||
`.trim() + '\n'; | ||
models.push(modelTs); | ||
@@ -105,7 +114,7 @@ } | ||
export interface AppDatabase extends Database { | ||
${modelNames.map(name => `${name}: Collection<AppDatabase.${name}>;`).join('\n ')} | ||
${indent(modelNames.map(name => `${name}: Collection<AppDatabase.${name}>;`))} | ||
} | ||
declare namespace AppDatabase { | ||
${models.join('\n\n ')} | ||
${indent(models)} | ||
} | ||
@@ -112,0 +121,0 @@ |
{ | ||
"name": "@journeyapps/cloudcode-build", | ||
"version": "0.0.1-dev7", | ||
"version": "1.9.1-dev.953da0e.49da882", | ||
"main": "index.js", | ||
@@ -29,3 +29,4 @@ "license": "MIT", | ||
"lib" | ||
] | ||
], | ||
"gitHead": "cbcd524e6ba92643c33ce23a8c5d7942dddb6021" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14785
18
232