diff --git a/.gitignore b/.gitignore index 706b9f9f8..4a75cbf4a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ cov-pt* **/test/temp .release.json package-lock.json + +scripts/tsconfig.json +packages/pug-error/lib diff --git a/README.md b/README.md index 256546577..fb57f0768 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ + # Pug Full documentation is at [pugjs.org](https://pugjs.org/) @@ -9,7 +10,7 @@ feature requests and questions, [open an issue](https://github.com/pugjs/pug/iss For discussion join the [chat room](https://gitter.im/pugjs/pug). You can test drive Pug online [here](https://pugjs.org/). - + [Professionally supported pug is now available](https://tidelift.com/subscription/pkg/npm-pug?utm_source=npm-pug&utm_medium=referral&utm_campaign=readme) [![Build Status](https://img.shields.io/github/workflow/status/pugjs/pug/Test/master?style=for-the-badge)](https://github.com/pugjs/pug/actions?query=workflow%3ATest+branch%3Amaster) @@ -17,23 +18,24 @@ You can test drive Pug online [here](https://pugjs.org/). [![NPM version](https://img.shields.io/npm/v/pug?style=for-the-badge)](https://www.npmjs.com/package/pug) [![Join Gitter Chat](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg?style=for-the-badge)](https://gitter.im/pugjs/pug?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -### Dependency Status - -| Package | Dependencies | Dev Dependencies | -| ------------- |:-------------| :-----| -| mono-repo top | [![Dependency Status](https://img.shields.io/david/pugjs/pug.svg?style=flat)](https://david-dm.org/pugjs/pug) | [![devDependencies Status](https://img.shields.io/david/dev/pugjs/pug.svg?style=flat)](https://david-dm.org/pugjs/pug?type=dev) | -| pug | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug)](https://david-dm.org/pugjs/pug?path=packages/pug) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug)](https://david-dm.org/pugjs/pug?path=packages/pug&type=dev) | -| pug-attrs | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-attrs)](https://david-dm.org/pugjs/pug?path=packages/pug-attrs) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-attrs)](https://david-dm.org/pugjs/pug?path=packages/pug-attrs&type=dev) | -| pug-code-gen | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-code-gen)](https://david-dm.org/pugjs/pug?path=packages/pug-code-gen) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-code-gen)](https://david-dm.org/pugjs/pug?path=packages/pug-code-gen&type=dev) | -| pug-error | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-error)](https://david-dm.org/pugjs/pug?path=packages/pug-error) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-error)](https://david-dm.org/pugjs/pug?path=packages/pug-error&type=dev) | -| pug-filters | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-filters)](https://david-dm.org/pugjs/pug?path=packages/pug-filters) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-filters)](https://david-dm.org/pugjs/pug?path=packages/pug-filters&type=dev) | -| pug-lexer | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-lexer)](https://david-dm.org/pugjs/pug?path=packages/pug-lexer) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-lexer)](https://david-dm.org/pugjs/pug?path=packages/pug-lexer&type=dev) | -| pug-linker | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-linker)](https://david-dm.org/pugjs/pug?path=packages/pug-linker) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-linker)](https://david-dm.org/pugjs/pug?path=packages/pug-linker&type=dev) | -| pug-load | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-load)](https://david-dm.org/pugjs/pug?path=packages/pug-load) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-load)](https://david-dm.org/pugjs/pug?path=packages/pug-load&type=dev) | -| pug-parser | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-parser)](https://david-dm.org/pugjs/pug?path=packages/pug-parser) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-parser)](https://david-dm.org/pugjs/pug?path=packages/pug-parser&type=dev) | -| pug-runtime | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-runtime)](https://david-dm.org/pugjs/pug?path=packages/pug-runtime) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-runtime)](https://david-dm.org/pugjs/pug?path=packages/pug-runtime&type=dev) | -| pug-strip-comments | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-strip-comments)](https://david-dm.org/pugjs/pug?path=packages/pug-strip-comments) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-strip-comments)](https://david-dm.org/pugjs/pug?path=packages/pug-strip-comments&type=dev) | -| pug-walk | [![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-walk)](https://david-dm.org/pugjs/pug?path=packages/pug-walk) | [![Dependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-walk)](https://david-dm.org/pugjs/pug?path=packages/pug-walk&type=dev) | +## Packages + + +Package Name | Version +-------------|-------- +pug | [![NPM version](https://img.shields.io/npm/v/pug?style=for-the-badge)](https://www.npmjs.com/package/pug) +pug-attrs | [![NPM version](https://img.shields.io/npm/v/pug-attrs?style=for-the-badge)](https://www.npmjs.com/package/pug-attrs) +pug-code-gen | [![NPM version](https://img.shields.io/npm/v/pug-code-gen?style=for-the-badge)](https://www.npmjs.com/package/pug-code-gen) +pug-error | [![NPM version](https://img.shields.io/npm/v/pug-error?style=for-the-badge)](https://www.npmjs.com/package/pug-error) +pug-filters | [![NPM version](https://img.shields.io/npm/v/pug-filters?style=for-the-badge)](https://www.npmjs.com/package/pug-filters) +pug-lexer | [![NPM version](https://img.shields.io/npm/v/pug-lexer?style=for-the-badge)](https://www.npmjs.com/package/pug-lexer) +pug-linker | [![NPM version](https://img.shields.io/npm/v/pug-linker?style=for-the-badge)](https://www.npmjs.com/package/pug-linker) +pug-load | [![NPM version](https://img.shields.io/npm/v/pug-load?style=for-the-badge)](https://www.npmjs.com/package/pug-load) +pug-parser | [![NPM version](https://img.shields.io/npm/v/pug-parser?style=for-the-badge)](https://www.npmjs.com/package/pug-parser) +pug-runtime | [![NPM version](https://img.shields.io/npm/v/pug-runtime?style=for-the-badge)](https://www.npmjs.com/package/pug-runtime) +pug-strip-comments | [![NPM version](https://img.shields.io/npm/v/pug-strip-comments?style=for-the-badge)](https://www.npmjs.com/package/pug-strip-comments) +pug-walk | [![NPM version](https://img.shields.io/npm/v/pug-walk?style=for-the-badge)](https://www.npmjs.com/package/pug-walk) + ## Rename from "Jade" @@ -41,7 +43,7 @@ This project was formerly known as "Jade". However, it was revealed to us that " If your package or app currently uses `jade`, don't worry: we have secured permissions to continue to occupy that package name, although all new versions will be released under `pug`. -Before the renaming, work had already begun on “Jade 2.0.0”. Therefore, the rename to Pug coincided with the major version bump. As a result, upgrading from Jade to Pug will be the same process as upgrading any other package with a major version bump. +Before the renaming, work had already begun on “Jade 2.0.0”. Therefore, the rename to Pug coincided with the major version bump. As a result, upgrading from Jade to Pug will be the same process as upgrading any other package with a major version bump. The syntax of Pug has several differences, deprecations, and removals compared to its predecessor. These differences are documented in [#2305](https://github.com/pugjs/pug/issues/2305). @@ -57,7 +59,6 @@ To use Pug in your own JavaScript projects: $ npm install pug ``` - ### Command Line After installing the latest version of [Node.js](http://nodejs.org), install with: @@ -74,7 +75,7 @@ $ pug --help ## Syntax -Pug is a clean, whitespace sensitive syntax for writing HTML. Here is a simple example: +Pug is a clean, whitespace sensitive syntax for writing HTML. Here is a simple example: ```pug doctype html @@ -82,7 +83,7 @@ html(lang="en") head title= pageTitle script(type='text/javascript'). - if (foo) bar(1 + 5) + if (foo) bar(1 + 5); body h1 Pug - node template engine #container.col @@ -97,21 +98,23 @@ html(lang="en") Pug transforms the above to: - ```html Pug

