clasp-types
Version:
A d.ts generator for clasp projects
81 lines (80 loc) • 3.53 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReadmeBuilder = void 0;
var Builder_1 = require("./Builder");
var ReadmeBuilder = /** @class */ (function (_super) {
__extends(ReadmeBuilder, _super);
function ReadmeBuilder(packageJson, claspJson) {
var _this = _super.call(this) || this;
_this.packageJson = packageJson;
_this.claspJson = claspJson;
return _this;
}
ReadmeBuilder.prototype.build = function () {
var org = this.extractOrg();
this
.append("# Summary").doubleLine()
.append("This package contains Typescript definitions for [" + this.claspJson.library.name + "](" + this.extractHomepage() + ")").doubleLine()
.append("# Instalation").doubleLine()
.append('### 1) Add the package:').doubleLine()
.append('```').line()
.append("npm i -S " + this.packageJson.name).line()
.append('```').line()
.append('or').line()
.append('```').line()
.append("yarn add --dev " + this.packageJson.name).line()
.append('```').doubleLine()
.append("### 2) Configure tsconfig.json:").doubleLine()
.append('```').line()
.append('{').line()
.append(' "compilerOptions": {').line();
if (org) {
this.append(" \"typeRoots\" : [\"node_modules/" + org + "\", \"node_modules/@types\" ]").line();
}
else {
this.append(" \"types\" : [\"" + this.packageJson.name + "\", \"google-apps-script\"]").line();
}
this.append(' }').line()
.append('}').line()
.append('```').doubleLine()
.append('[Learn more](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types) about **@types**, **typeRoots** and **types**').doubleLine();
this.append('# Details').doubleLine()
.append("Generated using [clasp-types](https://github.com/maelcaldas/clasp-types)").doubleLine();
return this;
};
ReadmeBuilder.prototype.extractOrg = function () {
if (this.packageJson.name.startsWith('@')) {
return this.packageJson.name.split('/')[0];
}
return null;
};
ReadmeBuilder.prototype.extractHomepage = function () {
if (this.packageJson.homepage) {
return this.packageJson.homepage;
}
if (this.packageJson.repository) {
if (typeof this.packageJson.repository === 'string') {
return this.packageJson.repository;
}
else {
return this.packageJson.repository.url.replace('\\.git', '');
}
}
return 'https://developers.google.com/apps-script/guides/libraries';
};
return ReadmeBuilder;
}(Builder_1.Builder));
exports.ReadmeBuilder = ReadmeBuilder;