@vinodotdev/codegen
Advanced tools
Comparing version 0.2.2 to 1.0.1
@@ -47,2 +47,3 @@ import DEBUG from 'debug'; | ||
export declare function registerTypePartials(language: LANGUAGE, type: CODEGEN_TYPE | WIDL_TYPE | JSON_TYPE): void; | ||
export declare function registerCommonPartials(language: LANGUAGE): void; | ||
export declare function codegen(node: AbstractNode): string; | ||
@@ -49,0 +50,0 @@ export interface CommonOutputOptions { |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.commitOutput = exports.widlOpts = exports.outputOpts = exports.codegen = exports.registerTypePartials = exports.registerPartial = exports.getTemplate = exports.normalizeFilename = exports.readFile = exports.DEFAULT_CODEGEN_TYPE = exports.LANGUAGE_OFFERS = exports.JSON_TYPE = exports.WIDL_TYPE = exports.CODEGEN_TYPE = exports.LANGUAGE = exports.debug = void 0; | ||
exports.commitOutput = exports.widlOpts = exports.outputOpts = exports.codegen = exports.registerCommonPartials = exports.registerTypePartials = exports.registerPartial = exports.getTemplate = exports.normalizeFilename = exports.readFile = exports.DEFAULT_CODEGEN_TYPE = exports.LANGUAGE_OFFERS = exports.JSON_TYPE = exports.WIDL_TYPE = exports.CODEGEN_TYPE = exports.LANGUAGE = exports.debug = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
@@ -85,2 +85,3 @@ const path_1 = __importDefault(require("path")); | ||
function registerTypePartials(language, type) { | ||
registerCommonPartials(language); | ||
const relativeDir = path_1.default.join(language, 'partials', type); | ||
@@ -105,2 +106,22 @@ const dir = path_1.default.join(find_root_1.default(__dirname), 'templates', relativeDir); | ||
exports.registerTypePartials = registerTypePartials; | ||
function registerCommonPartials(language) { | ||
const relativeDir = path_1.default.join(language, 'partials', 'common'); | ||
const dir = path_1.default.join(find_root_1.default(__dirname), 'templates', relativeDir); | ||
exports.debug(`Looking for partials in ${dir}`); | ||
if (!fs_1.default.existsSync(dir)) | ||
return; | ||
const files = fs_1.default.readdirSync(dir); | ||
for (const file of files) { | ||
const name = file.replace(path_1.default.extname(`${file}.hbs`), ''); | ||
const partialPath = path_1.default.join(dir, file); | ||
exports.debug(`Loading partial ${partialPath}`); | ||
const exists = fs_1.default.existsSync(partialPath); | ||
if (exists) { | ||
exports.debug(`Registering common partial for ${language}: ${name}`); | ||
const partialSource = readFile(partialPath); | ||
widl_template_1.handlebars.registerPartial(name, partialSource); | ||
} | ||
} | ||
} | ||
exports.registerCommonPartials = registerCommonPartials; | ||
// This should be a separate module but won't until it does a complete codegen | ||
@@ -107,0 +128,0 @@ function codegen(node) { |
@@ -28,3 +28,2 @@ "use strict"; | ||
common_1.registerTypePartials(LANG, TYPE); | ||
common_1.registerPartial(LANG, 'expand-type'); | ||
const options = { | ||
@@ -31,0 +30,0 @@ root: args.root, |
@@ -28,3 +28,2 @@ "use strict"; | ||
common_1.registerTypePartials(LANG, TYPE); | ||
common_1.registerPartial(LANG, 'expand-type'); | ||
const options = { | ||
@@ -31,0 +30,0 @@ root: args.root, |
@@ -28,3 +28,2 @@ "use strict"; | ||
common_1.registerTypePartials(LANG, TYPE); | ||
common_1.registerPartial(LANG, 'expand-type'); | ||
const options = { | ||
@@ -31,0 +30,0 @@ root: args.root, |
@@ -23,3 +23,2 @@ "use strict"; | ||
common_1.registerTypePartials(LANG, TYPE); | ||
common_1.registerPartial(LANG, 'expand-type'); | ||
const options = { | ||
@@ -26,0 +25,0 @@ root: args.root, |
@@ -23,3 +23,2 @@ "use strict"; | ||
common_1.registerTypePartials(LANG, TYPE); | ||
common_1.registerPartial(LANG, 'expand-type'); | ||
const options = { | ||
@@ -26,0 +25,0 @@ root: args.root, |
@@ -5,3 +5,3 @@ { | ||
"author": "jsoverson@gmail.com", | ||
"version": "0.2.2", | ||
"version": "1.0.1", | ||
"main": "dist/src/index.js", | ||
@@ -8,0 +8,0 @@ "types": "dist/src/index.d.ts", |
@@ -91,2 +91,3 @@ import fs from 'fs'; | ||
export function registerTypePartials(language: LANGUAGE, type: CODEGEN_TYPE | WIDL_TYPE | JSON_TYPE): void { | ||
registerCommonPartials(language); | ||
const relativeDir = path.join(language, 'partials', type); | ||
@@ -110,2 +111,21 @@ const dir = path.join(findroot(__dirname), 'templates', relativeDir); | ||
export function registerCommonPartials(language: LANGUAGE): void { | ||
const relativeDir = path.join(language, 'partials', 'common'); | ||
const dir = path.join(findroot(__dirname), 'templates', relativeDir); | ||
debug(`Looking for partials in ${dir}`); | ||
if (!fs.existsSync(dir)) return; | ||
const files = fs.readdirSync(dir); | ||
for (const file of files) { | ||
const name = file.replace(path.extname(`${file}.hbs`), ''); | ||
const partialPath = path.join(dir, file); | ||
debug(`Loading partial ${partialPath}`); | ||
const exists = fs.existsSync(partialPath); | ||
if (exists) { | ||
debug(`Registering common partial for ${language}: ${name}`); | ||
const partialSource = readFile(partialPath); | ||
handlebars.registerPartial(name, partialSource); | ||
} | ||
} | ||
} | ||
// This should be a separate module but won't until it does a complete codegen | ||
@@ -112,0 +132,0 @@ export function codegen(node: AbstractNode): string { |
@@ -9,3 +9,2 @@ import yargs from 'yargs'; | ||
readFile, | ||
registerPartial, | ||
registerTypePartials, | ||
@@ -44,3 +43,2 @@ widlOpts, | ||
registerTypePartials(LANG, TYPE); | ||
registerPartial(LANG, 'expand-type'); | ||
@@ -47,0 +45,0 @@ const options = { |
@@ -13,2 +13,3 @@ import yargs from 'yargs'; | ||
normalizeFilename, | ||
registerCommonPartials, | ||
} from '../../common'; | ||
@@ -15,0 +16,0 @@ import fs from 'fs'; |
@@ -9,3 +9,2 @@ import yargs from 'yargs'; | ||
readFile, | ||
registerPartial, | ||
registerTypePartials, | ||
@@ -44,3 +43,2 @@ widlOpts, | ||
registerTypePartials(LANG, TYPE); | ||
registerPartial(LANG, 'expand-type'); | ||
@@ -47,0 +45,0 @@ const options = { |
@@ -9,3 +9,2 @@ import yargs from 'yargs'; | ||
readFile, | ||
registerPartial, | ||
registerTypePartials, | ||
@@ -44,3 +43,2 @@ widlOpts, | ||
registerTypePartials(LANG, TYPE); | ||
registerPartial(LANG, 'expand-type'); | ||
@@ -47,0 +45,0 @@ const options = { |
@@ -9,3 +9,2 @@ import yargs from 'yargs'; | ||
readFile, | ||
registerPartial, | ||
registerTypePartials, | ||
@@ -41,3 +40,2 @@ widlOpts, | ||
registerTypePartials(LANG, TYPE); | ||
registerPartial(LANG, 'expand-type'); | ||
@@ -44,0 +42,0 @@ const options = { |
@@ -9,3 +9,2 @@ import yargs from 'yargs'; | ||
readFile, | ||
registerPartial, | ||
registerTypePartials, | ||
@@ -41,3 +40,2 @@ widlOpts, | ||
registerTypePartials(LANG, TYPE); | ||
registerPartial(LANG, 'expand-type'); | ||
@@ -44,0 +42,0 @@ const options = { |
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
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
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
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
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
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
95
1802
1
111860