Pug - node template engine

You are amazing

-

Pug is a terse and simple templating language with a strong focus on performance and powerful features.

+

+ Pug is a terse and simple templating language with a strong focus on + performance and powerful features. +

@@ -137,15 +140,15 @@ var html = pug.renderFile('filename.pug', merge(options, locals)); ### Options - - `filename` Used in exceptions, and required when using includes - - `compileDebug` When `false` no debug instrumentation is compiled - - `pretty` Add pretty-indentation whitespace to output _(`false` by default)_ +- `filename` Used in exceptions, and required when using includes +- `compileDebug` When `false` no debug instrumentation is compiled +- `pretty` Add pretty-indentation whitespace to output _(`false` by default)_ ## Browser Support -The latest version of pug can be [downloaded for the browser in standalone form](https://pugjs.org/js/pug.js). It only supports the very latest browsers, though, and is a large file. It is recommended that you pre-compile your pug templates to JavaScript. +The latest version of pug can be [downloaded for the browser in standalone form](https://pugjs.org/js/pug.js). It only supports the very latest browsers, though, and is a large file. It is recommended that you pre-compile your pug templates to JavaScript. - To compile a template for use on the client using the command line, do: +To compile a template for use on the client using the command line, do: ```bash $ pug --client --no-debug filename.pug @@ -155,9 +158,9 @@ which will produce `filename.js` containing the compiled template. ## Tutorials - - cssdeck interactive [Pug syntax tutorial](http://cssdeck.com/labs/learning-the-jade-templating-engine-syntax) - - cssdeck interactive [Pug logic tutorial](http://cssdeck.com/labs/jade-templating-tutorial-codecast-part-2) - - [Pug について。](https://gist.github.com/japboy/5402844) (A Japanese Tutorial) +- cssdeck interactive [Pug syntax tutorial](http://cssdeck.com/labs/learning-the-jade-templating-engine-syntax) +- cssdeck interactive [Pug logic tutorial](http://cssdeck.com/labs/jade-templating-tutorial-codecast-part-2) +- [Pug について。](https://gist.github.com/japboy/5402844) (A Japanese Tutorial) ## Implementations in other languages @@ -165,53 +168,53 @@ which will produce `filename.js` containing the compiled template. Ports to other languages, with very close syntax: - - [PHP](https://github.com/pug-php/pug) - - [Java](https://github.com/neuland/jade4j) - - [Python](https://github.com/kakulukia/pypugjs) - - [Ruby](https://github.com/yivo/pug-ruby) - - [C# (ASP.NET Core)](https://github.com/AspNetMonsters/pugzor) - - [RPG/ILE](https://github.com/WorksOfLiam/apug) +- [PHP](https://github.com/pug-php/pug) +- [Java](https://github.com/neuland/jade4j) +- [Python](https://github.com/kakulukia/pypugjs) +- [Ruby](https://github.com/yivo/pug-ruby) +- [C# (ASP.NET Core)](https://github.com/AspNetMonsters/pugzor) +- [RPG/ILE](https://github.com/WorksOfLiam/apug) ### Equivalents in other languages Templates engines for other languages with a different syntax, but a similar philosophy: - - [Scaml for Scala](https://scalate.github.io/scalate/documentation/scaml-reference.html) - - [Slim for Ruby](https://github.com/slim-template/slim) (should not be confused with Slim PHP framework) - - [HAML for Ruby](http://haml.info) - +- [Scaml for Scala](https://scalate.github.io/scalate/documentation/scaml-reference.html) +- [Slim for Ruby](https://github.com/slim-template/slim) (should not be confused with Slim PHP framework) +- [HAML for Ruby](http://haml.info) + ### Framework implementations/adapters Embedded view engines for frameworks: - - [Laravel](https://github.com/BKWLD/laravel-pug) - - [Symfony](https://github.com/pug-php/pug-symfony) - - [Phalcon](https://github.com/pug-php/pug-phalcon) - - [CodeIgniter](https://github.com/pug-php/ci-pug-engine) - - [Yii 2](https://github.com/pug-php/pug-yii2) - - [Slim 3](https://github.com/pug-php/pug-slim) - - [Silex (implementation example)](https://gist.github.com/kylekatarnls/ba13e4361ab14f4ff5d2a5775eb0cc10) - - [Lumen](https://github.com/BKWLD/laravel-pug#use-in-lumen) - - [Rails](https://github.com/yivo/pug-rails) +- [Laravel](https://github.com/BKWLD/laravel-pug) +- [Symfony](https://github.com/pug-php/pug-symfony) +- [Phalcon](https://github.com/pug-php/pug-phalcon) +- [CodeIgniter](https://github.com/pug-php/ci-pug-engine) +- [Yii 2](https://github.com/pug-php/pug-yii2) +- [Slim 3](https://github.com/pug-php/pug-slim) +- [Silex (implementation example)](https://gist.github.com/kylekatarnls/ba13e4361ab14f4ff5d2a5775eb0cc10) +- [Lumen](https://github.com/BKWLD/laravel-pug#use-in-lumen) +- [Rails](https://github.com/yivo/pug-rails) ### CMS plugins - - [WordPress](https://github.com/welaika/wordless) +- [WordPress](https://github.com/welaika/wordless) ## Additional Resources - - [Emacs Mode](https://github.com/brianc/jade-mode) - - [Vim Syntax](https://github.com/digitaltoad/vim-pug) - - [TextMate Bundle](http://github.com/miksago/jade-tmbundle) - - [Coda/SubEtha syntax Mode](https://github.com/aaronmccall/jade.mode) - - [html2pug](https://github.com/donpark/html2jade) converter - - [pug2php](https://github.com/SE7ENSKY/jade2php) converter - - [Pug Server](https://github.com/ctrlaltdev/pug-server) Ideal for building local prototypes apart from any application - - [cache-pug-templates](https://github.com/ladjs/cache-pug-templates) Cache Pug templates for [Lad](https://github.com/ladjs/lad)/[Koa](https://github.com/koajs/koa)/[Express](https://github.com/expressjs/express)/[Connect](https://github.com/senchalabs/connect) with [Redis](https://redis.io) - - [Prettier Plugin](https://github.com/prettier/plugin-pug) - +- [Emacs Mode](https://github.com/brianc/jade-mode) +- [Vim Syntax](https://github.com/digitaltoad/vim-pug) +- [TextMate Bundle](http://github.com/miksago/jade-tmbundle) +- [Coda/SubEtha syntax Mode](https://github.com/aaronmccall/jade.mode) +- [html2pug](https://github.com/donpark/html2jade) converter +- [pug2php](https://github.com/SE7ENSKY/jade2php) converter +- [Pug Server](https://github.com/ctrlaltdev/pug-server) Ideal for building local prototypes apart from any application +- [cache-pug-templates](https://github.com/ladjs/cache-pug-templates) Cache Pug templates for [Lad](https://github.com/ladjs/lad)/[Koa](https://github.com/koajs/koa)/[Express](https://github.com/expressjs/express)/[Connect](https://github.com/senchalabs/connect) with [Redis](https://redis.io) +- [Prettier Plugin](https://github.com/prettier/plugin-pug) ## Backers + Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/pug#backer)] @@ -246,6 +249,7 @@ Support us with a monthly donation and help us continue our activities. [[Become ## Sponsors + Become a sponsor and get your logo on our README on GitHub with a link to your site. [[Become a sponsor](https://opencollective.com/pug#sponsor)] diff --git a/package.json b/package.json index ba40c0720..06c9476ab 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,9 @@ "devDependencies": { "coveralls": "3.0.9", "jest": "^26.0.1", - "prettier": "1.19.1" + "prettier": "1.19.1", + "typescript": "^4.1.2", + "wsrun": "^5.2.0" }, "repository": { "type": "git", @@ -17,7 +19,7 @@ "scripts": { "prettier:check": "prettier --ignore-path .gitignore --list-different './**/*.js'", "format": "prettier --ignore-path .gitignore --write './**/*.js'", - "build": "wsrun --stages --exclude-missing --fast-exit --collect-logs build", + "build": "node scripts/prebuild && wsrun --stages --exclude-missing --fast-exit --collect-logs build && tsc --build scripts", "pretest": "yarn build", "test": "jest", "coverage": "jest --coverage", @@ -32,8 +34,5 @@ "./scripts/buffer-serializer.js" ] }, - "license": "MIT", - "dependencies": { - "wsrun": "^5.2.0" - } + "license": "MIT" } diff --git a/packages/pug-error/package.json b/packages/pug-error/package.json index 2cf393930..f0864d379 100644 --- a/packages/pug-error/package.json +++ b/packages/pug-error/package.json @@ -2,11 +2,13 @@ "name": "pug-error", "version": "1.3.3", "description": "Standard error objects for pug", + "main": "./lib/index.js", + "types": "./lib/index.d.ts", "keywords": [ "pug" ], "files": [ - "index.js" + "lib/" ], "repository": { "type": "git", diff --git a/packages/pug-error/index.js b/packages/pug-error/src/index.ts similarity index 53% rename from packages/pug-error/index.js rename to packages/pug-error/src/index.ts index 9bc75135d..087b606d1 100644 --- a/packages/pug-error/index.js +++ b/packages/pug-error/src/index.ts @@ -1,24 +1,25 @@ -'use strict'; - -module.exports = makeError; -function makeError(code, message, options) { - var line = options.line; - var column = options.column; - var filename = options.filename; - var src = options.src; - var fullMessage; - var location = line + (column ? ':' + column : ''); +export default function makeError( + code: string, + message: string, + options: {line: number; column: number; filename?: string; src?: string}, +) { + const line = options.line; + const column = options.column; + const filename = options.filename; + const src = options.src; + let fullMessage; + const location = line + (column ? ':' + column : ''); if (src && line >= 1 && line <= src.split('\n').length) { - var lines = src.split('\n'); - var start = Math.max(line - 3, 0); - var end = Math.min(lines.length, line + 3); + const lines = src.split('\n'); + const start = Math.max(line - 3, 0); + const end = Math.min(lines.length, line + 3); // Error context - var context = lines + const context = lines .slice(start, end) .map(function(text, i) { - var curr = i + start + 1; - var preamble = (curr == line ? ' > ' : ' ') + curr + '| '; - var out = preamble + text; + const curr = i + start + 1; + const preamble = (curr == line ? ' > ' : ' ') + curr + '| '; + let out = preamble + text; if (curr === line && column > 0) { out += '\n'; out += Array(preamble.length + column).join('-') + '^'; @@ -31,7 +32,7 @@ function makeError(code, message, options) { } else { fullMessage = (filename || 'Pug') + ':' + location + '\n\n' + message; } - var err = new Error(fullMessage); + const err: any = new Error(fullMessage); err.code = 'PUG:' + code; err.msg = message; err.line = line; @@ -49,3 +50,7 @@ function makeError(code, message, options) { }; return err; } + +// Make this easier to use from CommonJS +module.exports = makeError; +module.exports.default = makeError; diff --git a/packages/pug-error/test/index.test.js b/packages/pug-error/test/index.test.js index 19aca14a3..7008fa853 100644 --- a/packages/pug-error/test/index.test.js +++ b/packages/pug-error/test/index.test.js @@ -1,6 +1,5 @@ 'use strict'; -var assert = require('assert'); var error = require('../'); describe('with a source', function() { diff --git a/packages/pug-error/tsconfig.json b/packages/pug-error/tsconfig.json new file mode 100644 index 000000000..1233d3d8c --- /dev/null +++ b/packages/pug-error/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "composite": true, + "rootDir": "src", + "outDir": "lib", + "tsBuildInfoFile": "lib/tsconfig.tsbuildinfo", + }, + "references": [], +} diff --git a/packages/pug-strip-comments/LICENSE b/packages/pug-strip-comments/LICENSE new file mode 100644 index 000000000..e2a4f77b0 --- /dev/null +++ b/packages/pug-strip-comments/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2021 Forbes Lindesay + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/scripts/prebuild.js b/scripts/prebuild.js new file mode 100644 index 000000000..7df2ccd82 --- /dev/null +++ b/scripts/prebuild.js @@ -0,0 +1,132 @@ +const { + readdirSync, + writeFileSync, + statSync, + readFileSync, + existsSync, +} = require('fs'); + +const LICENSE = `Copyright (c) ${new Date().getFullYear()} Forbes Lindesay + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.`; + +const packageNames = []; +const typeScriptPackages = []; +const packageDirectories = readdirSync(__dirname + '/../packages') + .filter(directory => + statSync(__dirname + '/../packages/' + directory).isDirectory() + ) + .sort(); +packageDirectories.forEach(directory => { + if (!existsSync(__dirname + '/../packages/' + directory + '/LICENSE')) { + writeFileSync( + __dirname + '/../packages/' + directory + '/LICENSE', + LICENSE + ); + } + let pkg = {}; + try { + pkg = JSON.parse( + readFileSync( + __dirname + '/../packages/' + directory + '/package.json', + 'utf8' + ) + ); + } catch (ex) { + if (ex.code !== 'ENOENT') { + throw ex; + } + } + const before = JSON.stringify(pkg); + if (!pkg.name) { + pkg.name = directory; + } + packageNames.push(pkg.name); + const after = JSON.stringify(pkg); + if (before !== after) { + writeFileSync( + __dirname + '/../packages/' + directory + '/package.json', + JSON.stringify(pkg, null, ' ') + '\n' + ); + } + if (existsSync(__dirname + '/../packages/' + directory + '/tsconfig.json')) { + typeScriptPackages.push(directory); + const deps = [ + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.devDependencies || {}), + ] + .filter(dep => + existsSync(__dirname + '/../packages/' + dep + '/tsconfig.json') + ) + .map( + dep => + `\n {"path": ${JSON.stringify( + `../${dep.substr(`@databases/`.length)}` + )}},` + ) + .join(``); + writeFileSync( + __dirname + '/../packages/' + directory + '/tsconfig.json', + `{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "composite": true, + "rootDir": "src", + "outDir": "lib", + "tsBuildInfoFile": "lib/tsconfig.tsbuildinfo", + }, + "references": ${deps.length ? `[${deps}\n ],` : `[],`} +} +` + ); + } +}); + +writeFileSync( + `scripts/tsconfig.json`, + `{ + "extends": "../tsconfig.json", + "references": [${typeScriptPackages + .map(n => `\n {"path": ${JSON.stringify(`../packages/${n}`)}},`) + .join(``)} + ], +}` +); +const [README_HEADER, _table, README_FOOTER] = readFileSync( + __dirname + '/../README.md', + 'utf8' +).split(''); + +const versionsTable = ` +Package Name | Version +-------------|-------- +${packageNames + .sort() + .map( + name => + `${name} | [![NPM version](https://img.shields.io/npm/v/${name}?style=for-the-badge)](https://www.npmjs.com/package/${name})` + ) + .join('\n')} +`; +writeFileSync( + __dirname + '/../README.md', + [README_HEADER, versionsTable, README_FOOTER || ''].join( + '' + ) +); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..a5df34e36 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES5", + "module": "commonjs", + "declaration": true, + "sourceMap": true, + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": false, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "lib": ["es2016", "dom"], + "pretty": true + } +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index aebbb3fa2..0c402c83a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4039,6 +4039,11 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" +typescript@^4.1.2: + version "4.5.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.4.tgz#a17d3a0263bf5c8723b9c52f43c5084edf13c2e8" + integrity sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg== + uc.micro@^1.0.1, uc.micro@^1.0.5: version "1.0.6" resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac"