@adonisjs/sink
Advanced tools
Comparing version 2.4.6 to 2.5.0
@@ -35,4 +35,5 @@ import { PromptContract } from '@poppinss/prompts'; | ||
export { KeyValueFile } from './src/base/KeyValueFile'; | ||
export { DotTemplate } from './src/formats/DotTemplate'; | ||
export { TemplateFile } from './src/formats/TemplateFile'; | ||
export { copyFiles, deleteFiles, makeDirs } from 'mrm-core'; | ||
export { executeInstructions } from './src/executeInstructions'; |
@@ -68,2 +68,4 @@ "use strict"; | ||
exports.KeyValueFile = KeyValueFile_1.KeyValueFile; | ||
var DotTemplate_1 = require("./src/formats/DotTemplate"); | ||
exports.DotTemplate = DotTemplate_1.DotTemplate; | ||
var TemplateFile_1 = require("./src/formats/TemplateFile"); | ||
@@ -70,0 +72,0 @@ exports.TemplateFile = TemplateFile_1.TemplateFile; |
{ | ||
"name": "@adonisjs/sink", | ||
"version": "2.4.6", | ||
"version": "2.5.0", | ||
"description": "Utilities to create AdonisJs boilerplates and custom providers", | ||
@@ -32,3 +32,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@adonisjs/application": "^1.3.6", | ||
"@adonisjs/application": "^1.3.9", | ||
"@adonisjs/dev-utils": "^1.4.0", | ||
@@ -39,3 +39,3 @@ "@adonisjs/fold": "^6.3.4", | ||
"@types/ini": "^1.3.30", | ||
"@types/marked": "^0.7.2", | ||
"@types/marked": "^0.7.3", | ||
"@types/node": "^13.7.7", | ||
@@ -52,7 +52,7 @@ "@types/yaml": "^1.2.0", | ||
"japa": "^3.0.1", | ||
"mrm": "^2.1.0", | ||
"mrm": "^2.1.1", | ||
"np": "^5.2.1", | ||
"ts-node": "^8.6.2", | ||
"ts-node": "^8.8.1", | ||
"typescript": "^3.8.3", | ||
"yaml": "^1.7.2" | ||
"yaml": "^1.8.3" | ||
}, | ||
@@ -82,6 +82,7 @@ "nyc": { | ||
"@poppinss/utils": "^2.1.2", | ||
"fs-extra": "^8.1.0", | ||
"marked": "^0.8.0", | ||
"mrm-core": "^4.0.2", | ||
"open": "^7.0.2" | ||
"dot": "^1.1.3", | ||
"fs-extra": "^9.0.0", | ||
"marked": "^0.8.2", | ||
"mrm-core": "^4.0.3", | ||
"open": "^7.0.3" | ||
}, | ||
@@ -88,0 +89,0 @@ "peerDependencies": { |
@@ -5,2 +5,4 @@ import { ApplicationContract } from '@ioc:Adonis/Core/Application'; | ||
dest: string; | ||
dotSyntax?: boolean; | ||
data?: any; | ||
} | string; | ||
@@ -7,0 +9,0 @@ /** |
@@ -14,5 +14,19 @@ "use strict"; | ||
const logger_1 = require("./logger"); | ||
const DotTemplate_1 = require("./formats/DotTemplate"); | ||
const TemplateFile_1 = require("./formats/TemplateFile"); | ||
const colors = new colors_1.Colors(); | ||
/** | ||
* Normalizes the template node | ||
*/ | ||
function normalizeTemplateNode(templateNode) { | ||
templateNode = typeof (templateNode) === 'string' ? { | ||
src: templateNode, | ||
dest: templateNode.replace(new RegExp(`${path_1.extname(templateNode)}$`), ''), | ||
dotSyntax: false, | ||
data: {}, | ||
} : templateNode; | ||
templateNode.dest = path_1.extname(templateNode.dest) === '' ? `${templateNode.dest}.ts` : templateNode.dest; | ||
return templateNode; | ||
} | ||
/** | ||
* Copy multiple templates to the user project. | ||
@@ -47,10 +61,3 @@ */ | ||
: [templates[templateFor]]; | ||
/** | ||
* Loop and copy each template to the source | ||
*/ | ||
templatesToCopy.forEach((templateToCopy) => { | ||
const src = typeof (templateToCopy) === 'string' ? templateToCopy : templateToCopy.src; | ||
let dest = typeof (templateToCopy) === 'string' | ||
? templateToCopy.replace(new RegExp(`${path_1.extname(templateToCopy)}$`), '.ts') | ||
: path_1.extname(templateToCopy.dest) === '' ? `${templateToCopy.dest}.ts` : templateToCopy.dest; | ||
templatesToCopy.map(normalizeTemplateNode).forEach(({ src, dest, dotSyntax, data }) => { | ||
if (!src || !dest) { | ||
@@ -61,3 +68,5 @@ throw new Error('src and dest are required when copying templates'); | ||
const destinationPath = path_1.normalize(`${configuredDirectory}/${dest}`); | ||
const template = new TemplateFile_1.TemplateFile(projectRoot, destinationPath, sourcePath); | ||
const template = dotSyntax | ||
? new DotTemplate_1.DotTemplate(projectRoot, destinationPath, sourcePath) | ||
: new TemplateFile_1.TemplateFile(projectRoot, destinationPath, sourcePath); | ||
/** | ||
@@ -70,3 +79,3 @@ * Skip when file already exists | ||
} | ||
template.apply({}).commit(); | ||
template.apply(data || {}).commit(); | ||
logger_1.logger.create(destinationPath); | ||
@@ -73,0 +82,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import { template } from 'mrm-core'; | ||
import { file } from 'mrm-core'; | ||
import { BaseFile } from '../base/BaseFile'; | ||
@@ -7,4 +7,7 @@ /** | ||
export declare class TemplateFile extends BaseFile { | ||
private templatePath; | ||
private templateData; | ||
private whitespace; | ||
protected $actions: never[]; | ||
filePointer: ReturnType<typeof template>; | ||
filePointer: ReturnType<typeof file>; | ||
removeOnRollback: boolean; | ||
@@ -14,2 +17,6 @@ overwrite: boolean; | ||
/** | ||
* Returns the contents of the template file | ||
*/ | ||
private readTemplate; | ||
/** | ||
* Returns existing contents for a template file | ||
@@ -27,2 +34,7 @@ */ | ||
/** | ||
* Control whether or not to render whitespace. It is enabled by | ||
* default | ||
*/ | ||
renderWhitespace(whitespaceFlag: boolean): this; | ||
/** | ||
* Commit changes | ||
@@ -29,0 +41,0 @@ */ |
@@ -10,4 +10,9 @@ "use strict"; | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const dot_1 = __importDefault(require("dot")); | ||
const mrm_core_1 = require("mrm-core"); | ||
const fs_1 = require("fs"); | ||
const BaseFile_1 = require("../base/BaseFile"); | ||
@@ -20,2 +25,5 @@ /** | ||
super(basePath); | ||
this.templatePath = templatePath; | ||
this.templateData = {}; | ||
this.whitespace = true; | ||
this.$actions = []; | ||
@@ -25,6 +33,22 @@ this.removeOnRollback = true; | ||
this.$cdIn(); | ||
this.filePointer = mrm_core_1.template(filename, templatePath); | ||
this.filePointer = mrm_core_1.file(filename); | ||
this.$cdOut(); | ||
} | ||
/** | ||
* Returns the contents of the template file | ||
*/ | ||
readTemplate() { | ||
try { | ||
return fs_1.readFileSync(this.templatePath, 'utf8'); | ||
} | ||
catch (err) { | ||
if (err.code === 'ENOENT') { | ||
throw Error(`Template file not found: ${this.templatePath}`); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
} | ||
/** | ||
* Returns existing contents for a template file | ||
@@ -45,6 +69,14 @@ */ | ||
apply(contents) { | ||
this.filePointer.apply(contents); | ||
this.templateData = contents || {}; | ||
return this; | ||
} | ||
/** | ||
* Control whether or not to render whitespace. It is enabled by | ||
* default | ||
*/ | ||
renderWhitespace(whitespaceFlag) { | ||
this.whitespace = whitespaceFlag; | ||
return this; | ||
} | ||
/** | ||
* Commit changes | ||
@@ -62,4 +94,13 @@ */ | ||
} | ||
this.filePointer.save(); | ||
this.$cdOut(); | ||
try { | ||
const templateFn = dot_1.default.template(this.readTemplate(), Object.assign({}, dot_1.default.templateSettings, { | ||
strip: !this.whitespace, | ||
})); | ||
this.filePointer.save(templateFn(this.templateData)); | ||
this.$cdOut(); | ||
} | ||
catch (error) { | ||
this.$cdOut(); | ||
throw error; | ||
} | ||
} | ||
@@ -66,0 +107,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84185
37
2460
10
7
+ Addeddot@^1.1.3
+ Addedat-least-node@1.0.0(transitive)
+ Addeddot@1.1.3(transitive)
+ Addedfs-extra@9.1.0(transitive)
+ Addedjsonfile@6.1.0(transitive)
+ Addeduniversalify@2.0.1(transitive)
Updatedfs-extra@^9.0.0
Updatedmarked@^0.8.2
Updatedmrm-core@^4.0.3
Updatedopen@^7.0.3