Compare commits

...

64 Commits

Author SHA1 Message Date
b4b5e52799 4.0.9 2023-06-25 12:45:44 +02:00
7de1cfbb6f fix(core): update 2023-06-25 12:45:44 +02:00
f426e110f0 4.0.8 2023-06-25 12:33:14 +02:00
02e9cdff98 fix(core): update 2023-06-25 12:33:13 +02:00
576ee88283 4.0.7 2023-06-25 12:27:17 +02:00
d1886a0966 fix(core): update 2023-06-25 12:27:17 +02:00
9f8b14c6fe 4.0.6 2023-06-25 12:26:39 +02:00
e64e610092 fix(core): update 2023-06-25 12:26:39 +02:00
86f19de7d8 4.0.5 2023-06-25 00:59:37 +02:00
1b6b45f15f fix(core): update 2023-06-25 00:59:36 +02:00
a8d2954689 4.0.4 2023-06-25 00:50:25 +02:00
6071ae5de3 fix(core): update 2023-06-25 00:50:25 +02:00
a664f3da76 4.0.3 2022-06-26 00:31:58 +02:00
5d3b4585b0 fix(core): update 2022-06-26 00:31:57 +02:00
11abf9aafd 4.0.2 2022-06-25 03:23:08 +02:00
1b86228bc4 fix(core): update 2022-06-25 03:23:08 +02:00
8a5097ba50 4.0.1 2022-06-25 03:19:43 +02:00
2dae7b1200 fix(core): update 2022-06-25 03:19:43 +02:00
909cceb1a5 4.0.0 2022-06-25 03:19:16 +02:00
5f1bc8dc29 BREAKING CHANGE(core): switch to esm 2022-06-25 03:19:16 +02:00
d33f943fc6 3.0.10 2020-01-31 14:51:06 +00:00
e4c2d86dbc fix(core): update 2020-01-31 14:51:05 +00:00
088bed779f 3.0.9 2019-10-11 21:56:11 +02:00
1cecba6f13 fix(core): update 2019-10-11 21:56:11 +02:00
324b93a419 3.0.8 2019-10-02 12:50:14 +02:00
4be3fc27b3 fix(core): update 2019-10-02 12:50:14 +02:00
655a8a72ff 3.0.7 2019-09-10 18:23:53 +02:00
80a77d5f06 fix(core): update 2019-09-10 18:23:53 +02:00
6296411b50 3.0.6 2019-09-10 18:18:30 +02:00
e7690d4020 fix(core): update 2019-09-10 18:18:30 +02:00
b85a29cfc1 3.0.5 2019-09-10 18:03:33 +02:00
d559b0f402 fix(core): update 2019-09-10 18:03:33 +02:00
7433c1dba4 3.0.4 2019-09-10 18:00:13 +02:00
c8f6b0296d update 2019-09-10 18:00:03 +02:00
0cffae9eaa update dependencies 2019-09-10 17:59:29 +02:00
d50c8a1260 3.0.3 2019-02-17 17:17:47 +01:00
b3702d56bc fix(core): update 2019-02-17 17:17:47 +01:00
ff0faa719b 3.0.2 2019-01-27 18:55:39 +01:00
400e228ffc fix(core): update 2019-01-27 18:55:38 +01:00
25871fc970 3.0.1 2018-10-04 17:00:33 +02:00
eb990a8ec2 fix(core): update 2018-10-04 17:00:33 +02:00
f5194b76bd Merge branch 'master' into 'master'
update

