@trayio/generator 0.0.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +22 -0
- package/README.md +28 -0
- package/dist/generator/Generator.d.ts +5 -0
- package/dist/generator/Generator.d.ts.map +1 -0
- package/dist/generator/Generator.js +2 -0
- package/dist/generator/NodeFsGenerator.d.ts +17 -0
- package/dist/generator/NodeFsGenerator.d.ts.map +1 -0
- package/dist/generator/NodeFsGenerator.js +103 -0
- package/dist/generator/NodeFsGenerator.unit.test.d.ts +2 -0
- package/dist/generator/NodeFsGenerator.unit.test.d.ts.map +1 -0
- package/dist/generator/NodeFsGenerator.unit.test.js +168 -0
- package/dist/generator/project.test.zip +0 -0
- package/package.json +32 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Tray.io, Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Tray Template Generator allows users to create customized templates by replacing specific placeholders with user-provided values. It supports both zip files and folders
|
|
2
|
+
|
|
3
|
+
### Usage
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { NodeFsGenerator } from '@trayio/generator';
|
|
7
|
+
|
|
8
|
+
const templatePath = 'path/to/template';
|
|
9
|
+
const outputPath = 'output/path';
|
|
10
|
+
const values = {
|
|
11
|
+
name: 'foo',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const generator = new NodeFsGenerator();
|
|
15
|
+
await generator.generate(
|
|
16
|
+
templatePath,
|
|
17
|
+
outputPath,
|
|
18
|
+
values
|
|
19
|
+
)();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Template Source
|
|
23
|
+
|
|
24
|
+
The template source can be either a zip file or a folder. If the template is a zip file, ensure the file extension is `.zip`. If it's a folder, provide the path to the folder.
|
|
25
|
+
|
|
26
|
+
### Placeholder Syntax
|
|
27
|
+
|
|
28
|
+
Placeholders could be defined using the `$placeholder$` syntax on file/folder names or withing the content of files.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Generator.d.ts","sourceRoot":"","sources":["../../src/generator/Generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEvC,MAAM,WAAW,SAAS;IACzB,QAAQ,CACP,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;CACnC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
2
|
+
import { Generator } from './Generator';
|
|
3
|
+
export declare class NodeFsGenerator implements Generator {
|
|
4
|
+
generate(templatePath: string, targetPath: string, values: Record<string, string>): TE.TaskEither<Error, undefined>;
|
|
5
|
+
private replacePlaceholdersInDir;
|
|
6
|
+
private renameParentDir;
|
|
7
|
+
private replacePlaceholdersInFile;
|
|
8
|
+
private replacePlaceholdersInContent;
|
|
9
|
+
private readStats;
|
|
10
|
+
private readDir;
|
|
11
|
+
private readFile;
|
|
12
|
+
private writeFile;
|
|
13
|
+
private rename;
|
|
14
|
+
private copy;
|
|
15
|
+
private unzip;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=NodeFsGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeFsGenerator.d.ts","sourceRoot":"","sources":["../../src/generator/NodeFsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAOvC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,qBAAa,eAAgB,YAAW,SAAS;IAChD,QAAQ,CACP,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAyBlC,OAAO,CAAC,wBAAwB,CA0B9B;IAEF,OAAO,CAAC,eAAe,CAsCrB;IAEF,OAAO,CAAC,yBAAyB,CAa/B;IAEF,OAAO,CAAC,4BAA4B,CAUlC;IAEF,OAAO,CAAC,SAAS,CACiD;IAElE,OAAO,CAAC,OAAO,CAGZ;IAEH,OAAO,CAAC,QAAQ,CAGb;IAEH,OAAO,CAAC,SAAS,CASd;IAEH,OAAO,CAAC,MAAM,CASX;IAEH,OAAO,CAAC,IAAI,CAST;IAEH,OAAO,CAAC,KAAK,CAYV;CACH"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.NodeFsGenerator = void 0;
|
|
27
|
+
const fs = __importStar(require("fs/promises"));
|
|
28
|
+
const path_1 = require("path");
|
|
29
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
30
|
+
const Task_1 = require("@trayio/commons/task/Task");
|
|
31
|
+
const function_1 = require("fp-ts/function");
|
|
32
|
+
const fse = __importStar(require("fs-extra"));
|
|
33
|
+
const Array_1 = require("fp-ts/Array");
|
|
34
|
+
const extract = require("extract-zip");
|
|
35
|
+
class NodeFsGenerator {
|
|
36
|
+
constructor() {
|
|
37
|
+
this.replacePlaceholdersInDir = (dirPath, values) => {
|
|
38
|
+
const targetPath = this.replacePlaceholdersInContent(dirPath, values);
|
|
39
|
+
return (0, function_1.pipe)(this.rename(dirPath, targetPath), TE.chain(() => this.readDir(targetPath)), TE.chain((direntList) => (0, Array_1.traverse)(TE.ApplicativeSeq)((dirent) => {
|
|
40
|
+
const fileOrDirPath = (0, path_1.join)(targetPath, dirent.name);
|
|
41
|
+
if (dirent.isDirectory()) {
|
|
42
|
+
return this.replacePlaceholdersInDir(fileOrDirPath, values);
|
|
43
|
+
}
|
|
44
|
+
if (dirent.isFile()) {
|
|
45
|
+
return this.replacePlaceholdersInFile(fileOrDirPath, values);
|
|
46
|
+
}
|
|
47
|
+
return TE.left(new Error('Unknown file type. Template directory should contain either folders or files'));
|
|
48
|
+
})(direntList)), TE.map(() => undefined));
|
|
49
|
+
};
|
|
50
|
+
this.renameParentDir = (targetPath, values) => {
|
|
51
|
+
const regex = /\$(.*?)\$/g;
|
|
52
|
+
return (0, function_1.pipe)(this.readDir(targetPath), TE.chain((direntList) => TE.right(direntList.filter((dirent) => regex.test(dirent.name)))), TE.chain((direntList) => {
|
|
53
|
+
if (direntList.length === 0) {
|
|
54
|
+
return TE.right(targetPath);
|
|
55
|
+
}
|
|
56
|
+
if (direntList.length > 1) {
|
|
57
|
+
return TE.left(new Error('More than one parent directory found. This is not allowed'));
|
|
58
|
+
}
|
|
59
|
+
return TE.right(`${targetPath}/${direntList[0].name}`);
|
|
60
|
+
}), TE.chain((parentDirName) => {
|
|
61
|
+
const replacedParentDirName = this.replacePlaceholdersInContent(parentDirName, values);
|
|
62
|
+
return (0, function_1.pipe)(this.rename(parentDirName, replacedParentDirName), TE.map(() => replacedParentDirName));
|
|
63
|
+
}));
|
|
64
|
+
};
|
|
65
|
+
this.replacePlaceholdersInFile = (filePath, values) => {
|
|
66
|
+
const targetPath = this.replacePlaceholdersInContent(filePath, values);
|
|
67
|
+
return (0, function_1.pipe)(this.rename(filePath, targetPath), TE.chain(() => this.readFile(targetPath)), TE.map((fileContent) => this.replacePlaceholdersInContent(fileContent, values)), TE.chain((replacedContent) => this.writeFile(targetPath, replacedContent)));
|
|
68
|
+
};
|
|
69
|
+
this.replacePlaceholdersInContent = (templateContent, replacements) => {
|
|
70
|
+
let content = templateContent;
|
|
71
|
+
Object.entries(replacements).forEach(([placeholder, value]) => {
|
|
72
|
+
const regex = new RegExp(`\\$${placeholder}\\$`, 'g');
|
|
73
|
+
content = content.replace(regex, value);
|
|
74
|
+
});
|
|
75
|
+
return content;
|
|
76
|
+
};
|
|
77
|
+
this.readStats = (path) => (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.lstat(path));
|
|
78
|
+
this.readDir = (path) => (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.readdir(path, { withFileTypes: true }));
|
|
79
|
+
this.readFile = (path) => (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.readFile(path, 'utf-8'));
|
|
80
|
+
this.writeFile = (targetPath, generatedContent) => (0, function_1.pipe)((0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fs.writeFile(targetPath, generatedContent)), TE.map(() => undefined));
|
|
81
|
+
this.rename = (oldPath, newPath) => (0, function_1.pipe)((0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fse.rename(oldPath, newPath)), TE.map(() => undefined));
|
|
82
|
+
this.copy = (source, targetPath) => (0, function_1.pipe)((0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => fse.copy(source, targetPath)), TE.map(() => undefined));
|
|
83
|
+
this.unzip = (source, targetPath) => (0, function_1.pipe)((0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => {
|
|
84
|
+
const extracted = extract(source, {
|
|
85
|
+
dir: targetPath,
|
|
86
|
+
});
|
|
87
|
+
return extracted;
|
|
88
|
+
}), TE.map(() => undefined));
|
|
89
|
+
}
|
|
90
|
+
generate(templatePath, targetPath, values) {
|
|
91
|
+
return (0, function_1.pipe)(this.readStats(templatePath), TE.chain((stats) => {
|
|
92
|
+
if (stats.isDirectory()) {
|
|
93
|
+
return this.copy(templatePath, targetPath);
|
|
94
|
+
}
|
|
95
|
+
if (stats.isFile() && (0, path_1.extname)(templatePath) === '.zip') {
|
|
96
|
+
const unzip = this.unzip(templatePath, targetPath);
|
|
97
|
+
return unzip;
|
|
98
|
+
}
|
|
99
|
+
return TE.left(new Error('Unknown file type. Template path needs to be either a directory or a zip file'));
|
|
100
|
+
}), TE.chain(() => this.renameParentDir(targetPath, values)), TE.chain((parentDirName) => this.replacePlaceholdersInDir(parentDirName, values)), TE.map(() => undefined));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.NodeFsGenerator = NodeFsGenerator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeFsGenerator.unit.test.d.ts","sourceRoot":"","sources":["../../src/generator/NodeFsGenerator.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const fs = __importStar(require("fs"));
|
|
36
|
+
const path_1 = require("path");
|
|
37
|
+
const extract = require("extract-zip");
|
|
38
|
+
const NodeFsGenerator_1 = require("./NodeFsGenerator");
|
|
39
|
+
const unzip = (source, targetPath) => extract(source, {
|
|
40
|
+
dir: targetPath,
|
|
41
|
+
});
|
|
42
|
+
const outputTest = (outputPath, values) => {
|
|
43
|
+
const dirContent = fs.readdirSync(outputPath);
|
|
44
|
+
expect(dirContent).toStrictEqual(expect.arrayContaining([values.name]));
|
|
45
|
+
const serviceDirPath = (0, path_1.join)(outputPath, values.name);
|
|
46
|
+
const serviceDirContent = fs.readdirSync(serviceDirPath);
|
|
47
|
+
expect(serviceDirContent).toEqual(expect.arrayContaining([
|
|
48
|
+
'.github',
|
|
49
|
+
'.gitignore',
|
|
50
|
+
'README.md',
|
|
51
|
+
'modules',
|
|
52
|
+
'package.json',
|
|
53
|
+
]));
|
|
54
|
+
const modulesDir = (0, path_1.join)(serviceDirPath, `modules`);
|
|
55
|
+
const modulesDirDirContent = fs.readdirSync(modulesDir);
|
|
56
|
+
expect(modulesDirDirContent).toEqual(expect.arrayContaining([`${values.name}-contract`, `${values.name}-domain`]));
|
|
57
|
+
return undefined;
|
|
58
|
+
};
|
|
59
|
+
const contentTest = (outputPath, values) => {
|
|
60
|
+
const filePath = (0, path_1.join)(outputPath, `${values.name}/modules/${values.name}-contract/src/${values.entityFolder}/${values.entity}Facade.ts`);
|
|
61
|
+
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
62
|
+
const expectedContent = `import { RequestHandler } from '@trayio/base-contract/base/Facade';
|
|
63
|
+
import { TypeCodec } from '@trayio/commons/codec/TypeCodec';
|
|
64
|
+
import * as t from 'io-ts';
|
|
65
|
+
|
|
66
|
+
export interface ${values.entity}Facade {
|
|
67
|
+
get${values.entity}: RequestHandler<Get${values.entity}, ${values.entity}>;
|
|
68
|
+
create${values.entity}: RequestHandler<Create${values.entity}, ${values.entity}>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type Get${values.entity} = {
|
|
72
|
+
id: string;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type Create${values.entity} = {
|
|
76
|
+
description: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type ${values.entity} = {
|
|
80
|
+
id: string;
|
|
81
|
+
description: string;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const get${values.entity}Codec = new TypeCodec<Get${values.entity}>(
|
|
85
|
+
t.type({
|
|
86
|
+
id: t.string,
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
export const create${values.entity}Codec = new TypeCodec<Create${values.entity}>(
|
|
91
|
+
t.type({
|
|
92
|
+
description: t.string,
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
export const ${values.entityVar}Codec = new TypeCodec<${values.entity}>(
|
|
97
|
+
t.type({
|
|
98
|
+
id: t.string,
|
|
99
|
+
description: t.string,
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
`;
|
|
103
|
+
expect(fileContent).toEqual(expectedContent);
|
|
104
|
+
};
|
|
105
|
+
/** test directory structure:
|
|
106
|
+
* - generator-test-output
|
|
107
|
+
* - zip-test
|
|
108
|
+
* - folder-test-template
|
|
109
|
+
* - folder-test-output
|
|
110
|
+
*/
|
|
111
|
+
describe('NodeFsGenerator', () => {
|
|
112
|
+
const dirPath = __dirname;
|
|
113
|
+
const outputPath = (0, path_1.join)(dirPath, 'generator-test-output');
|
|
114
|
+
const zipTemplatePath = (0, path_1.join)(dirPath, 'project.test.zip');
|
|
115
|
+
const values = {
|
|
116
|
+
name: 'cluster-service',
|
|
117
|
+
entityFolder: 'foo',
|
|
118
|
+
entityVar: 'foo',
|
|
119
|
+
entity: 'Foo',
|
|
120
|
+
};
|
|
121
|
+
try {
|
|
122
|
+
fs.mkdirSync(outputPath);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
// ignore error
|
|
126
|
+
}
|
|
127
|
+
// comment out to see output
|
|
128
|
+
afterAll(() => {
|
|
129
|
+
fs.rmSync(outputPath, { recursive: true, force: true });
|
|
130
|
+
});
|
|
131
|
+
describe('zip template', () => {
|
|
132
|
+
const zipOutputPath = (0, path_1.join)(outputPath, 'zip-test');
|
|
133
|
+
fs.mkdirSync(zipOutputPath, {
|
|
134
|
+
recursive: true,
|
|
135
|
+
});
|
|
136
|
+
it('Should extract all content of the template', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
137
|
+
const generator = new NodeFsGenerator_1.NodeFsGenerator();
|
|
138
|
+
yield generator.generate(zipTemplatePath, zipOutputPath, values)();
|
|
139
|
+
}));
|
|
140
|
+
it('should output template and rename files/folders according to user input', () => {
|
|
141
|
+
outputTest(zipOutputPath, values);
|
|
142
|
+
});
|
|
143
|
+
it('should update the content of files according to user input', () => {
|
|
144
|
+
contentTest(zipOutputPath, values);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
describe('folder template', () => {
|
|
148
|
+
const folderTemplatePath = (0, path_1.join)(outputPath, 'folder-test-template');
|
|
149
|
+
const folderOutputPath = (0, path_1.join)(outputPath, 'folder-test-output');
|
|
150
|
+
fs.mkdirSync(folderTemplatePath, {
|
|
151
|
+
recursive: true,
|
|
152
|
+
});
|
|
153
|
+
fs.mkdirSync(folderOutputPath, {
|
|
154
|
+
recursive: true,
|
|
155
|
+
});
|
|
156
|
+
unzip(zipTemplatePath, folderTemplatePath);
|
|
157
|
+
it('Should copy all content of the template', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
|
+
const generator = new NodeFsGenerator_1.NodeFsGenerator();
|
|
159
|
+
const result = yield generator.generate(folderTemplatePath, folderOutputPath, values)();
|
|
160
|
+
}));
|
|
161
|
+
it('should output template and rename files/folders according to user input', () => {
|
|
162
|
+
outputTest(folderOutputPath, values);
|
|
163
|
+
});
|
|
164
|
+
it('should update the content of files according to user input', () => {
|
|
165
|
+
contentTest(folderOutputPath, values);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trayio/generator",
|
|
3
|
+
"version": "0.0.1-beta",
|
|
4
|
+
"description": "Template based generator",
|
|
5
|
+
"author": "Tray.io",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18.x"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@trayio/commons": "0.0.1-beta",
|
|
15
|
+
"extract-zip": "2.0.1",
|
|
16
|
+
"fs-extra": "11.1.0"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
"./*": "./dist/*.js"
|
|
20
|
+
},
|
|
21
|
+
"typesVersions": {
|
|
22
|
+
"*": {
|
|
23
|
+
"*": [
|
|
24
|
+
"*",
|
|
25
|
+
"dist/*"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"/dist"
|
|
31
|
+
]
|
|
32
|
+
}
|