@journeyapps/cloudcode-build
Advanced tools
Comparing version 1.9.1 to 1.9.3-dev.341bb23.99cb637
@@ -5,5 +5,3 @@ #!/usr/bin/env node | ||
const yargs = require("yargs"); | ||
const datamodel_1 = require("./datamodel"); | ||
const build_1 = require("./build"); | ||
const ProcessError_1 = require("./ProcessError"); | ||
const _1 = require("./"); | ||
// path to /schema.xml from /cloudcode/task | ||
@@ -17,4 +15,4 @@ const DEFAULT_SCHEMA_PATH = '../../schema.xml'; | ||
}, handled(async (argv) => { | ||
await datamodel_1.fileToDefinitions(argv.datamodel, DEFAULT_DATAMODEL_OUT); | ||
await build_1.buildTypescript(); | ||
await _1.fileToDefinitions(argv.datamodel, DEFAULT_DATAMODEL_OUT); | ||
await _1.buildTypescript(); | ||
})) | ||
@@ -26,3 +24,3 @@ .command('datamodel', 'build the datamodel', yargs => { | ||
}, handled(async (argv) => { | ||
await datamodel_1.fileToDefinitions(argv.datamodel, argv.out); | ||
await _1.fileToDefinitions(argv.datamodel, argv.out); | ||
})) | ||
@@ -39,3 +37,3 @@ .option('verbose', { | ||
catch (err) { | ||
if (err instanceof ProcessError_1.ProcessError) { | ||
if (err instanceof _1.ProcessError) { | ||
console.error(err.message); | ||
@@ -42,0 +40,0 @@ process.exit(err.status); |
import { Schema } from 'journeyapps/lib/app/schema'; | ||
export declare function fileToDefinitions(datamodelPath: string, outPath: string): Promise<void>; | ||
export declare function schemaToDefinitions(schema: Schema): Promise<string>; | ||
export declare function schemaToDefinitions(schema: Schema): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs = require("fs"); | ||
const schema_1 = require("journeyapps/lib/app/schema"); | ||
const version_1 = require("journeyapps/lib/app/version"); | ||
const path = require("path"); | ||
const TYPE_MAP = { | ||
@@ -14,4 +10,4 @@ text: 'string', | ||
number: 'number', | ||
date: 'Date', | ||
datetime: 'Day', | ||
date: 'Day', | ||
datetime: 'Date', | ||
'multiple-choice-integer': 'number[]', | ||
@@ -31,14 +27,2 @@ 'multiple-choice': 'string[]', | ||
} | ||
async function fileToDefinitions(datamodelPath, outPath) { | ||
const data = await fs.readFileSync(datamodelPath, 'utf-8'); | ||
const schema = new schema_1.Schema(); | ||
schema.loadXml(data, { apiVersion: new version_1.Version('4.0') }); | ||
const ts = await schemaToDefinitions(schema); | ||
const dir = path.dirname(outPath); | ||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir); | ||
} | ||
fs.writeFileSync(outPath, ts); | ||
} | ||
exports.fileToDefinitions = fileToDefinitions; | ||
function indentation(levels) { | ||
@@ -70,3 +54,3 @@ let r = ''; | ||
} | ||
async function schemaToDefinitions(schema) { | ||
function schemaToDefinitions(schema) { | ||
const models = []; | ||
@@ -86,7 +70,7 @@ const modelNames = Object.keys(schema.objects); | ||
let rel = model.belongsTo[relName]; | ||
attrs.push(`/** Lookup related ${rel.foreignType.label}. */`, `${relName}(): Promise<AppDatabase.${rel.foreignType.name}>;`, `/** Set related ${rel.foreignType.label}. */`, `${relName}(value: AppDatabase.${rel.foreignType.name}): void;`, `/** ID of related ${rel.foreignType.label}. */`, `${relName}_id: string;`); | ||
attrs.push(`/** Lookup related ${rel.foreignType.label}. */`, `${relName}(): Promise<DB.${rel.foreignType.name}>;`, `/** Set related ${rel.foreignType.label}. */`, `${relName}(value: DB.${rel.foreignType.name}): void;`, `/** ID of related ${rel.foreignType.label}. */`, `${relName}_id: string;`); | ||
} | ||
for (let relName in model.hasMany) { | ||
let rel = model.hasMany[relName]; | ||
attrs.push(`/** Query for related ${rel.objectType.label}. */`, `readonly ${relName}: Query<AppDatabase.${rel.objectType.name}>;`); | ||
attrs.push(`/** Query for related ${rel.objectType.label}. */`, `readonly ${relName}: Query<DB.${rel.objectType.name}>;`); | ||
} | ||
@@ -115,12 +99,14 @@ const modelTs = ` | ||
export interface AppDatabase extends Database { | ||
${indent(modelNames.map(name => `${name}: Collection<AppDatabase.${name}>;`))} | ||
interface DB extends Database { | ||
${indent(modelNames.map(name => `${name}: Collection<DB.${name}>;`))} | ||
} | ||
declare namespace AppDatabase { | ||
${indent(models)} | ||
} | ||
declare global { | ||
const DB: AppDatabase; | ||
namespace DB { | ||
${indent(models, 2)} | ||
} | ||
const DB: DB; | ||
} | ||
@@ -127,0 +113,0 @@ |
@@ -1,4 +0,5 @@ | ||
import { fileToDefinitions } from './datamodel'; | ||
import { schemaToDefinitions } from './datamodel'; | ||
import { buildTypescript } from './build'; | ||
export { fileToDefinitions, buildTypescript }; | ||
import { ProcessError } from './ProcessError'; | ||
export { buildTypescript, ProcessError, schemaToDefinitions }; | ||
export interface BuildOptions { | ||
@@ -8,1 +9,2 @@ datamodel: string; | ||
export declare function buildTask(taskPath: string, options?: Partial<BuildOptions>): Promise<void>; | ||
export declare function fileToDefinitions(datamodelPath: string, outPath: string): Promise<void>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const datamodel_1 = require("./datamodel"); | ||
exports.fileToDefinitions = datamodel_1.fileToDefinitions; | ||
exports.schemaToDefinitions = datamodel_1.schemaToDefinitions; | ||
const build_1 = require("./build"); | ||
exports.buildTypescript = build_1.buildTypescript; | ||
const ProcessError_1 = require("./ProcessError"); | ||
exports.ProcessError = ProcessError_1.ProcessError; | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const app_1 = require("journeyapps/lib/app"); | ||
const DEFAULT_OPTIONS = { | ||
@@ -14,6 +18,18 @@ datamodel: '../../schema.xml' | ||
options = { ...DEFAULT_OPTIONS, ...options }; | ||
await datamodel_1.fileToDefinitions(path.resolve(taskPath, options.datamodel), path.resolve(taskPath, DEFAULT_DATAMODEL_OUT)); | ||
await fileToDefinitions(path.resolve(taskPath, options.datamodel), path.resolve(taskPath, DEFAULT_DATAMODEL_OUT)); | ||
await build_1.buildTypescript(taskPath); | ||
} | ||
exports.buildTask = buildTask; | ||
async function fileToDefinitions(datamodelPath, outPath) { | ||
const data = await fs.readFileSync(datamodelPath, 'utf-8'); | ||
const schema = new app_1.Schema(); | ||
schema.loadXml(data, { apiVersion: new app_1.Version('4.0') }); | ||
const ts = await datamodel_1.schemaToDefinitions(schema); | ||
const dir = path.dirname(outPath); | ||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir); | ||
} | ||
fs.writeFileSync(outPath, ts); | ||
} | ||
exports.fileToDefinitions = fileToDefinitions; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@journeyapps/cloudcode-build", | ||
"version": "1.9.1", | ||
"version": "1.9.3-dev.341bb23.99cb637", | ||
"main": "./lib/index.js", | ||
@@ -30,3 +30,3 @@ "license": "MIT", | ||
], | ||
"gitHead": "de4bab09cb51000774fa76c7b805d6b43ce52a16" | ||
"gitHead": "d451600622cd3f6ed2f0f101971ff16c5837a506" | ||
} |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
16241
256
2