See merge request pushrocks/smartscaf!1
2018-10-04 14:48:20 +00:00
6b5e9ac617 update 2018-10-04 16:04:42 +02:00
60854250eb 3.0.0 2018-08-30 22:43:22 +02:00
53de92ac1a BREAKING CHANGE(structure): templates now take their path within the constructor 2018-08-30 22:43:22 +02:00
6cb4fff0a5 2.0.2 2018-08-28 23:57:06 +02:00
45710ded00 2.0.1 2018-08-28 00:20:02 +02:00
aa87ed9427 fix(dependencies): resolve dependencies 2018-08-28 00:20:02 +02:00
f3594447ac 2.0.0 2018-08-27 23:55:14 +02:00
a3f18c17ed BREAKING CHANGE(scope): switch to new @pushrocks scope 2018-08-27 23:55:14 +02:00
c5ec7e9c24 1.0.14 2017-08-09 16:57:39 +02:00
98875a2ece fix variable distribution 2017-08-09 16:57:32 +02:00
5b42cf93cb 1.0.13 2017-08-09 15:31:39 +02:00
e0ab34c466 update dependencies 2017-08-09 15:31:35 +02:00
beb3013e2c 1.0.12 2017-07-28 14:47:46 +02:00
5d1c0a6f1e update dependencies 2017-07-28 14:47:43 +02:00
fc450816e6 1.0.11 2017-06-02 01:03:27 +02:00
5fac35c75f prevent empty defaults.yml causing error 2017-06-02 01:03:24 +02:00
dde29629b7 1.0.10 2017-05-28 00:14:25 +02:00
4347f800e6 update dependencies 2017-05-28 00:14:11 +02:00
59161f1eeb 1.0.9 2017-05-27 23:53:06 +02:00
b9a346c5d7 now supports frontmatter for advanced file templating 2017-05-27 23:52:58 +02:00
fa961f86b8 1.0.8 2017-05-27 03:25:50 +02:00
ff679c1787 add docs 2017-05-27 03:25:42 +02:00
38 changed files with 5159 additions and 1623 deletions

View 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
View File

@ -1,3 +1,20 @@
node_modules/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -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
View 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
View 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
View File

@ -1 +0,0 @@
export * from './smartscaf.classes.smartscaf';

7
dist/index.js vendored
View File

@ -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

View File

@ -1,51 +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[];
defaultVariables: any;
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 gets merged with this.suppliedVariables
*/
supplyVariables(variablesArg: any): Promise<void>;
/**
* Will ask for the missing variables by cli interaction
*/
askCliForMissingVariables(): Promise<void>;
writeToDisk(destinationDirArg: any): Promise<void>;
/**
* finds all variables in a Template in as string
* e.g. myobject.someKey and myobject.someOtherKey
*/
private _findVariablesInTemplate();
/**
* checks if supplied Variables satisfy the template
*/
private _checkSuppliedVariables();
/**
* checks the default.yml at the root of a template for default variables
* allows 2 ways of notation in YAML:
* >> myObject.myKey.someDeeperKey: someValue
* >> myObject.yourKey.yourDeeperKey: yourValue
* or
* >> myObject:
* >> - someKey:
* >> - someDeeperKey: someValue
* >> - yourKey:
* >> - yourDeeperKey: yourValue
*/
private _checkDefaultVariables();
}

View File

@ -1,135 +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");
const helpers = require("./smartscaf.helpers");
class ScafTemplate {
constructor() {
this.suppliedVariables = {};
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, '**/*');
yield this._findVariablesInTemplate();
yield this._checkSuppliedVariables();
yield this._checkDefaultVariables();
});
}
/**
* supply the variables to render the teplate with
* @param variablesArg gets merged with this.suppliedVariables
*/
supplyVariables(variablesArg) {
return __awaiter(this, void 0, void 0, function* () {
this.suppliedVariables = plugins.lodash.merge(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: (() => {
if (this.defaultVariables[missingVariable]) {
return this.defaultVariables[missingVariable];
}
else {
return 'undefined variable';
}
})(),
message: `What is the value of ${missingVariable}?`
}]);
}
let answerBucket = yield localSmartInteract.runQueue();
answerBucket.answerMap.forEach((answer) => __awaiter(this, void 0, void 0, function* () {
yield helpers.deepAddToObject(this.suppliedVariables, answer.name, answer.value);
}));
});
}
writeToDisk(destinationDirArg) {
return __awaiter(this, void 0, void 0, function* () {
let smartfileArrayToWrite = plugins.lodash.cloneDeep(this.templateSmartfileArray);
for (let smartfile of smartfileArrayToWrite) {
let template = yield plugins.smarthbs.getTemplateForString(smartfile.contents.toString());
let renderedTemplateString = template(this.suppliedVariables);
smartfile.contents = Buffer.from(renderedTemplateString);
}
yield plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
});
}
/**
* finds all variables in a Template in as string
* e.g. myobject.someKey and myobject.someOtherKey
*/
_findVariablesInTemplate() {
return __awaiter(this, void 0, void 0, function* () {
let templateVariables = [];
for (let templateSmartfile of this.templateSmartfileArray) {
let localTemplateVariables = yield plugins.smarthbs.findVarsInHbsString(templateSmartfile.contents.toString());
templateVariables = plugins.lodash.concat(templateVariables, localTemplateVariables);
}
templateVariables = plugins.lodash.uniq(templateVariables);
});
}
/**
* 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;
});
}
/**
* checks the default.yml at the root of a template for default variables
* allows 2 ways of notation in YAML:
* >> myObject.myKey.someDeeperKey: someValue
* >> myObject.yourKey.yourDeeperKey: yourValue
* or
* >> myObject:
* >> - someKey:
* >> - someDeeperKey: someValue
* >> - yourKey:
* >> - yourDeeperKey: yourValue
*/
_checkDefaultVariables() {
return __awaiter(this, void 0, void 0, function* () {
let defaultsSmartfile = this.templateSmartfileArray.filter(smartfileArg => {
return smartfileArg.parsedPath.base === 'defaults.yml';
})[0];
if (defaultsSmartfile) {
let defaultObject = yield plugins.smartyaml.yamlStringToObject(defaultsSmartfile.contents.toString());
this.defaultVariables = defaultObject;
}
else {
this.defaultVariables = {};
}
});
}
}
exports.ScafTemplate = ScafTemplate;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQ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FBRSxDQUN0QyxDQUFBO2dCQUNELElBQUksQ0FBQyxnQkFBZ0IsR0FBRyxhQUFhLENBQUE7WUFDdkMsQ0FBQztZQUFDLElBQUksQ0FBQyxDQUFDO2dCQUNOLElBQUksQ0FBQyxnQkFBZ0IsR0FBRyxFQUFFLENBQUE7WUFDNUIsQ0FBQztRQUNILENBQUM7S0FBQTtDQUNGO0FBM0hELG9DQTJIQyJ9

