Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
11abf9aafd | |||
1b86228bc4 | |||
8a5097ba50 | |||
2dae7b1200 | |||
909cceb1a5 | |||
5f1bc8dc29 | |||
d33f943fc6 | |||
e4c2d86dbc | |||
088bed779f | |||
1cecba6f13 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
111
.gitlab-ci.yml
111
.gitlab-ci.yml
@ -3,14 +3,17 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,21 +21,37 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command snyk test
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -41,37 +60,36 @@ snyk:
|
|||||||
testStable:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
@ -79,36 +97,37 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-dbase:npmci
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci node install stable
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -116,5 +135,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
23
.snyk
23
.snyk
@ -1,23 +0,0 @@
|
|||||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
|
||||||
version: v1.13.5
|
|
||||||
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
|
|
||||||
ignore:
|
|
||||||
SNYK-JS-JSYAML-173999:
|
|
||||||
- '@pushrocks/smartfm > gray-matter > js-yaml':
|
|
||||||
reason: None given
|
|
||||||
expires: '2019-10-10T16:23:38.993Z'
|
|
||||||
- '@pushrocks/smartyaml > js-yaml':
|
|
||||||
reason: None given
|
|
||||||
expires: '2019-10-10T16:23:38.993Z'
|
|
||||||
SNYK-JS-JSYAML-174129:
|
|
||||||
- '@pushrocks/smartfm > gray-matter > js-yaml':
|
|
||||||
reason: None given
|
|
||||||
expires: '2019-10-10T16:23:38.993Z'
|
|
||||||
- '@pushrocks/smartyaml > js-yaml':
|
|
||||||
reason: None given
|
|
||||||
expires: '2019-10-10T16:23:38.993Z'
|
|
||||||
SNYK-JS-LODASH-450202:
|
|
||||||
- '@pushrocks/smartinteract > inquirer > lodash':
|
|
||||||
reason: None given
|
|
||||||
expires: '2019-10-10T16:23:38.993Z'
|
|
||||||
patch: {}
|
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -7,11 +7,12 @@
|
|||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartscaf",
|
"gitrepo": "smartscaf",
|
||||||
"shortDescription": "scaffold projects quickly",
|
"description": "scaffold projects quickly",
|
||||||
"npmPackagename": "@pushrocks/smartscaf",
|
"npmPackagename": "@pushrocks/smartscaf",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
12074
package-lock.json
generated
12074
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
50
package.json
50
package.json
@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartscaf",
|
"name": "@pushrocks/smartscaf",
|
||||||
"version": "3.0.8",
|
"version": "4.0.2",
|
||||||
"private": false,
|
"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": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,30 +26,39 @@
|
|||||||
"npm"
|
"npm"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.63",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.37",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.71",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"@types/node": "^12.7.9"
|
"@types/node": "^18.0.0",
|
||||||
|
"tslint": "^6.0.0",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.11",
|
"@pushrocks/lik": "^6.0.0",
|
||||||
"@pushrocks/smartfile": "^7.0.6",
|
"@pushrocks/smartfile": "^10.0.2",
|
||||||
"@pushrocks/smartfm": "^2.0.4",
|
"@pushrocks/smartfm": "^2.0.4",
|
||||||
"@pushrocks/smarthbs": "^2.0.8",
|
"@pushrocks/smarthbs": "^2.0.8",
|
||||||
"@pushrocks/smartinteract": "^2.0.4",
|
"@pushrocks/smartinteract": "^2.0.11",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartparam": "^1.1.6",
|
||||||
"@pushrocks/smartyaml": "^2.0.3"
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
|
"@pushrocks/smartshell": "^2.0.30",
|
||||||
|
"@pushrocks/smartyaml": "^2.0.5"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_*/**/*",
|
||||||
"dist_ts_web/*",
|
"dist_ts/**/*",
|
||||||
"assets/*",
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
25
readme.md
25
readme.md
@ -8,13 +8,20 @@ scaffold projects quickly
|
|||||||
* [docs (typedoc)](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/@pushrocks/smartscaf)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartscaf)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
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)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -27,6 +34,10 @@ For further information read the linked docs at the top of this README.
|
|||||||
|
|
||||||
[](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.
|
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)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
import * as smartscaf from '../ts/index';
|
import * as smartscaf from '../ts/index.js';
|
||||||
|
|
||||||
process.env.CI = 'true';
|
process.env.CI = 'true';
|
||||||
|
|
||||||
@ -9,12 +9,12 @@ let testScafTemplate: smartscaf.ScafTemplate;
|
|||||||
|
|
||||||
tap.test('should create new Smartscaf instance', async () => {
|
tap.test('should create new Smartscaf instance', async () => {
|
||||||
testScafTemplate = new smartscaf.ScafTemplate('./test/test_template');
|
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();
|
await testScafTemplate.readTemplateFromDir();
|
||||||
expect(testScafTemplate.templateSmartfileArray.length).to.equal(6);
|
expect(testScafTemplate.templateSmartfileArray.length).toEqual(6);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('smartfile -> should accept variables', async () => {
|
tap.test('smartfile -> should accept variables', async () => {
|
||||||
|
@ -8,3 +8,6 @@ defaults:
|
|||||||
dependencies:
|
dependencies:
|
||||||
merge:
|
merge:
|
||||||
- ../test_template_2
|
- ../test_template_2
|
||||||
|
|
||||||
|
runafter:
|
||||||
|
- npm install
|
@ -1,3 +1,6 @@
|
|||||||
|
---
|
||||||
|
fileName: anothername.yml
|
||||||
|
---
|
||||||
# this is a {{templateObject.value1}}
|
# this is a {{templateObject.value1}}
|
||||||
# this is a {{templateObject.value2}}
|
# this is a {{templateObject.value2}}
|
||||||
# this is a {{templateVar3}}
|
# this is a {{templateVar3}}
|
||||||
|
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.2',
|
||||||
|
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,5 +1,5 @@
|
|||||||
import * as plugins from './smartscaf.plugins';
|
import * as plugins from './smartscaf.plugins.js';
|
||||||
import * as helpers from './smartscaf.helpers';
|
import * as interfaces from './interfaces/index.js';
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
import { Smartfile } from '@pushrocks/smartfile';
|
import { Smartfile } from '@pushrocks/smartfile';
|
||||||
@ -11,31 +11,37 @@ export interface ScafTemplateContructorOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ScafTemplate {
|
export class ScafTemplate {
|
||||||
static async createTemplateFromDir() {}
|
public static async createTemplateFromDir() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the name of the template
|
* the name of the template
|
||||||
*/
|
*/
|
||||||
name: string;
|
public name: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the descriptions of the template
|
* the descriptions of the template
|
||||||
*/
|
*/
|
||||||
description: string;
|
public description: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the location on disk of the template
|
* the location on disk of the template
|
||||||
*/
|
*/
|
||||||
dirPath: string;
|
public dirPath: string;
|
||||||
|
public destinationPath: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* smartscafFile
|
||||||
|
*/
|
||||||
|
public smartscafFile: interfaces.ISmartscafFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the files of the template as array of Smartfiles
|
* the files of the template as array of Smartfiles
|
||||||
*/
|
*/
|
||||||
templateSmartfileArray: Smartfile[];
|
public templateSmartfileArray: Smartfile[];
|
||||||
requiredVariables: string[];
|
public requiredVariables: string[];
|
||||||
defaultVariables: any;
|
public defaultVariables: any;
|
||||||
suppliedVariables: any = {};
|
public suppliedVariables: any = {};
|
||||||
missingVariables: string[] = [];
|
public missingVariables: string[] = [];
|
||||||
|
|
||||||
constructor(dirPathArg: string) {
|
constructor(dirPathArg: string) {
|
||||||
this.dirPath = plugins.path.resolve(dirPathArg);
|
this.dirPath = plugins.path.resolve(dirPathArg);
|
||||||
@ -44,8 +50,32 @@ export class ScafTemplate {
|
|||||||
/**
|
/**
|
||||||
* read a template from a directory
|
* read a template from a directory
|
||||||
*/
|
*/
|
||||||
async readTemplateFromDir() {
|
public async readTemplateFromDir() {
|
||||||
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(this.dirPath, '**/*');
|
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._resolveTemplateDependencies();
|
||||||
await this._findVariablesInTemplate();
|
await this._findVariablesInTemplate();
|
||||||
await this._checkSuppliedVariables();
|
await this._checkSuppliedVariables();
|
||||||
@ -56,10 +86,10 @@ export class ScafTemplate {
|
|||||||
* supply the variables to render the teplate with
|
* supply the variables to render the teplate with
|
||||||
* @param variablesArg gets merged with this.suppliedVariables
|
* @param variablesArg gets merged with this.suppliedVariables
|
||||||
*/
|
*/
|
||||||
async supplyVariables(variablesArg) {
|
public async supplyVariables(variablesArg) {
|
||||||
this.suppliedVariables = {
|
this.suppliedVariables = {
|
||||||
...this.suppliedVariables,
|
...this.suppliedVariables,
|
||||||
...variablesArg
|
...variablesArg,
|
||||||
};
|
};
|
||||||
this.missingVariables = await this._checkSuppliedVariables();
|
this.missingVariables = await this._checkSuppliedVariables();
|
||||||
}
|
}
|
||||||
@ -67,10 +97,10 @@ export class ScafTemplate {
|
|||||||
/**
|
/**
|
||||||
* 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,
|
name: missingVariable,
|
||||||
@ -82,37 +112,39 @@ export class ScafTemplate {
|
|||||||
return 'undefined variable';
|
return 'undefined variable';
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
message: `What is the value of ${missingVariable}?`
|
message: `What is the value of ${missingVariable}?`,
|
||||||
}
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
let answerBucket = await localSmartInteract.runQueue();
|
const answerBucket = await localSmartInteract.runQueue();
|
||||||
await answerBucket.answerMap.forEach(async answer => {
|
const answers = answerBucket.getAllAnswers();
|
||||||
await helpers.deepAddToObject(this.suppliedVariables, answer.name, answer.value);
|
for (const answer of answers) {
|
||||||
});
|
await plugins.smartparam.smartAdd(this.suppliedVariables, answer.name, answer.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* writes a file to disk
|
* writes a file to disk
|
||||||
* @param destinationDirArg
|
* @param destinationDirArg
|
||||||
*/
|
*/
|
||||||
async writeToDisk(destinationDirArg) {
|
public async writeToDisk(destinationDirArg) {
|
||||||
|
this.destinationPath = destinationDirArg;
|
||||||
const smartfileArrayToWrite: Smartfile[] = [];
|
const smartfileArrayToWrite: Smartfile[] = [];
|
||||||
for (let smartfile of this.templateSmartfileArray) {
|
for (const smartfile of this.templateSmartfileArray) {
|
||||||
// lets filter out template files
|
// lets filter out template files
|
||||||
if (smartfile.path === '.smartscaf.yml') {
|
if (smartfile.path === '.smartscaf.yml') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// render the template
|
// render the template
|
||||||
let template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString());
|
const template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString());
|
||||||
let renderedTemplateString = template(this.suppliedVariables);
|
const renderedTemplateString = template(this.suppliedVariables);
|
||||||
|
|
||||||
// handle frontmatter
|
// handle frontmatter
|
||||||
const smartfmInstance = new plugins.smartfm.Smartfm({
|
const smartfmInstance = new plugins.smartfm.Smartfm({
|
||||||
fmType: 'yaml'
|
fmType: 'yaml',
|
||||||
});
|
});
|
||||||
let parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any;
|
const parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any;
|
||||||
if (parsedTemplate.data.fileName) {
|
if (parsedTemplate.data.fileName) {
|
||||||
smartfile.updateFileName(parsedTemplate.data.fileName);
|
smartfile.updateFileName(parsedTemplate.data.fileName);
|
||||||
}
|
}
|
||||||
@ -122,6 +154,7 @@ export class ScafTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
|
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
|
||||||
|
await this.runScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,8 +163,8 @@ export class ScafTemplate {
|
|||||||
*/
|
*/
|
||||||
private async _findVariablesInTemplate() {
|
private async _findVariablesInTemplate() {
|
||||||
let templateVariables: string[] = [];
|
let templateVariables: string[] = [];
|
||||||
for (let templateSmartfile of this.templateSmartfileArray) {
|
for (const templateSmartfile of this.templateSmartfileArray) {
|
||||||
let localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(
|
const localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(
|
||||||
templateSmartfile.contents.toString()
|
templateSmartfile.contents.toString()
|
||||||
);
|
);
|
||||||
templateVariables = [...templateVariables, ...localTemplateVariables];
|
templateVariables = [...templateVariables, ...localTemplateVariables];
|
||||||
@ -146,8 +179,8 @@ export class ScafTemplate {
|
|||||||
*/
|
*/
|
||||||
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
|
||||||
);
|
);
|
||||||
@ -176,7 +209,7 @@ export class ScafTemplate {
|
|||||||
* >> - yourDeeperKey: yourValue
|
* >> - yourDeeperKey: yourValue
|
||||||
*/
|
*/
|
||||||
private async _checkDefaultVariables() {
|
private async _checkDefaultVariables() {
|
||||||
let smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => {
|
const smartscafSmartfile = this.templateSmartfileArray.find((smartfileArg) => {
|
||||||
return smartfileArg.parsedPath.base === '.smartscaf.yml';
|
return smartfileArg.parsedPath.base === '.smartscaf.yml';
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -199,23 +232,8 @@ export class ScafTemplate {
|
|||||||
* resolve template dependencies
|
* resolve template dependencies
|
||||||
*/
|
*/
|
||||||
private async _resolveTemplateDependencies() {
|
private async _resolveTemplateDependencies() {
|
||||||
const smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => {
|
|
||||||
return smartfileArg.parsedPath.base === '.smartscaf.yml';
|
|
||||||
});
|
|
||||||
if (!smartscafSmartfile) {
|
|
||||||
console.log('No further template dependencies defined!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log('Found template dependencies! Resolving them now!');
|
|
||||||
console.log('looking at templates to merge!');
|
console.log('looking at templates to merge!');
|
||||||
const smartscafYamlObject = await plugins.smartyaml.yamlStringToObject(
|
for (const dependency of this.smartscafFile.dependencies.merge) {
|
||||||
smartscafSmartfile.contentBuffer.toString()
|
|
||||||
);
|
|
||||||
if (!smartscafYamlObject) {
|
|
||||||
console.log('Something seems strange about the supplied dependencies.yml file.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const dependency of smartscafYamlObject.dependencies.merge) {
|
|
||||||
console.log(`Now resolving ${dependency}`);
|
console.log(`Now resolving ${dependency}`);
|
||||||
const templatePathToMerge = plugins.path.join(this.dirPath, dependency);
|
const templatePathToMerge = plugins.path.join(this.dirPath, dependency);
|
||||||
if (!plugins.smartfile.fs.isDirectory(templatePathToMerge)) {
|
if (!plugins.smartfile.fs.isDirectory(templatePathToMerge)) {
|
||||||
@ -231,4 +249,16 @@ export class ScafTemplate {
|
|||||||
this.templateSmartfileArray = this.templateSmartfileArray.concat(templateSmartfileArray);
|
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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +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
|
|
||||||
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!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
@ -4,7 +4,20 @@ import * as smartfile from '@pushrocks/smartfile';
|
|||||||
import * as smartfm from '@pushrocks/smartfm';
|
import * as smartfm from '@pushrocks/smartfm';
|
||||||
import * as smarthbs from '@pushrocks/smarthbs';
|
import * as smarthbs from '@pushrocks/smarthbs';
|
||||||
import * as smartinteract from '@pushrocks/smartinteract';
|
import * as smartinteract from '@pushrocks/smartinteract';
|
||||||
import * as smartq from '@pushrocks/smartpromise';
|
import * as smartparam from '@pushrocks/smartparam';
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartyaml from '@pushrocks/smartyaml';
|
import * as smartyaml from '@pushrocks/smartyaml';
|
||||||
|
import * as smartshell from '@pushrocks/smartshell';
|
||||||
|
|
||||||
export { path, lik, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml };
|
export {
|
||||||
|
path,
|
||||||
|
lik,
|
||||||
|
smartfile,
|
||||||
|
smartfm,
|
||||||
|
smarthbs,
|
||||||
|
smartinteract,
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user