Compare commits
76 Commits
Author | SHA1 | Date | |
---|---|---|---|
b4b5e52799 | |||
7de1cfbb6f | |||
f426e110f0 | |||
02e9cdff98 | |||
576ee88283 | |||
d1886a0966 | |||
9f8b14c6fe | |||
e64e610092 | |||
86f19de7d8 | |||
1b6b45f15f | |||
a8d2954689 | |||
6071ae5de3 | |||
a664f3da76 | |||
5d3b4585b0 | |||
11abf9aafd | |||
1b86228bc4 | |||
8a5097ba50 | |||
2dae7b1200 | |||
909cceb1a5 | |||
5f1bc8dc29 | |||
d33f943fc6 | |||
e4c2d86dbc | |||
088bed779f | |||
1cecba6f13 | |||
324b93a419 | |||
4be3fc27b3 | |||
655a8a72ff | |||
80a77d5f06 | |||
6296411b50 | |||
e7690d4020 | |||
b85a29cfc1 | |||
d559b0f402 | |||
7433c1dba4 | |||
c8f6b0296d | |||
0cffae9eaa | |||
d50c8a1260 | |||
b3702d56bc | |||
ff0faa719b | |||
400e228ffc | |||
25871fc970 | |||
eb990a8ec2 | |||
f5194b76bd | |||
6b5e9ac617 | |||
60854250eb | |||
53de92ac1a | |||
6cb4fff0a5 | |||
45710ded00 | |||
aa87ed9427 | |||
f3594447ac | |||
a3f18c17ed | |||
c5ec7e9c24 | |||
98875a2ece | |||
5b42cf93cb | |||
e0ab34c466 | |||
beb3013e2c | |||
5d1c0a6f1e | |||
fc450816e6 | |||
5fac35c75f | |||
dde29629b7 | |||
4347f800e6 | |||
59161f1eeb | |||
b9a346c5d7 | |||
fa961f86b8 | |||
ff679c1787 | |||
35e3c9ae48 | |||
bf0007ff3a | |||
3ab780e600 | |||
d0662f809f | |||
e20bf7f610 | |||
0a97ec4d07 | |||
69e09c8b4c | |||
0e92554d0a | |||
648afbcf21 | |||
7998c99f27 | |||
8e3633827c | |||
eac20873e5 |
107
.gitea/workflows/gitzone_ci_default.yaml
Normal file
107
.gitea/workflows/gitzone_ci_default.yaml
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
name: CI Pipeline
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm prepare
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci command npm run buildDocs
|
||||||
|
|
||||||
|
- name: Upload artifacts
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: public
|
||||||
|
path: public
|
||||||
|
retention-days: 7
|
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,3 +1,20 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
@ -1,71 +0,0 @@
|
|||||||
# gitzone standard
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .yarn/
|
|
||||||
key: "$CI_BUILD_STAGE"
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- trigger
|
|
||||||
- pages
|
|
||||||
|
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test legacy
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test lts
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test stable
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: trigger
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: pages
|
|
||||||
script:
|
|
||||||
- npmci command yarn global add npmpage
|
|
||||||
- npmci command npmpage
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"command": "npm test",
|
||||||
|
"name": "Run npm test",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export * from './smartscaf.classes.smartscaf';
|
|
7
dist/index.js
vendored
7
dist/index.js
vendored
@ -1,7 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
function __export(m) {
|
|
||||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
||||||
}
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
__export(require("./smartscaf.classes.smartscaf"));
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1EQUE2QyJ9
|
|
35
dist/smartscaf.classes.smartscaf.d.ts
vendored
35
dist/smartscaf.classes.smartscaf.d.ts
vendored
@ -1,35 +0,0 @@
|
|||||||
import { Smartfile } from 'smartfile';
|
|
||||||
export interface ScafTemplateContructorOptions {
|
|
||||||
name?: string;
|
|
||||||
description?: string;
|
|
||||||
sourceDir?: string;
|
|
||||||
}
|
|
||||||
export declare class ScafTemplate {
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
templateSmartfileArray: Smartfile[];
|
|
||||||
requiredVariables: string[];
|
|
||||||
suppliedVariables: any;
|
|
||||||
missingVariables: string[];
|
|
||||||
/**
|
|
||||||
* read a template from a directory
|
|
||||||
*/
|
|
||||||
readTemplateFromDir(dirPathArg: string): Promise<void>;
|
|
||||||
/**
|
|
||||||
* supply the variables to render the teplate with
|
|
||||||
* @param variablesArg
|
|
||||||
*/
|
|
||||||
supplyVariables(variablesArg: any): Promise<void>;
|
|
||||||
/**
|
|
||||||
* Will ask for the missing variables by cli interaction
|
|
||||||
*/
|
|
||||||
askCliForMissingVariables(): Promise<void>;
|
|
||||||
/**
|
|
||||||
* finds all variables in a Template
|
|
||||||
*/
|
|
||||||
private _findVariablesInTemplate();
|
|
||||||
/**
|
|
||||||
* checks if supplied Variables satisfy the template
|
|
||||||
*/
|
|
||||||
private _checkSuppliedVariables();
|
|
||||||
}
|
|
79
dist/smartscaf.classes.smartscaf.js
vendored
79
dist/smartscaf.classes.smartscaf.js
vendored
@ -1,79 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const plugins = require("./smartscaf.plugins");
|
|
||||||
class ScafTemplate {
|
|
||||||
constructor() {
|
|
||||||
this.missingVariables = [];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* read a template from a directory
|
|
||||||
*/
|
|
||||||
readTemplateFromDir(dirPathArg) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
let dirPath = plugins.path.resolve(dirPathArg);
|
|
||||||
this.templateSmartfileArray = yield plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*');
|
|
||||||
this._findVariablesInTemplate();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* supply the variables to render the teplate with
|
|
||||||
* @param variablesArg
|
|
||||||
*/
|
|
||||||
supplyVariables(variablesArg) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
this.suppliedVariables = variablesArg;
|
|
||||||
this.missingVariables = yield this._checkSuppliedVariables();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Will ask for the missing variables by cli interaction
|
|
||||||
*/
|
|
||||||
askCliForMissingVariables() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
this.missingVariables = yield this._checkSuppliedVariables();
|
|
||||||
let localSmartInteract = new plugins.smartinteract.SmartInteract();
|
|
||||||
for (let missingVariable of this.missingVariables) {
|
|
||||||
localSmartInteract.addQuestions([{
|
|
||||||
name: missingVariable,
|
|
||||||
type: 'input',
|
|
||||||
default: `undefined ${missingVariable}`,
|
|
||||||
message: `What is the value of ${missingVariable}?`
|
|
||||||
}]);
|
|
||||||
}
|
|
||||||
let answers = yield localSmartInteract.runQueue();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* finds all variables in a Template
|
|
||||||
*/
|
|
||||||
_findVariablesInTemplate() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
for (let localSmartfile of this.templateSmartfileArray) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* checks if supplied Variables satisfy the template
|
|
||||||
*/
|
|
||||||
_checkSuppliedVariables() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
let missingVars = [];
|
|
||||||
for (let templateSmartFile of this.templateSmartfileArray) {
|
|
||||||
let localMissingVars = yield plugins.smarthbs.checkVarsSatisfaction(templateSmartFile.contents.toString(), this.suppliedVariables);
|
|
||||||
missingVars = plugins.lodash.concat(missingVars, localMissingVars);
|
|
||||||
missingVars = plugins.lodash.uniq(missingVars);
|
|
||||||
}
|
|
||||||
return missingVars;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.ScafTemplate = ScafTemplate;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSwrQ0FBOEM7QUFXOUM7SUFBQTtRQU1FLHFCQUFnQixHQUFhLEVBQUUsQ0FBQTtJQTZEakMsQ0FBQztJQTNEQzs7T0FFRztJQUNHLG1CQUFtQixDQUFFLFVBQWtCOztZQUMzQyxJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQTtZQUM5QyxJQUFJLENBQUMsc0JBQXNCLEdBQUcsTUFBTSxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxnQkFBZ0IsQ0FBQyxPQUFPLEVBQUUsTUFBTSxDQUFDLENBQUE7WUFDMUYsSUFBSSxDQUFDLHdCQUF3QixFQUFFLENBQUE7UUFDakMsQ0FBQztLQUFBO0lBRUQ7OztPQUdHO0lBQ0csZUFBZSxDQUFFLFlBQVk7O1lBQ2pDLElBQUksQ0FBQyxpQkFBaUIsR0FBRyxZQUFZLENBQUE7WUFDckMsSUFBSSxDQUFDLGdCQUFnQixHQUFHLE1BQU0sSUFBSSxDQUFDLHVCQUF1QixFQUFFLENBQUE7UUFDOUQsQ0FBQztLQUFBO0lBRUQ7O09BRUc7SUFDRyx5QkFBeUI7O1lBQzdCLElBQUksQ0FBQyxnQkFBZ0IsR0FBRyxNQUFNLElBQUksQ0FBQyx1QkFBdUIsRUFBRSxDQUFBO1lBQzVELElBQUksa0JBQWtCLEdBQUcsSUFBSSxPQUFPLENBQUMsYUFBYSxDQUFDLGFBQWEsRUFBRSxDQUFBO1lBQ2xFLEdBQUcsQ0FBQyxDQUFDLElBQUksZUFBZSxJQUFJLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUM7Z0JBQ2xELGtCQUFrQixDQUFDLFlBQVksQ0FBQyxDQUFDO3dCQUMvQixJQUFJLEVBQUUsZUFBZTt3QkFDckIsSUFBSSxFQUFFLE9BQU87d0JBQ2IsT0FBTyxFQUFFLGFBQWEsZUFBZSxFQUFFO3dCQUN2QyxPQUFPLEVBQUUsd0JBQXdCLGVBQWUsR0FBRztxQkFDcEQsQ0FBQyxDQUFDLENBQUE7WUFDTCxDQUFDO1lBQ0QsSUFBSSxPQUFPLEdBQUcsTUFBTSxrQkFBa0IsQ0FBQyxRQUFRLEVBQUUsQ0FBQTtRQUNuRCxDQUFDO0tBQUE7SUFFRDs7T0FFRztJQUNXLHdCQUF3Qjs7WUFDcEMsR0FBRyxDQUFDLENBQUMsSUFBSSxjQUFjLElBQUksSUFBSSxDQUFDLHNCQUFzQixDQUFDLENBQUMsQ0FBQztZQUV6RCxDQUFDO1FBQ0gsQ0FBQztLQUFBO0lBRUQ7O09BRUc7SUFDVyx1QkFBdUI7O1lBQ25DLElBQUksV0FBVyxHQUFhLEVBQUUsQ0FBQTtZQUM5QixHQUFHLENBQUMsQ0FBQyxJQUFJLGlCQUFpQixJQUFJLElBQUksQ0FBQyxzQkFBc0IsQ0FBQyxDQUFDLENBQUM7Z0JBQzFELElBQUksZ0JBQWdCLEdBQUcsTUFBTSxPQUFPLENBQUMsUUFBUSxDQUFDLHFCQUFxQixDQUNqRSxpQkFBaUIsQ0FBQyxRQUFRLENBQUMsUUFBUSxFQUFFLEVBQ3JDLElBQUksQ0FBQyxpQkFBaUIsQ0FDdkIsQ0FBQTtnQkFDRCxXQUFXLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxNQUFNLENBQUMsV0FBVyxFQUFFLGdCQUFnQixDQUFDLENBQUE7Z0JBQ2xFLFdBQVcsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQTtZQUNoRCxDQUFDO1lBQ0QsTUFBTSxDQUFDLFdBQVcsQ0FBQTtRQUNwQixDQUFDO0tBQUE7Q0FDRjtBQW5FRCxvQ0FtRUMifQ==
|
|
0
dist/smartscaf.helpers.d.ts
vendored
0
dist/smartscaf.helpers.d.ts
vendored
3
dist/smartscaf.helpers.js
vendored
3
dist/smartscaf.helpers.js
vendored
@ -1,3 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
|
8
dist/smartscaf.plugins.d.ts
vendored
8
dist/smartscaf.plugins.d.ts
vendored
@ -1,8 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
import * as lodash from 'lodash';
|
|
||||||
import * as path from 'path';
|
|
||||||
import * as smartfile from 'smartfile';
|
|
||||||
import * as smarthbs from 'smarthbs';
|
|
||||||
import * as smartinteract from 'smartinteract';
|
|
||||||
import * as smartq from 'smartq';
|
|
||||||
export { lodash, path, smartfile, smarthbs, smartinteract, smartq };
|
|
16
dist/smartscaf.plugins.js
vendored
16
dist/smartscaf.plugins.js
vendored
@ -1,16 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
require("typings-global");
|
|
||||||
const lodash = require("lodash");
|
|
||||||
exports.lodash = lodash;
|
|
||||||
const path = require("path");
|
|
||||||
exports.path = path;
|
|
||||||
const smartfile = require("smartfile");
|
|
||||||
exports.smartfile = smartfile;
|
|
||||||
const smarthbs = require("smarthbs");
|
|
||||||
exports.smarthbs = smarthbs;
|
|
||||||
const smartinteract = require("smartinteract");
|
|
||||||
exports.smartinteract = smartinteract;
|
|
||||||
const smartq = require("smartq");
|
|
||||||
exports.smartq = smartq;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixpQ0FBZ0M7QUFROUIsd0JBQU07QUFQUiw2QkFBNEI7QUFRMUIsb0JBQUk7QUFQTix1Q0FBc0M7QUFRcEMsOEJBQVM7QUFQWCxxQ0FBb0M7QUFRbEMsNEJBQVE7QUFQViwrQ0FBOEM7QUFRNUMsc0NBQWE7QUFQZixpQ0FBZ0M7QUFROUIsd0JBQU0ifQ==
|
|
@ -3,8 +3,18 @@
|
|||||||
"coverageTreshold": 30
|
"coverageTreshold": 30
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"globalNpmTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
"npmAccessLevel": "public"
|
||||||
]
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartscaf",
|
||||||
|
"description": "scaffold projects quickly",
|
||||||
|
"npmPackagename": "@pushrocks/smartscaf",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
53
package.json
53
package.json
@ -1,11 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "smartscaf",
|
"name": "@pushrocks/smartscaf",
|
||||||
"version": "1.0.1",
|
"version": "4.0.9",
|
||||||
|
"private": false,
|
||||||
"description": "scaffold projects quickly",
|
"description": "scaffold projects quickly",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "(tstest test/)",
|
||||||
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -23,15 +26,37 @@
|
|||||||
"npm"
|
"npm"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tapbundle": "^1.0.10"
|
"@gitzone/tsbuild": "^2.1.66",
|
||||||
|
"@gitzone/tsrun": "^1.2.42",
|
||||||
|
"@gitzone/tstest": "^1.0.74",
|
||||||
|
"@pushrocks/tapbundle": "^5.0.8",
|
||||||
|
"@types/node": "^20.3.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/lodash": "^4.14.63",
|
"@pushrocks/lik": "^6.0.2",
|
||||||
"lodash": "^4.17.4",
|
"@pushrocks/smartfile": "^10.0.17",
|
||||||
"smartfile": "^4.2.9",
|
"@pushrocks/smartfm": "^2.0.4",
|
||||||
"smarthbs": "^1.0.12",
|
"@pushrocks/smarthbs": "^3.0.3",
|
||||||
"smartinteract": "^1.0.4",
|
"@pushrocks/smartinteract": "^2.0.11",
|
||||||
"smartq": "^1.1.1",
|
"@pushrocks/smartparam": "^1.1.6",
|
||||||
"typings-global": "^1.0.16"
|
"@pushrocks/smartpromise": "^4.0.2",
|
||||||
}
|
"@pushrocks/smartshell": "^3.0.3",
|
||||||
|
"@pushrocks/smartyaml": "^2.0.5"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
4616
pnpm-lock.yaml
generated
Normal file
4616
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
readme.md
47
readme.md
@ -1,29 +1,44 @@
|
|||||||
# smartscaf
|
# @pushrocks/smartscaf
|
||||||
scaffold projects quickly
|
scaffold projects quickly
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty and Links
|
||||||
[](https://www.npmjs.com/package/smartscaf)
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartscaf)
|
||||||
[](https://GitLab.com/pushrocks/smartscaf)
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartscaf)
|
||||||
[](https://github.com/pushrocks/smartscaf)
|
* [github.com (source mirror)](https://github.com/pushrocks/smartscaf)
|
||||||
[](https://pushrocks.gitlab.io/smartscaf/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartscaf/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://GitLab.com/pushrocks/smartscaf/commits/master)
|
|
||||||
[](https://GitLab.com/pushrocks/smartscaf/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/smartscaf)
|
-- | --
|
||||||
[](https://david-dm.org/pushrocks/smartscaf)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartscaf/master/dependencies/npm)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartscaf)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
Snyk | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
[](http://standardjs.com/)
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
[](https://)
|
[](https://)
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
## Legal
|
||||||
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
41
test/test.ts
41
test/test.ts
@ -1,26 +1,37 @@
|
|||||||
import { expect, tap } from 'tapbundle'
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
import * as smartscaf from '../dist/index'
|
import * as smartscaf from '../ts/index.js';
|
||||||
|
|
||||||
let testScafTemplate: smartscaf.ScafTemplate
|
process.env.CI = 'true';
|
||||||
|
|
||||||
|
let testScafTemplate: smartscaf.ScafTemplate;
|
||||||
|
|
||||||
tap.test('should create new Smartscaf instance', async () => {
|
tap.test('should create new Smartscaf instance', async () => {
|
||||||
testScafTemplate = new smartscaf.ScafTemplate()
|
testScafTemplate = new smartscaf.ScafTemplate('./test/test_template');
|
||||||
expect(testScafTemplate).to.be.instanceof(smartscaf.ScafTemplate)
|
expect(testScafTemplate).toBeInstanceOf(smartscaf.ScafTemplate);
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.test('Smartscaf instance -> should read a template directory', async () => {
|
tap.test('Smartscaf instance -> should read a template directory', async () => {
|
||||||
await testScafTemplate.readTemplateFromDir('./test/test_template')
|
await testScafTemplate.readTemplateFromDir();
|
||||||
expect(testScafTemplate.templateSmartfileArray.length).to.equal(3)
|
expect(testScafTemplate.templateSmartfileArray.length).toEqual(6);
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.test('smartfile -> should accept variables', async () => {
|
tap.test('smartfile -> should accept variables', async () => {
|
||||||
await testScafTemplate.supplyVariables({})
|
await testScafTemplate.supplyVariables({});
|
||||||
console.log(testScafTemplate.missingVariables)
|
console.log(testScafTemplate.missingVariables);
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.test('ask cli', async () => {
|
tap.test('ask cli', async () => {
|
||||||
await testScafTemplate.askCliForMissingVariables()
|
await testScafTemplate.askCliForMissingVariables();
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.start()
|
tap.test('should have valid supplied variables', async () => {
|
||||||
|
console.log(testScafTemplate.suppliedVariables);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should output ready rendered template', async () => {
|
||||||
|
await testScafTemplate.writeToDisk(path.resolve('./test/test_output'));
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
3
test/test_output/anothername.yml
Normal file
3
test/test_output/anothername.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# this is a wow
|
||||||
|
# this is a here
|
||||||
|
# this is a undefined variable
|
1
test/test_output/changedname.md
Normal file
1
test/test_output/changedname.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# some undefined variable
|
1
test/test_output/hello.md
Normal file
1
test/test_output/hello.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# param1 10
|
1
test/test_output/notemplate.yml
Normal file
1
test/test_output/notemplate.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
awesome!
|
3
test/test_output/template1.md
Normal file
3
test/test_output/template1.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# this is a wow
|
||||||
|
# this is a here
|
||||||
|
# this is a undefined variable
|
3
test/test_output/template2.md
Normal file
3
test/test_output/template2.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# this is a from default yaml
|
||||||
|
# this is a this is another value from yml
|
||||||
|
# this is a undefined variable
|
13
test/test_template/.smartscaf.yml
Normal file
13
test/test_template/.smartscaf.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
defaults:
|
||||||
|
templateVar1: from default yaml
|
||||||
|
templateVar2: this is another value from yml
|
||||||
|
templateObject.value1: wow
|
||||||
|
templateObject.value2: here
|
||||||
|
node_version: '10'
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
merge:
|
||||||
|
- ../test_template_2
|
||||||
|
|
||||||
|
runafter:
|
||||||
|
- npm install
|
1
test/test_template/notemplate.yml
Normal file
1
test/test_template/notemplate.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
awesome!
|
@ -1,3 +1,6 @@
|
|||||||
# this is a {{templateVar1}}
|
---
|
||||||
# this is a {{templateVar2}}
|
fileName: anothername.yml
|
||||||
|
---
|
||||||
|
# this is a {{templateObject.value1}}
|
||||||
|
# this is a {{templateObject.value2}}
|
||||||
# this is a {{templateVar3}}
|
# this is a {{templateVar3}}
|
||||||
|
@ -1 +1,4 @@
|
|||||||
|
---
|
||||||
|
fileName: changedname.md
|
||||||
|
---
|
||||||
# some {{wow}}
|
# some {{wow}}
|
1
test/test_template_2/hello.md
Normal file
1
test/test_template_2/hello.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# param1 {{node_version}}
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@pushrocks/smartscaf',
|
||||||
|
version: '4.0.9',
|
||||||
|
description: 'scaffold projects quickly'
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
export * from './smartscaf.classes.smartscaf'
|
export * from './smartscaf.classes.smartscaf.js';
|
||||||
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './smartscaf.js';
|
7
ts/interfaces/smartscaf.ts
Normal file
7
ts/interfaces/smartscaf.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export interface ISmartscafFile {
|
||||||
|
defaults: { [key: string]: string };
|
||||||
|
dependencies: {
|
||||||
|
merge: string[];
|
||||||
|
};
|
||||||
|
runafter: string[];
|
||||||
|
}
|
@ -1,79 +1,266 @@
|
|||||||
import * as plugins from './smartscaf.plugins'
|
import * as plugins from './smartscaf.plugins.js';
|
||||||
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
import { Smartfile } from 'smartfile'
|
import { Smartfile } from '@pushrocks/smartfile';
|
||||||
|
|
||||||
export interface ScafTemplateContructorOptions {
|
export interface ScafTemplateContructorOptions {
|
||||||
name?: string,
|
name?: string;
|
||||||
description?: string
|
description?: string;
|
||||||
sourceDir?: string
|
sourceDir?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ScafTemplate {
|
export class ScafTemplate {
|
||||||
name: string
|
public static async createTemplateFromDir(dirPathArg: string) {
|
||||||
description: string
|
return new ScafTemplate(dirPathArg);
|
||||||
templateSmartfileArray: Smartfile[]
|
}
|
||||||
requiredVariables: string[]
|
|
||||||
suppliedVariables: any
|
/**
|
||||||
missingVariables: string[] = []
|
* the name of the template
|
||||||
|
*/
|
||||||
|
public name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the descriptions of the template
|
||||||
|
*/
|
||||||
|
public description: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the location on disk of the template
|
||||||
|
*/
|
||||||
|
public dirPath: string;
|
||||||
|
public destinationPath: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* smartscafFile
|
||||||
|
*/
|
||||||
|
public smartscafFile: interfaces.ISmartscafFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the files of the template as array of Smartfiles
|
||||||
|
*/
|
||||||
|
public templateSmartfileArray: Smartfile[];
|
||||||
|
public requiredVariables: string[];
|
||||||
|
public defaultVariables: any;
|
||||||
|
public suppliedVariables: any = {};
|
||||||
|
public missingVariables: string[] = [];
|
||||||
|
|
||||||
|
constructor(dirPathArg: string) {
|
||||||
|
this.dirPath = plugins.path.resolve(dirPathArg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read a template from a directory
|
* read a template from a directory
|
||||||
*/
|
*/
|
||||||
async readTemplateFromDir (dirPathArg: string) {
|
public async readTemplateFromDir() {
|
||||||
let dirPath = plugins.path.resolve(dirPathArg)
|
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(this.dirPath, '**/*');
|
||||||
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*')
|
|
||||||
this._findVariablesInTemplate()
|
// read .smartscaf.yml file
|
||||||
|
let smartscafFile: interfaces.ISmartscafFile = {
|
||||||
|
defaults: {},
|
||||||
|
dependencies: {
|
||||||
|
merge: [],
|
||||||
|
},
|
||||||
|
runafter: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const smartscafSmartfile = this.templateSmartfileArray.find((smartfileArg) => {
|
||||||
|
return smartfileArg.parsedPath.base === '.smartscaf.yml';
|
||||||
|
});
|
||||||
|
|
||||||
|
if (smartscafSmartfile) {
|
||||||
|
smartscafFile = {
|
||||||
|
...smartscafFile,
|
||||||
|
...(await plugins.smartyaml.yamlStringToObject(
|
||||||
|
smartscafSmartfile.contentBuffer.toString()
|
||||||
|
)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.smartscafFile = smartscafFile;
|
||||||
|
|
||||||
|
await this._resolveTemplateDependencies();
|
||||||
|
await this._findVariablesInTemplate();
|
||||||
|
await this._checkSuppliedVariables();
|
||||||
|
await this._checkDefaultVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* supply the variables to render the teplate with
|
* supply the variables to render the teplate with
|
||||||
* @param variablesArg
|
* @param variablesArg gets merged with this.suppliedVariables
|
||||||
*/
|
*/
|
||||||
async supplyVariables (variablesArg) {
|
public async supplyVariables(variablesArg) {
|
||||||
this.suppliedVariables = variablesArg
|
this.suppliedVariables = {
|
||||||
this.missingVariables = await this._checkSuppliedVariables()
|
...this.suppliedVariables,
|
||||||
|
...variablesArg,
|
||||||
|
};
|
||||||
|
this.missingVariables = await this._checkSuppliedVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will ask for the missing variables by cli interaction
|
* Will ask for the missing variables by cli interaction
|
||||||
*/
|
*/
|
||||||
async askCliForMissingVariables () {
|
public async askCliForMissingVariables() {
|
||||||
this.missingVariables = await this._checkSuppliedVariables()
|
this.missingVariables = await this._checkSuppliedVariables();
|
||||||
let localSmartInteract = new plugins.smartinteract.SmartInteract()
|
const localSmartInteract = new plugins.smartinteract.SmartInteract();
|
||||||
for (let missingVariable of this.missingVariables) {
|
for (const missingVariable of this.missingVariables) {
|
||||||
localSmartInteract.addQuestions([{
|
localSmartInteract.addQuestions([
|
||||||
name: missingVariable,
|
{
|
||||||
type: 'input',
|
name: missingVariable,
|
||||||
default: `undefined ${missingVariable}`,
|
type: 'input',
|
||||||
message: `What is the value of ${missingVariable}?`
|
default: (() => {
|
||||||
}])
|
if (this.defaultVariables && this.defaultVariables[missingVariable]) {
|
||||||
|
return this.defaultVariables[missingVariable];
|
||||||
|
} else {
|
||||||
|
return 'undefined variable';
|
||||||
|
}
|
||||||
|
})(),
|
||||||
|
message: `What is the value of ${missingVariable}?`,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
const answerBucket = await localSmartInteract.runQueue();
|
||||||
|
const answers = answerBucket.getAllAnswers();
|
||||||
|
for (const answer of answers) {
|
||||||
|
await plugins.smartparam.smartAdd(this.suppliedVariables, answer.name, answer.value);
|
||||||
}
|
}
|
||||||
let answers = await localSmartInteract.runQueue()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* finds all variables in a Template
|
* writes a file to disk
|
||||||
|
* @param destinationDirArg
|
||||||
|
*/
|
||||||
|
public async writeToDisk(destinationDirArg) {
|
||||||
|
this.destinationPath = destinationDirArg;
|
||||||
|
const smartfileArrayToWrite: Smartfile[] = [];
|
||||||
|
for (const smartfile of this.templateSmartfileArray) {
|
||||||
|
// lets filter out template files
|
||||||
|
if (smartfile.path === '.smartscaf.yml') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// render the template
|
||||||
|
const template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString());
|
||||||
|
const renderedTemplateString = template(this.suppliedVariables);
|
||||||
|
|
||||||
|
// handle frontmatter
|
||||||
|
const smartfmInstance = new plugins.smartfm.Smartfm({
|
||||||
|
fmType: 'yaml',
|
||||||
|
});
|
||||||
|
const parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any;
|
||||||
|
if (parsedTemplate.data.fileName) {
|
||||||
|
smartfile.updateFileName(parsedTemplate.data.fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
smartfile.contents = Buffer.from(await plugins.smarthbs.postprocess(parsedTemplate.content));
|
||||||
|
smartfileArrayToWrite.push(smartfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
|
||||||
|
await this.runScripts();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* finds all variables in a Template in as string
|
||||||
|
* e.g. myobject.someKey and myobject.someOtherKey
|
||||||
*/
|
*/
|
||||||
private async _findVariablesInTemplate() {
|
private async _findVariablesInTemplate() {
|
||||||
for (let localSmartfile of this.templateSmartfileArray) {
|
let templateVariables: string[] = [];
|
||||||
|
for (const templateSmartfile of this.templateSmartfileArray) {
|
||||||
|
const localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(
|
||||||
|
templateSmartfile.contents.toString()
|
||||||
|
);
|
||||||
|
templateVariables = [...templateVariables, ...localTemplateVariables];
|
||||||
}
|
}
|
||||||
|
templateVariables = templateVariables.filter((value, index, self) => {
|
||||||
|
return self.indexOf(value) === index;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if supplied Variables satisfy the template
|
* checks if supplied Variables satisfy the template
|
||||||
*/
|
*/
|
||||||
private async _checkSuppliedVariables() {
|
private async _checkSuppliedVariables() {
|
||||||
let missingVars: string[] = []
|
let missingVars: string[] = [];
|
||||||
for (let templateSmartFile of this.templateSmartfileArray) {
|
for (const templateSmartfile of this.templateSmartfileArray) {
|
||||||
let localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
|
const localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
|
||||||
templateSmartFile.contents.toString(),
|
templateSmartfile.contents.toString(),
|
||||||
this.suppliedVariables
|
this.suppliedVariables
|
||||||
)
|
);
|
||||||
missingVars = plugins.lodash.concat(missingVars, localMissingVars)
|
|
||||||
missingVars = plugins.lodash.uniq(missingVars)
|
// combine with other missingVars
|
||||||
|
missingVars = [...missingVars, ...localMissingVars];
|
||||||
|
}
|
||||||
|
|
||||||
|
// dedupe
|
||||||
|
missingVars = missingVars.filter((value, index, self) => {
|
||||||
|
return self.indexOf(value) === index;
|
||||||
|
});
|
||||||
|
return missingVars;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks the smartscaf.yml default values at the root of a template
|
||||||
|
* allows 2 ways of notation in YAML:
|
||||||
|
* >> myObject.myKey.someDeeperKey: someValue
|
||||||
|
* >> myObject.yourKey.yourDeeperKey: yourValue
|
||||||
|
* or
|
||||||
|
* >> myObject:
|
||||||
|
* >> - someKey:
|
||||||
|
* >> - someDeeperKey: someValue
|
||||||
|
* >> - yourKey:
|
||||||
|
* >> - yourDeeperKey: yourValue
|
||||||
|
*/
|
||||||
|
private async _checkDefaultVariables() {
|
||||||
|
const smartscafSmartfile = this.templateSmartfileArray.find((smartfileArg) => {
|
||||||
|
return smartfileArg.parsedPath.base === '.smartscaf.yml';
|
||||||
|
});
|
||||||
|
|
||||||
|
if (smartscafSmartfile) {
|
||||||
|
const smartscafObject = await plugins.smartyaml.yamlStringToObject(
|
||||||
|
smartscafSmartfile.contents.toString()
|
||||||
|
);
|
||||||
|
const defaultObject = smartscafObject.defaults;
|
||||||
|
this.defaultVariables = defaultObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
// safeguard against non existent defaults
|
||||||
|
if (!this.defaultVariables) {
|
||||||
|
console.log('this template does not specify defaults');
|
||||||
|
this.defaultVariables = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resolve template dependencies
|
||||||
|
*/
|
||||||
|
private async _resolveTemplateDependencies() {
|
||||||
|
console.log('looking at templates to merge!');
|
||||||
|
for (const dependency of this.smartscafFile.dependencies.merge) {
|
||||||
|
console.log(`Now resolving ${dependency}`);
|
||||||
|
const templatePathToMerge = plugins.path.join(this.dirPath, dependency);
|
||||||
|
if (!plugins.smartfile.fs.isDirectory(templatePathToMerge)) {
|
||||||
|
console.log(
|
||||||
|
`dependency ${dependency} resolves to ${templatePathToMerge} which ist NOT a directory`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(
|
||||||
|
templatePathToMerge,
|
||||||
|
'**/*'
|
||||||
|
);
|
||||||
|
this.templateSmartfileArray = this.templateSmartfileArray.concat(templateSmartfileArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async runScripts() {
|
||||||
|
if (!this.destinationPath) {
|
||||||
|
throw new Error('cannot run scripts without an destinationdir');
|
||||||
|
}
|
||||||
|
const smartshellInstance = new plugins.smartshell.Smartshell({
|
||||||
|
executor: 'bash',
|
||||||
|
});
|
||||||
|
for (const command of this.smartscafFile.runafter) {
|
||||||
|
await smartshellInstance.exec(`cd ${this.destinationPath} && ${command}`);
|
||||||
}
|
}
|
||||||
return missingVars
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
import * as plugins from './smartscaf.plugins'
|
|
||||||
|
|
@ -1,16 +1,23 @@
|
|||||||
import 'typings-global'
|
import * as path from 'path';
|
||||||
import * as lodash from 'lodash'
|
import * as lik from '@pushrocks/lik';
|
||||||
import * as path from 'path'
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as smartfile from 'smartfile'
|
import * as smartfm from '@pushrocks/smartfm';
|
||||||
import * as smarthbs from 'smarthbs'
|
import * as smarthbs from '@pushrocks/smarthbs';
|
||||||
import * as smartinteract from 'smartinteract'
|
import * as smartinteract from '@pushrocks/smartinteract';
|
||||||
import * as smartq from 'smartq'
|
import * as smartparam from '@pushrocks/smartparam';
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartyaml from '@pushrocks/smartyaml';
|
||||||
|
import * as smartshell from '@pushrocks/smartshell';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
lodash,
|
|
||||||
path,
|
path,
|
||||||
|
lik,
|
||||||
smartfile,
|
smartfile,
|
||||||
|
smartfm,
|
||||||
smarthbs,
|
smarthbs,
|
||||||
smartinteract,
|
smartinteract,
|
||||||
smartq
|
smartparam,
|
||||||
}
|
smartpromise,
|
||||||
|
smartyaml,
|
||||||
|
smartshell,
|
||||||
|
};
|
||||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "tslint-config-standard"
|
|
||||||
}
|
|
Reference in New Issue
Block a user