View File

@ -1,4 +0,0 @@
/**
* adds a variable in string dot notation to an already more or less expanded object
*/
export declare let deepAddToObject: (objectArg: any, varStringArg: string, valueArg: string) => Promise<void>;

View File

@ -1,45 +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 });
/**
* adds a variable in string dot notation to an already more or less expanded object
*/
exports.deepAddToObject = (objectArg, varStringArg, valueArg) => __awaiter(this, void 0, void 0, function* () {
let varNamesArray = varStringArg.split('.');
let referencePointer = objectArg;
for (let i = 0; i !== varNamesArray.length; i++) {
let varName = varNamesArray[i];
// is there a next variable ?
let varNameNext = (() => {
if (varNamesArray[i + 1]) {
return varNamesArray[i + 1];
}
return null;
})();
// build the tree in suppliedVariables
console.log(referencePointer);
console.log(varName);
if (!referencePointer[varName] && !varNameNext) {
referencePointer[varName] = valueArg;
referencePointer = null;
}
else if (!referencePointer[varName] && varNameNext) {
referencePointer[varName] = {};
referencePointer = referencePointer[varName];
}
else if (referencePointer[varName] && varNameNext) {
referencePointer = referencePointer[varName];
}
else {
throw new Error('Something is strange!');
}
}
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozL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UFDLFdBQVcsQ0FBQyxDQUFDLENBQUM7WUFDL0MsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLEdBQUcsUUFBUSxDQUFBO1lBQ3BDLGdCQUFnQixHQUFHLElBQUksQ0FBQTtRQUN6QixDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLElBQUksV0FBVyxDQUFDLENBQUMsQ0FBQztZQUNyRCxnQkFBZ0IsQ0FBQyxPQUFPLENBQUMsR0FBRyxFQUFFLENBQUE7WUFDOUIsZ0JBQWdCLEdBQUcsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLENBQUE7UUFDOUMsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxnQkFBZ0IsQ0FBQyxPQUFPLENBQUMsSUFBSSxXQUFXLENBQUMsQ0FBQyxDQUFDO1lBQ3BELGdCQUFnQixHQUFHLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxDQUFBO1FBQzlDLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLE1BQU0sSUFBSSxLQUFLLENBQUMsdUJBQXVCLENBQUMsQ0FBQTtRQUMxQyxDQUFDO0lBQ0gsQ0FBQztBQUNILENBQUMsQ0FBQSxDQUFBIn0=

View File

@ -1,9 +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';
import * as smartyaml from 'smartyaml';
export { lodash, path, smartfile, smarthbs, smartinteract, smartq, smartyaml };

View File

@ -1,18 +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;
const smartyaml = require("smartyaml");
exports.smartyaml = smartyaml;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixpQ0FBZ0M7QUFTOUIsd0JBQU07QUFSUiw2QkFBNEI7QUFTMUIsb0JBQUk7QUFSTix1Q0FBc0M7QUFTcEMsOEJBQVM7QUFSWCxxQ0FBb0M7QUFTbEMsNEJBQVE7QUFSViwrQ0FBOEM7QUFTNUMsc0NBQWE7QUFSZixpQ0FBZ0M7QUFTOUIsd0JBQU07QUFSUix1Q0FBc0M7QUFTcEMsOEJBQVMifQ==

View File

@ -3,8 +3,18 @@
"coverageTreshold": 30
},
"npmci": {
"globalNpmTools": [
"npmts"
]
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartscaf",
"description": "scaffold projects quickly",
"npmPackagename": "@pushrocks/smartscaf",
"license": "MIT"
}
}
}

View File

@ -1,11 +1,14 @@
{
"name": "smartscaf",
"version": "1.0.7",
"name": "@pushrocks/smartscaf",
"version": "4.0.9",
"private": false,
"description": "scaffold projects quickly",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/)",
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
@ -23,16 +26,37 @@
"npm"
],
"devDependencies": {
"tapbundle": "^1.0.13"
"@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": {
"@types/lodash": "^4.14.64",
"lodash": "^4.17.4",
"smartfile": "^4.2.15",
"smarthbs": "^1.0.15",
"smartinteract": "^1.0.4",
"smartq": "^1.1.1",
"smartyaml": "^1.0.2",
"typings-global": "^1.0.16"
}
"@pushrocks/lik": "^6.0.2",
"@pushrocks/smartfile": "^10.0.17",
"@pushrocks/smartfm": "^2.0.4",
"@pushrocks/smarthbs": "^3.0.3",
"@pushrocks/smartinteract": "^2.0.11",
"@pushrocks/smartparam": "^1.1.6",
"@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

File diff suppressed because it is too large Load Diff

View File

@ -1,29 +1,44 @@
# smartscaf
# @pushrocks/smartscaf
scaffold projects quickly
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartscaf)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartscaf)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartscaf)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartscaf/)
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartscaf)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartscaf)
* [github.com (source mirror)](https://github.com/pushrocks/smartscaf)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartscaf/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartscaf/badges/master/build.svg)](https://GitLab.com/pushrocks/smartscaf/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartscaf/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartscaf/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartscaf.svg)](https://www.npmjs.com/package/smartscaf)
[![Dependency Status](https://david-dm.org/pushrocks/smartscaf.svg)](https://david-dm.org/pushrocks/smartscaf)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartscaf/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartscaf/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartscaf/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartscaf)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartscaf/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartscaf/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartscaf)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartscaf)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartscaf)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartscaf)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartscaf)](https://lossless.cloud)
## Usage
Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README.
> MIT licensed | **&copy;** [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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](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 | **&copy;** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)

View File

@ -1,33 +1,37 @@
import { expect, tap } from 'tapbundle'
import * as path from 'path'
import { expect, tap } from '@pushrocks/tapbundle';
import * as path from 'path';
import * as smartscaf from '../dist/index'
import * as smartscaf from '../ts/index.js';
process.env.CI = 'true'
process.env.CI = 'true';
let testScafTemplate: smartscaf.ScafTemplate
let testScafTemplate: smartscaf.ScafTemplate;
tap.test('should create new Smartscaf instance', async () => {
testScafTemplate = new smartscaf.ScafTemplate()
expect(testScafTemplate).to.be.instanceof(smartscaf.ScafTemplate)
})
testScafTemplate = new smartscaf.ScafTemplate('./test/test_template');
expect(testScafTemplate).toBeInstanceOf(smartscaf.ScafTemplate);
});
tap.test('Smartscaf instance -> should read a template directory', async () => {
await testScafTemplate.readTemplateFromDir('./test/test_template')
expect(testScafTemplate.templateSmartfileArray.length).to.equal(5)
})
await testScafTemplate.readTemplateFromDir();
expect(testScafTemplate.templateSmartfileArray.length).toEqual(6);
});
tap.test('smartfile -> should accept variables', async () => {
await testScafTemplate.supplyVariables({})
console.log(testScafTemplate.missingVariables)
})
await testScafTemplate.supplyVariables({});
console.log(testScafTemplate.missingVariables);
});
tap.test('ask cli', async () => {
await testScafTemplate.askCliForMissingVariables()
})
await testScafTemplate.askCliForMissingVariables();
});
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'))
})
await testScafTemplate.writeToDisk(path.resolve('./test/test_output'));
});
tap.start()
tap.start();

