@cuba-platform/front-generator
Version:
CUBA Platform front-end clients generator
52 lines • 2.68 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const Base = require("yeoman-generator");
const YeomanEnvironment = require("yeoman-environment");
const fs = require("fs");
const util_1 = require("util");
const test_commons_1 = require("../../test-commons");
const assert = require("assert");
const rimraf = (0, util_1.promisify)(require('rimraf'));
const TPL_FILE_NAME = 'i18nMappings.ts';
const DEST_DIR = path.join(process.cwd(), `src/test/generated/templates`);
const GENERATED_FILE = path.join(DEST_DIR, TPL_FILE_NAME);
const FIXTURES_DIR = path.join(process.cwd(), `src/test/fixtures/templates`);
class CopyTplGenerator extends Base {
constructor(args, options) {
super(args, options);
this.sourceRoot(path.join(__dirname, '../../fixtures/templates'));
}
// noinspection JSUnusedGlobalSymbols
processTemplate() {
// noinspection JSUnusedGlobalSymbols
const model = {
isLocaleUsed: () => true
};
const tplPath = this.templatePath(`${TPL_FILE_NAME}.ejs`);
console.log('process template tplPath', fs.realpathSync(tplPath));
console.log('dest dir', fs.realpathSync(DEST_DIR));
this.fs.copyTpl(tplPath, GENERATED_FILE, model);
}
}
describe('react generator template processing test', () => {
it('should correct process ejs template', () => __awaiter(void 0, void 0, void 0, function* () {
yield rimraf(`${DEST_DIR}/*`);
!fs.existsSync(DEST_DIR) && fs.mkdirSync(DEST_DIR, { recursive: true });
const env = new YeomanEnvironment();
env.registerStub(CopyTplGenerator, 'CopyTplGenerator');
yield env.run('CopyTplGenerator', {});
(0, test_commons_1.format)(GENERATED_FILE);
assert.strictEqual(fs.readFileSync(GENERATED_FILE, 'utf8'), fs.readFileSync(path.join(FIXTURES_DIR, TPL_FILE_NAME), 'utf8'));
}));
});
//# sourceMappingURL=react-generator-process-templates.test.js.map