View File

@ -0,0 +1,3 @@
# this is a wow
# this is a here
# this is a undefined variable

View File

@ -1,4 +0,0 @@
templateVar1: from default yaml
templateVar2: this is another value from yml
templateObject.value1: wow
templateObject.value2: here

View File

@ -0,0 +1 @@
# param1 10

View File

@ -1 +0,0 @@
awesome!

View 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

View File

@ -1,4 +0,0 @@
templateVar1: from default yaml
templateVar2: this is another value from yml
templateObject.value1: wow
templateObject.value2: here

View File

@ -1,3 +1,6 @@
---
fileName: anothername.yml
---
# this is a {{templateObject.value1}}
# this is a {{templateObject.value2}}
# this is a {{templateVar3}}

View File

@ -1 +1,4 @@
---
fileName: changedname.md
---
# some {{wow}}

View File

@ -0,0 +1 @@
# param1 {{node_version}}

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartscaf',
version: '4.0.9',
description: 'scaffold projects quickly'
}

View File

@ -1 +1 @@
export * from './smartscaf.classes.smartscaf'
export * from './smartscaf.classes.smartscaf.js';

1
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './smartscaf.js';

View File

@ -0,0 +1,7 @@
export interface ISmartscafFile {
defaults: { [key: string]: string };
dependencies: {
merge: string[];
};
runafter: string[];
}

View File

@ -1,114 +1,205 @@
import * as plugins from './smartscaf.plugins'
import * as helpers from './smartscaf.helpers'
import * as plugins from './smartscaf.plugins.js';
import * as interfaces from './interfaces/index.js';
// interfaces
import { Smartfile } from 'smartfile'
import { Smartfile } from '@pushrocks/smartfile';
export interface ScafTemplateContructorOptions {
name?: string,
description?: string
sourceDir?: string
name?: string;
description?: string;
sourceDir?: string;
}
export class ScafTemplate {
name: string
description: string
templateSmartfileArray: Smartfile[]
requiredVariables: string[]
defaultVariables: any
suppliedVariables: any = {}
missingVariables: string[] = []
public static async createTemplateFromDir(dirPathArg: string) {
return new ScafTemplate(dirPathArg);
}
/**
* 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
*/
async readTemplateFromDir (dirPathArg: string) {
let dirPath = plugins.path.resolve(dirPathArg)
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*')
await this._findVariablesInTemplate()
await this._checkSuppliedVariables()
await this._checkDefaultVariables()
public async readTemplateFromDir() {
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(this.dirPath, '**/*');
// 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
* @param variablesArg gets merged with this.suppliedVariables
*/
async supplyVariables (variablesArg) {
this.suppliedVariables = plugins.lodash.merge(this.suppliedVariables, variablesArg)
this.missingVariables = await this._checkSuppliedVariables()
public async supplyVariables(variablesArg) {
this.suppliedVariables = {
...this.suppliedVariables,
...variablesArg,
};
this.missingVariables = await this._checkSuppliedVariables();
}
/**
* Will ask for the missing variables by cli interaction
*/
async askCliForMissingVariables () {
this.missingVariables = await this._checkSuppliedVariables()
let localSmartInteract = new plugins.smartinteract.SmartInteract()
for (let missingVariable of this.missingVariables) {
localSmartInteract.addQuestions([{
name: missingVariable,
type: 'input',
default: (() => {
if (this.defaultVariables[missingVariable]) {
return this.defaultVariables[missingVariable]
} else {
return 'undefined variable'
}
})(),
message: `What is the value of ${missingVariable}?`
}])
public async askCliForMissingVariables() {
this.missingVariables = await this._checkSuppliedVariables();
const localSmartInteract = new plugins.smartinteract.SmartInteract();
for (const missingVariable of this.missingVariables) {
localSmartInteract.addQuestions([
{
name: missingVariable,
type: 'input',
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 answerBucket = await localSmartInteract.runQueue()
answerBucket.answerMap.forEach(async answer => {
await helpers.deepAddToObject(this.suppliedVariables, answer.name, answer.value)
})
}
async writeToDisk (destinationDirArg) {
let smartfileArrayToWrite = plugins.lodash.cloneDeep(this.templateSmartfileArray)
for (let smartfile of smartfileArrayToWrite) {
let template = await plugins.smarthbs.getTemplateForString(
smartfile.contents.toString()
)
let renderedTemplateString = template(this.suppliedVariables)
smartfile.contents = Buffer.from(renderedTemplateString)
/**
* 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 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 () {
let templateVariables: string[] = []
for (let templateSmartfile of this.templateSmartfileArray) {
let localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(templateSmartfile.contents.toString())
templateVariables = plugins.lodash.concat(templateVariables, localTemplateVariables)
private async _findVariablesInTemplate() {
let templateVariables: string[] = [];
for (const templateSmartfile of this.templateSmartfileArray) {
const localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(
templateSmartfile.contents.toString()
);
templateVariables = [...templateVariables, ...localTemplateVariables];
}
templateVariables = plugins.lodash.uniq(templateVariables)
templateVariables = templateVariables.filter((value, index, self) => {
return self.indexOf(value) === index;
});
}
/**
* checks if supplied Variables satisfy the template
*/
private async _checkSuppliedVariables () {
let missingVars: string[] = []
for (let templateSmartfile of this.templateSmartfileArray) {
let localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
private async _checkSuppliedVariables() {
let missingVars: string[] = [];
for (const templateSmartfile of this.templateSmartfileArray) {
const localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
templateSmartfile.contents.toString(),
this.suppliedVariables
)
missingVars = plugins.lodash.concat(missingVars, localMissingVars)
);
// combine with other missingVars
missingVars = [...missingVars, ...localMissingVars];
}
missingVars = plugins.lodash.uniq(missingVars)
return missingVars
// dedupe
missingVars = missingVars.filter((value, index, self) => {
return self.indexOf(value) === index;
});
return missingVars;
}
/**
* checks the default.yml at the root of a template for default variables
* 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
@ -119,18 +210,57 @@ export class ScafTemplate {
* >> - yourKey:
* >> - yourDeeperKey: yourValue
*/
private async _checkDefaultVariables () {
let defaultsSmartfile = this.templateSmartfileArray.filter(smartfileArg => {
return smartfileArg.parsedPath.base === 'defaults.yml'
})[0]
private async _checkDefaultVariables() {
const smartscafSmartfile = this.templateSmartfileArray.find((smartfileArg) => {
return smartfileArg.parsedPath.base === '.smartscaf.yml';
});
if (defaultsSmartfile) {
let defaultObject = await plugins.smartyaml.yamlStringToObject(
defaultsSmartfile.contents.toString()
)
this.defaultVariables = defaultObject
} else {
this.defaultVariables = {}
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}`);
}
}
}

View File

@ -1,35 +0,0 @@
import * as plugins from './smartscaf.plugins'
/**
* adds a variable in string dot notation to an already more or less expanded object
*/
export let deepAddToObject = async (objectArg, varStringArg: string, valueArg: string) => {
let varNamesArray = varStringArg.split('.')
let referencePointer = objectArg
for (let i = 0; i !== varNamesArray.length; i++) {
let varName = varNamesArray[i]
// is there a next variable ?
let varNameNext: string = (() => {
if (varNamesArray[i + 1]) {
return varNamesArray[i + 1]
}
return null
})()
// build the tree in suppliedVariables
console.log(referencePointer)
console.log(varName)
if (!referencePointer[varName] && !varNameNext) {
referencePointer[varName] = valueArg
referencePointer = null
} else if (!referencePointer[varName] && varNameNext) {
referencePointer[varName] = {}
referencePointer = referencePointer[varName]
} else if (referencePointer[varName] && varNameNext) {
referencePointer = referencePointer[varName]
} else {
throw new Error('Something is strange!')
}
}
}

View File

@ -1,18 +1,23 @@
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'
import * as smartyaml from 'smartyaml'
import * as path from 'path';
import * as lik from '@pushrocks/lik';
import * as smartfile from '@pushrocks/smartfile';
import * as smartfm from '@pushrocks/smartfm';
import * as smarthbs from '@pushrocks/smarthbs';
import * as smartinteract from '@pushrocks/smartinteract';
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 {
lodash,
path,
lik,
smartfile,
smartfm,
smarthbs,
smartinteract,
smartq,
smartyaml
}
smartparam,
smartpromise,
smartyaml,
smartshell,
};

9
tsconfig.json Normal file
View File

@ -0,0 +1,9 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext"
}
}

View File

@ -1,3 +0,0 @@
{
"extends": "tslint-config-standard"
}

1090
yarn.lock

File diff suppressed because it is too large Load Diff