newlicense
commit
c32e3b4e3d
@ -0,0 +1,107 @@
|
||||
Define a template directory and write a README template for your
|
||||
project then compile it into a proper README.
|
||||
|
||||
## Installation
|
||||
```bash
|
||||
$ deno install --name readme-manager --reload --allow-all https://deno.land/x/readme_manager/cli.ts
|
||||
```
|
||||
|
||||
## Usage
|
||||
On the first run without any arguments a setup will happen :
|
||||
- `match` corresponds to the name the README template will have inside the repository
|
||||
it is created on first start but you can always recreate it with `--setup`
|
||||
(default `.README.template.md`)
|
||||
- `templates` corresponds to the path where the rendering function is stored
|
||||
it is boostrapped on first start but you can always access it with `--bootstrap`
|
||||
(default `$USER_CONFIG_DIR/readme-manager`)
|
||||
|
||||
```bash
|
||||
$ readme-manager
|
||||
# Will guide you through setup on first run
|
||||
|
||||
$ readme-manager
|
||||
# Will create readme in current directory with template and config
|
||||
|
||||
$ readme-manager my-project
|
||||
# Will create readme in my-project directory with template and config
|
||||
|
||||
$ readme-manager [...] --templates [path]
|
||||
# Will create a readme with config match and overriden template directory
|
||||
|
||||
$ readme-manager [...] --match [name]
|
||||
# Will create a readme with config template directory and overriden match name
|
||||
|
||||
$ readme-manager [...] --templates [path] --match [name]
|
||||
# Will create a readme and bypass configuration (if it exists)
|
||||
```
|
||||
|
||||
There are also some other commands :
|
||||
```bash
|
||||
$ readme-manager --help
|
||||
# Will print the help page
|
||||
|
||||
$ readme-manager --setup
|
||||
# Re-run setup step and backup old config
|
||||
|
||||
$ readme-manager --bootstrap
|
||||
# Re-run templates boostrapping step and backup old directory
|
||||
```
|
||||
|
||||
There is also a debug flag available that can be added to any command :
|
||||
```bash
|
||||
$ readme-manager [...] --debug
|
||||
# Will print more information to console and save all logs to the log file (instead of only errors by default)
|
||||
```
|
||||
|
||||
## Example
|
||||
You can check out the current templates I use for my project (including this readme) [over here](https://code.eutychia.org/kay/readme-templates).
|
||||
|
||||
## Templating
|
||||
When you bootstrap the templates forlder, 3 examples files will be create for you :
|
||||
- README.template.md: this is the base file that gets used when rendering your readme. You can await stuff in it. **This is the only required file**
|
||||
- HEADER.template.md: is an example header you might use
|
||||
- FOOTER.template.md: is an example footer you might use
|
||||
|
||||
Feel free to adjust, remove or add any files you might want. Simply keep in mind that `README.template.md` is required and will be the base for rendering.
|
||||
|
||||
Any file in the templates folder will be automatically required and available by its filename with `await include(filename)`.
|
||||
|
||||
Any file that starts with `.` will be ignored.
|
||||
|
||||
## Template variables
|
||||
The following variables are available to the template (on `it`):
|
||||
- name: basename of the folder the README is in
|
||||
- readme: content of the readme template file
|
||||
- readmeFilePath: the absolute filepath of the readme
|
||||
- readmeDirectoryPath: the absolute path of the directory containing the readme
|
||||
- gitTag: the current git tag
|
||||
- gitURL: the repository url
|
||||
- gitCommit: the sha of the current commit
|
||||
- gitBranch: the current checkout out branch
|
||||
|
||||
You can use javascript inside the templates and also async templates for data fetching (see Eta docs)
|
||||
|
||||
**Make sure to `await` any includes you do !** As templates are compiled in async mode for await support (even if you are not using it).
|
||||
|
||||
## Templating docs
|
||||
The templating engine use is https://deno.land/x/eta@v1.12.3.
|
||||
|
||||
More information about it can be found on their documentation.
|
||||
|
||||
## Suggestion
|
||||
If you are going to be using this for many repositories you might want tot setup a git template folder and add a precommit hook that runs the `readme-manager`.
|
||||
|
||||
Here is what mine looks like:
|
||||
```bash
|
||||
# ~/.git-templates/hooks/pre-commit
|
||||
# git config --global init.templatedir '~/.git-templates'
|
||||
# git init
|
||||
|
||||
#!/usr/bin/env bash
|
||||
~/.deno/bin/readme-manager
|
||||
git add -u
|
||||
```
|
||||
|
||||
## Documentation
|
||||
Documentation view is currently disabled for third party modules on deno.land/x but you can still view the auto generated docs on [doc.deno.land](https://doc.deno.land/https://deno.land/x/readme_manager)
|
||||
|
@ -0,0 +1,2 @@
|
||||
cov
|
||||
cov.lcov
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
include:
|
||||
- project: "kay/ci-templates"
|
||||
file:
|
||||
- "/Semantic-Release.gitlab-ci.yml"
|
||||
|
||||
stages:
|
||||
- review
|
@ -0,0 +1,202 @@
|
||||
# [3.0.0](https://code.eutychia.org/kay/readme-manager/compare/v2.8.0...v3.0.0) (2022-07-04)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* oops ([97bfabd](https://code.eutychia.org/kay/readme-manager/commit/97bfabd58f56e5ea2fc76178a0027ef446092292))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* include requires await
|
||||
|
||||
# [2.8.0](https://code.eutychia.org/kay/readme-manager/compare/v2.7.0...v2.8.0) (2022-07-04)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* ig tahts breaking actually mb ([5d96d48](https://code.eutychia.org/kay/readme-manager/commit/5d96d482b8c6d78fea9e3f77bff3d5fb564f0104))
|
||||
|
||||
# [2.7.0](https://code.eutychia.org/kay/readme-manager/compare/v2.6.1...v2.7.0) (2022-07-04)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Nested template async support ([857c0fa](https://code.eutychia.org/kay/readme-manager/commit/857c0fae57f55857b174a6b55858dc663a590fbb))
|
||||
|
||||
## [2.6.1](https://code.eutychia.org/kay/readme-manager/compare/v2.6.0...v2.6.1) (2022-07-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Auto generated docs link ([278e133](https://code.eutychia.org/kay/readme-manager/commit/278e1333b67fc669f89ac056a9b6a5cc60534cce))
|
||||
|
||||
# [2.6.0](https://code.eutychia.org/kay/readme-manager/compare/v2.5.0...v2.6.0) (2022-07-03)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Try to have the docs show up ([dea013b](https://code.eutychia.org/kay/readme-manager/commit/dea013b28a257cda629f2e09b34edac1044a511b))
|
||||
|
||||
# [2.5.0](https://code.eutychia.org/kay/readme-manager/compare/v2.4.0...v2.5.0) (2022-07-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* doc escape [skip ci] ([91f5ab8](https://code.eutychia.org/kay/readme-manager/commit/91f5ab8c1b6edead7c2b965c15edaa014dcb576a))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add docs and tests ([ad3c4fb](https://code.eutychia.org/kay/readme-manager/commit/ad3c4fbfffc22b5dc8b7c7b47dcc88b566d404d2))
|
||||
|
||||
# [2.4.0](https://code.eutychia.org/kay/readme-manager/compare/v2.3.1...v2.4.0) (2022-07-02)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* disable autoescape and autotrim ([aa02fe3](https://code.eutychia.org/kay/readme-manager/commit/aa02fe39094dd494a69b47e6247c18e362b796a0))
|
||||
|
||||
## [2.3.1](https://code.eutychia.org/kay/readme-manager/compare/v2.3.0...v2.3.1) (2022-07-02)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* update info about hook in readme ([3eef132](https://code.eutychia.org/kay/readme-manager/commit/3eef132418b0cfd7765ca9c72a095d00a8ece805))
|
||||
|
||||
# [2.3.0](https://code.eutychia.org/kay/readme-manager/compare/v2.2.1...v2.3.0) (2022-07-02)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Check permissions on readdir ([f786724](https://code.eutychia.org/kay/readme-manager/commit/f7867243545e5b4ea8ab1f6dd596025aafdb2a45))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add debug log ([607e9af](https://code.eutychia.org/kay/readme-manager/commit/607e9af6ed9b2d5e8761b6f4623d2a4f5c82c85e))
|
||||
|
||||
## [2.2.1](https://code.eutychia.org/kay/readme-manager/compare/v2.2.0...v2.2.1) (2022-07-02)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Example docs ([6087fb0](https://code.eutychia.org/kay/readme-manager/commit/6087fb01669aa1d00ba6e240bbe532340ab474e4))
|
||||
|
||||
# [2.2.0](https://code.eutychia.org/kay/readme-manager/compare/v2.1.3...v2.2.0) (2022-07-02)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Better async docs and bootstrap demo ([c76b9ce](https://code.eutychia.org/kay/readme-manager/commit/c76b9ce622f52407744eae3a0ceb91fc5ea94f9c))
|
||||
|
||||
## [2.1.3](https://code.eutychia.org/kay/readme-manager/compare/v2.1.2...v2.1.3) (2022-07-02)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fix async rendering ([75ce710](https://code.eutychia.org/kay/readme-manager/commit/75ce710a590141c5a4a83c6d956f8b4b8173c4ab))
|
||||
|
||||
## [2.1.2](https://code.eutychia.org/kay/readme-manager/compare/v2.1.1...v2.1.2) (2022-07-02)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Soft fail on git commands fail ([eed24e5](https://code.eutychia.org/kay/readme-manager/commit/eed24e5409f63ca68a1693dd8fc44da450b12244))
|
||||
|
||||
## [2.1.1](https://code.eutychia.org/kay/readme-manager/compare/v2.1.0...v2.1.1) (2022-07-02)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Add options to render ([a1a5111](https://code.eutychia.org/kay/readme-manager/commit/a1a5111950ece68bda7bc984e092dac7e8b04460))
|
||||
|
||||
# [2.1.0](https://code.eutychia.org/kay/readme-manager/compare/v2.0.2...v2.1.0) (2022-07-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Git variables and better variable docs ([e131d38](https://code.eutychia.org/kay/readme-manager/commit/e131d38bc34f858908e11897e0a7891846ee2fc8))
|
||||
|
||||
## [2.0.2](https://code.eutychia.org/kay/readme-manager/compare/v2.0.1...v2.0.2) (2022-07-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Error handling in render ([9c0c8b0](https://code.eutychia.org/kay/readme-manager/commit/9c0c8b0f47e19a6d606733fdeefe6521508bede2))
|
||||
|
||||
## [2.0.1](https://code.eutychia.org/kay/readme-manager/compare/v2.0.0...v2.0.1) (2022-07-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Docs ([ad2f7a1](https://code.eutychia.org/kay/readme-manager/commit/ad2f7a127a3716e0da767c5e2663780d873478d1))
|
||||
|
||||
# [2.0.0](https://code.eutychia.org/kay/readme-manager/compare/v1.4.2...v2.0.0) (2022-07-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Make templates dir not a deno module ([421817d](https://code.eutychia.org/kay/readme-manager/commit/421817d77b48985afcae00d5dddb22be86cb218a))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* no more mod.ts it doesnt work when distributed
|
||||
|
||||
## [1.4.2](https://code.eutychia.org/kay/readme-manager/compare/v1.4.1...v1.4.2) (2022-07-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Try relative imports since it wants to make it a url idk ([d7b8895](https://code.eutychia.org/kay/readme-manager/commit/d7b88955b9b75eb9fc8e0a323f30dec819f0001f))
|
||||
|
||||
## [1.4.1](https://code.eutychia.org/kay/readme-manager/compare/v1.4.0...v1.4.1) (2022-07-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* woopsies this is going to happen often lol ([54d6836](https://code.eutychia.org/kay/readme-manager/commit/54d683627474edf7179753d98db2436271b9b157))
|
||||
|
||||
# [1.4.0](https://code.eutychia.org/kay/readme-manager/compare/v1.3.1...v1.4.0) (2022-07-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add template module auto cache on boostrap and docs ([e6815eb](https://code.eutychia.org/kay/readme-manager/commit/e6815eb1ee8315e5eb45d5621ca13cd3aa757d1e))
|
||||
|
||||
## [1.3.1](https://code.eutychia.org/kay/readme-manager/compare/v1.3.0...v1.3.1) (2022-07-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Docs ([a197b0c](https://code.eutychia.org/kay/readme-manager/commit/a197b0c3baf752d2a0468818a910097c69d100af))
|
||||
|
||||
# [1.3.0](https://code.eutychia.org/kay/readme-manager/compare/v1.2.0...v1.3.0) (2022-07-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Proper docs ([f46ab00](https://code.eutychia.org/kay/readme-manager/commit/f46ab00d592fa4ad998ca21f3e63c75f482114fc))
|
||||
|
||||
# [1.2.0](https://code.eutychia.org/kay/readme-manager/compare/v1.1.0...v1.2.0) (2022-07-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add templates and match flags ([db76359](https://code.eutychia.org/kay/readme-manager/commit/db76359703c0c33f1007c4a74e33c885fced44b7))
|
||||
|
||||
# [1.1.0](https://code.eutychia.org/kay/readme-manager/compare/v1.0.0...v1.1.0) (2022-07-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Help and bootstrap toggle ([006dc91](https://code.eutychia.org/kay/readme-manager/commit/006dc9179b9fcd49fb6db2b166543f498936561d))
|
||||
|
||||
# 1.0.0 (2022-07-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Init ([8bcfe29](https://code.eutychia.org/kay/readme-manager/commit/8bcfe299e3748d2a50deb5a7e75dfc78bcd3983b))
|
||||
* License and CI ([2c389bc](https://code.eutychia.org/kay/readme-manager/commit/2c389bcf2f6c75169b12dae6ba5eb85971072ab7))
|
@ -0,0 +1,459 @@
|
||||
Attribution-NonCommercial-ShareAlike 4.0 International AntiFascistEdit
|
||||
|
||||
=======================================================================
|
||||
|
||||
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
||||
does not provide legal services or legal advice. Distribution of
|
||||
Creative Commons public licenses does not create a lawyer-client or
|
||||
other relationship. Creative Commons makes its licenses and related
|
||||
information available on an "as-is" basis. Creative Commons gives no
|
||||
warranties regarding its licenses, any material licensed under their
|
||||
terms and conditions, or any related information. Creative Commons
|
||||
disclaims all liability for damages resulting from their use to the
|
||||
fullest extent possible.
|
||||
|
||||
Using Creative Commons Public Licenses
|
||||
|
||||
Creative Commons public licenses provide a standard set of terms and
|
||||
conditions that creators and other rights holders may use to share
|
||||
original works of authorship and other material subject to copyright
|
||||
and certain other rights specified in the public license below. The
|
||||
following considerations are for informational purposes only, are not
|
||||
exhaustive, and do not form part of our licenses.
|
||||
|
||||
Considerations for licensors: Our public licenses are
|
||||
intended for use by those authorized to give the public
|
||||
permission to use material in ways otherwise restricted by
|
||||
copyright and certain other rights. Our licenses are
|
||||
irrevocable. Licensors should read and understand the terms
|
||||
and conditions of the license they choose before applying it.
|
||||
Licensors should also secure all rights necessary before
|
||||
applying our licenses so that the public can reuse the
|
||||
material as expected. Licensors should clearly mark any
|
||||
material not subject to the license. This includes other CC-
|
||||
licensed material, or material used under an exception or
|
||||
limitation to copyright. More considerations for licensors:
|
||||
wiki.creativecommons.org/Considerations_for_licensors
|
||||
|
||||
Considerations for the public: By using one of our public
|
||||
licenses, a licensor grants the public permission to use the
|
||||
licensed material under specified terms and conditions. If
|
||||
the licensor's permission is not necessary for any reason--for
|
||||
example, because of any applicable exception or limitation to
|
||||
copyright--then that use is not regulated by the license. Our
|
||||
licenses grant only permissions under copyright and certain
|
||||
other rights that a licensor has authority to grant. Use of
|
||||
the licensed material may still be restricted for other
|
||||
reasons, including because others have copyright or other
|
||||
rights in the material. A licensor may make special requests,
|
||||
such as asking that all changes be marked or described.
|
||||
Although not required by our licenses, you are encouraged to
|
||||
respect those requests where reasonable. More considerations
|
||||
for the public:
|
||||
wiki.creativecommons.org/Considerations_for_licensees
|
||||
|
||||
=======================================================================
|
||||
|
||||
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
|
||||
Public License
|
||||
|
||||
By exercising the Licensed Rights (defined below), You accept and agree
|
||||
to be bound by the terms and conditions of this Creative Commons
|
||||
Attribution-NonCommercial-ShareAlike 4.0 International Public License
|
||||
("Public License"). To the extent this Public License may be
|
||||
interpreted as a contract, You are granted the Licensed Rights in
|
||||
consideration of Your acceptance of these terms and conditions, and the
|
||||
Licensor grants You such rights in consideration of benefits the
|
||||
Licensor receives from making the Licensed Material available under
|
||||
these terms and conditions.
|
||||
|
||||
|
||||
Section 1 -- Definitions.
|
||||
|
||||
a. Adapted Material means material subject to Copyright and Similar
|
||||
Rights that is derived from or based upon the Licensed Material
|
||||
and in which the Licensed Material is translated, altered,
|
||||
arranged, transformed, or otherwise modified in a manner requiring
|
||||
permission under the Copyright and Similar Rights held by the
|
||||
Licensor. For purposes of this Public License, where the Licensed
|
||||
Material is a musical work, performance, or sound recording,
|
||||
Adapted Material is always produced where the Licensed Material is
|
||||
synched in timed relation with a moving image.
|
||||
|
||||
b. Adapter's License means the license You apply to Your Copyright
|
||||
and Similar Rights in Your contributions to Adapted Material in
|
||||
accordance with the terms and conditions of this Public License.
|
||||
|
||||
c. BY-NC-SA Compatible License means a license listed at
|
||||
creativecommons.org/compatiblelicenses, approved by Creative
|
||||
Commons as essentially the equivalent of this Public License.
|
||||
|
||||
d. Copyright and Similar Rights means copyright and/or similar rights
|
||||
closely related to copyright including, without limitation,
|
||||
performance, broadcast, sound recording, and Sui Generis Database
|
||||
Rights, without regard to how the rights are labeled or
|
||||
categorized. For purposes of this Public License, the rights
|
||||
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
||||
Rights.
|
||||
|
||||
e. Effective Technological Measures means those measures that, in the
|
||||
absence of proper authority, may not be circumvented under laws
|
||||
fulfilling obligations under Article 11 of the WIPO Copyright
|
||||
Treaty adopted on December 20, 1996, and/or similar international
|
||||
agreements.
|
||||
|
||||
f. Exceptions and Limitations means fair use, fair dealing, and/or
|
||||
any other exception or limitation to Copyright and Similar Rights
|
||||
that applies to Your use of the Licensed Material.
|
||||
|
||||
g. License Elements means the license attributes listed in the name
|
||||
of a Creative Commons Public License. The License Elements of this
|
||||
Public License are Attribution, NonCommercial, and ShareAlike.
|
||||
|
||||
h. Licensed Material means the artistic or literary work, database,
|
||||
or other material to which the Licensor applied this Public
|
||||
License.
|
||||
|
||||
i. Licensed Rights means the rights granted to You subject to the
|
||||
terms and conditions of this Public License, which are limited to
|
||||
all Copyright and Similar Rights that apply to Your use of the
|
||||
Licensed Material and that the Licensor has authority to license.
|
||||
|
||||
j. Licensor means the individual(s) or entity(ies) granting rights
|
||||
under this Public License.
|
||||
|
||||
k. NonCommercial means not primarily intended for or directed towards
|
||||
commercial advantage or monetary compensation. For purposes of
|
||||
this Public License, the exchange of the Licensed Material for
|
||||
other material subject to Copyright and Similar Rights by digital
|
||||
file-sharing or similar means is NonCommercial provided there is
|
||||
no payment of monetary compensation in connection with the
|
||||
exchange.
|
||||
|
||||
l. Share means to provide material to the public by any means or
|
||||
process that requires permission under the Licensed Rights, such
|
||||
as reproduction, public display, public performance, distribution,
|
||||
dissemination, communication, or importation, and to make material
|
||||
available to the public including in ways that members of the
|
||||
public may access the material from a place and at a time
|
||||
individually chosen by them.
|
||||
|
||||
m. Sui Generis Database Rights means rights other than copyright
|
||||
resulting from Directive 96/9/EC of the European Parliament and of
|
||||
the Council of 11 March 1996 on the legal protection of databases,
|
||||
as amended and/or succeeded, as well as other essentially
|
||||
equivalent rights anywhere in the world.
|
||||
|
||||
n. You means the individual or entity exercising the Licensed Rights
|
||||
under this Public License. Your has a corresponding meaning.
|
||||
|
||||
|
||||
Section 2 -- Scope.
|
||||
|
||||
a. License grant.
|
||||
|
||||
1. Subject to the terms and conditions of this Public License,
|
||||
the Licensor hereby grants You a worldwide, royalty-free,
|
||||
non-sublicensable, non-exclusive, irrevocable license to
|
||||
exercise the Licensed Rights in the Licensed Material to:
|
||||
|
||||
a. reproduce and Share the Licensed Material, in whole or
|
||||
in part, for NonCommercial purposes only; and
|
||||
|
||||
b. produce, reproduce, and Share Adapted Material for
|
||||
NonCommercial purposes only.
|
||||
|
||||
2. Exceptions and Limitations. For the avoidance of doubt, where
|
||||
Exceptions and Limitations apply to Your use, this Public
|
||||
License does not apply, and You do not need to comply with
|
||||
its terms and conditions.
|
||||
|
||||
3. Term. The term of this Public License is specified in Section
|
||||
6(a).
|
||||
|
||||
4. Media and formats; technical modifications allowed. The
|
||||
Licensor authorizes You to exercise the Licensed Rights in
|
||||
all media and formats whether now known or hereafter created,
|
||||
and to make technical modifications necessary to do so. The
|
||||
Licensor waives and/or agrees not to assert any right or
|
||||
authority to forbid You from making technical modifications
|
||||
necessary to exercise the Licensed Rights, including
|
||||
technical modifications necessary to circumvent Effective
|
||||
Technological Measures. For purposes of this Public License,
|
||||
simply making modifications authorized by this Section 2(a)
|
||||
(4) never produces Adapted Material.
|
||||
|
||||
5. Downstream recipients.
|
||||
|
||||
a. Offer from the Licensor -- Licensed Material. Every
|
||||
recipient of the Licensed Material automatically
|
||||
receives an offer from the Licensor to exercise the
|
||||
Licensed Rights under the terms and conditions of this
|
||||
Public License.
|
||||
|
||||
b. Additional offer from the Licensor -- Adapted Material.
|
||||
Every recipient of Adapted Material from You
|
||||
automatically receives an offer from the Licensor to
|
||||
exercise the Licensed Rights in the Adapted Material
|
||||
under the conditions of the Adapter's License You apply.
|
||||
|
||||
c. No downstream restrictions. You may not offer or impose
|
||||
any additional or different terms or conditions on, or
|
||||
apply any Effective Technological Measures to, the
|
||||
Licensed Material if doing so restricts exercise of the
|
||||
Licensed Rights by any recipient of the Licensed
|
||||
Material.
|
||||
|
||||
6. No endorsement. Nothing in this Public License constitutes or
|
||||
may be construed as permission to assert or imply that You
|
||||
are, or that Your use of the Licensed Material is, connected
|
||||
with, or sponsored, endorsed, or granted official status by,
|
||||
the Licensor or others designated to receive attribution as
|
||||
provided in Section 3(a)(1)(A)(i).
|
||||
|
||||
b. Other rights.
|
||||
|
||||
1. Moral rights, such as the right of integrity, are not
|
||||
licensed under this Public License, nor are publicity,
|
||||
privacy, and/or other similar personality rights; however, to
|
||||
the extent possible, the Licensor waives and/or agrees not to
|
||||
assert any such rights held by the Licensor to the limited
|
||||
extent necessary to allow You to exercise the Licensed
|
||||
Rights, but not otherwise.
|
||||
|
||||
2. Patent and trademark rights are not licensed under this
|
||||
Public License.
|
||||
|
||||
3. To the extent possible, the Licensor waives any right to
|
||||
collect royalties from You for the exercise of the Licensed
|
||||
Rights, whether directly or through a collecting society
|
||||
under any voluntary or waivable statutory or compulsory
|
||||
licensing scheme. In all other cases the Licensor expressly
|
||||
reserves any right to collect such royalties, including when
|
||||
the Licensed Material is used other than for NonCommercial
|
||||
purposes.
|
||||
|
||||
|
||||
Section 3 -- License Conditions.
|
||||
|
||||
Your exercise of the Licensed Rights is expressly made subject to the
|
||||
following conditions.
|
||||
|
||||
a. Attribution.
|
||||
|
||||
1. If You Share the Licensed Material (including in modified
|
||||
form), You must:
|
||||
|
||||
a. retain the following if it is supplied by the Licensor
|
||||
with the Licensed Material:
|
||||
|
||||
i. identification of the creator(s) of the Licensed
|
||||
Material and any others designated to receive
|
||||
attribution, in any reasonable manner requested by
|
||||
the Licensor (including by pseudonym if
|
||||
designated);
|
||||
|
||||
ii. a copyright notice;
|
||||
|
||||
iii. a notice that refers to this Public License;
|
||||
|
||||
iv. a notice that refers to the disclaimer of
|
||||
warranties;
|
||||
|
||||
v. a URI or hyperlink to the Licensed Material to the
|
||||
extent reasonably practicable;
|
||||
|
||||
b. indicate if You modified the Licensed Material and
|
||||
retain an indication of any previous modifications; and
|
||||
|
||||
c. indicate the Licensed Material is licensed under this
|
||||
Public License, and include the text of, or the URI or
|
||||
hyperlink to, this Public License.
|
||||
|
||||
2. You may satisfy the conditions in Section 3(a)(1) in any
|
||||
reasonable manner based on the medium, means, and context in
|
||||
which You Share the Licensed Material. For example, it may be
|
||||
reasonable to satisfy the conditions by providing a URI or
|
||||
hyperlink to a resource that includes the required
|
||||
information.
|
||||
3. If requested by the Licensor, You must remove any of the
|
||||
information required by Section 3(a)(1)(A) to the extent
|
||||
reasonably practicable.
|
||||
|
||||
b. ShareAlike.
|
||||
|
||||
In addition to the conditions in Section 3(a), if You Share
|
||||
Adapted Material You produce, the following conditions also apply.
|
||||
|
||||
1. The Adapter's License You apply must be a Creative Commons
|
||||
license with the same License Elements, this version or
|
||||
later, or a BY-NC-SA Compatible License.
|
||||
|
||||
2. You must include the text of, or the URI or hyperlink to, the
|
||||
Adapter's License You apply. You may satisfy this condition
|
||||
in any reasonable manner based on the medium, means, and
|
||||
context in which You Share Adapted Material.
|
||||
|
||||
3. You may not offer or impose any additional or different terms
|
||||
or conditions on, or apply any Effective Technological
|
||||
Measures to, Adapted Material that restrict exercise of the
|
||||
rights granted under the Adapter's License You apply.
|
||||
|
||||
|
||||
Section 4 -- Sui Generis Database Rights.
|
||||
|
||||
Where the Licensed Rights include Sui Generis Database Rights that
|
||||
apply to Your use of the Licensed Material:
|
||||
|
||||
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
||||
to extract, reuse, reproduce, and Share all or a substantial
|
||||
portion of the contents of the database for NonCommercial purposes
|
||||
only;
|
||||
|
||||
b. if You include all or a substantial portion of the database
|
||||
contents in a database in which You have Sui Generis Database
|
||||
Rights, then the database in which You have Sui Generis Database
|
||||
Rights (but not its individual contents) is Adapted Material,
|
||||
including for purposes of Section 3(b); and
|
||||
|
||||
c. You must comply with the conditions in Section 3(a) if You Share
|
||||
all or a substantial portion of the contents of the database.
|
||||
|
||||
For the avoidance of doubt, this Section 4 supplements and does not
|
||||
replace Your obligations under this Public License where the Licensed
|
||||
Rights include other Copyright and Similar Rights.
|
||||
|
||||
|
||||
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
||||
|
||||
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
||||
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
||||
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
||||
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
||||
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
||||
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
||||
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
||||
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
||||
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
||||
|
||||
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
||||
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
||||
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
||||
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
||||
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
||||
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
||||
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
||||
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
||||
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
||||
|
||||
c. The disclaimer of warranties and limitation of liability provided
|
||||
above shall be interpreted in a manner that, to the extent
|
||||
possible, most closely approximates an absolute disclaimer and
|
||||
waiver of all liability.
|
||||
|
||||
|
||||
Section 6 -- Term and Termination.
|
||||
|
||||
a. This Public License applies for the term of the Copyright and
|
||||
Similar Rights licensed here. However, if You fail to comply with
|
||||
this Public License, then Your rights under this Public License
|
||||
terminate automatically.
|
||||
|
||||
b. Where Your right to use the Licensed Material has terminated under
|
||||
Section 6(a), it reinstates:
|
||||
|
||||
1. automatically as of the date the violation is cured, provided
|
||||
it is cured within 30 days of Your discovery of the
|
||||
violation; or
|
||||
|
||||
2. upon express reinstatement by the Licensor.
|
||||
|
||||
For the avoidance of doubt, this Section 6(b) does not affect any
|
||||
right the Licensor may have to seek remedies for Your violations
|
||||
of this Public License.
|
||||
|
||||
c. For the avoidance of doubt, the Licensor may also offer the
|
||||
Licensed Material under separate terms or conditions or stop
|
||||
distributing the Licensed Material at any time; however, doing so
|
||||
will not terminate this Public License.
|
||||
|
||||
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
||||
License.
|
||||
|
||||
|
||||
Section 7 -- Other Terms and Conditions.
|
||||
|
||||
a. The Licensor shall not be bound by any additional or different
|
||||
terms or conditions communicated by You unless expressly agreed.
|
||||
|
||||
b. Any arrangements, understandings, or agreements regarding the
|
||||
Licensed Material not stated herein are separate from and
|
||||
independent of the terms and conditions of this Public License.
|
||||
|
||||
c. The License does not apply and no license is granted for
|
||||
taking action on behalf of a Nation or State or Government,
|
||||
be it military, law enforcement, agent, spy, hacker, developer,
|
||||
this list is not exhaustive.
|
||||
|
||||
d. The License does not apply and no license is granted to actors
|
||||
taking action to oppress, harm, injure, kill, whether
|
||||
physically or psycholocially.
|
||||
|
||||
e. The License does not apply and no license is granted to actors
|
||||
acting on behalf of any party previously found guilty of committing
|
||||
war crimes at any point in time.
|
||||
|
||||
f. The License does not apply and no license is granted to actors
|
||||
acting on behalf of any party previously found not respecting the
|
||||
Universal Declaration of Human Rights at any point in time.
|
||||
|
||||
g. The License does not apply and no license is granted to actors
|
||||
acting with the intent of surveilling a population or the intent of
|
||||
gathering information on spefific or non-specific populations and/or
|
||||
target demographics.
|
||||
|
||||
|
||||
Section 8 -- Interpretation.
|
||||
|
||||
a. For the avoidance of doubt, this Public License does not, and
|
||||
shall not be interpreted to, reduce, limit, restrict, or impose
|
||||
conditions on any use of the Licensed Material that could lawfully
|
||||
be made without permission under this Public License.
|
||||
|
||||
b. To the extent possible, if any provision of this Public License is
|
||||
deemed unenforceable, it shall be automatically reformed to the
|
||||
minimum extent necessary to make it enforceable. If the provision
|
||||
cannot be reformed, it shall be severed from this Public License
|
||||
without affecting the enforceability of the remaining terms and
|
||||
conditions.
|
||||
|
||||
c. No term or condition of this Public License will be waived and no
|
||||
failure to comply consented to unless expressly agreed to by the
|
||||
Licensor.
|
||||
|
||||
d. Nothing in this Public License constitutes or may be interpreted
|
||||
as a limitation upon, or waiver of, any privileges and immunities
|
||||
that apply to the Licensor or You, including from the legal
|
||||
processes of any jurisdiction or authority.
|
||||
|
||||
=======================================================================
|
||||
|
||||
Creative Commons is not a party to its public
|
||||
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
||||
its public licenses to material it publishes and in those instances
|
||||
will be considered the “Licensor.” The text of the Creative Commons
|
||||
public licenses is dedicated to the public domain under the CC0 Public
|
||||
Domain Dedication. Except for the limited purpose of indicating that
|
||||
material is shared under a Creative Commons public license or as
|
||||
otherwise permitted by the Creative Commons policies published at
|
||||
creativecommons.org/policies, Creative Commons does not authorize the
|
||||
use of the trademark "Creative Commons" or any other trademark or logo
|
||||
of Creative Commons without its prior written consent including,
|
||||
without limitation, in connection with any unauthorized modifications
|
||||
to any of its public licenses or any other arrangements,
|
||||
understandings, or agreements concerning use of licensed material. For
|
||||
the avoidance of doubt, this paragraph does not form part of the
|
||||
public licenses.
|
||||
|
||||
Creative Commons may be contacted at creativecommons.org.
|
@ -0,0 +1,165 @@
|
||||
# [readme-manager](https://code.juke.fr/kay/readme-manager)
|
||||
helps manage and harmonise READMEs in many repositories with template files available on deno.land/x/readme_manager
|
||||
|
||||
Define a template directory and write a README template for your
|
||||
project then compile it into a proper README.
|
||||
|
||||
## Installation
|
||||
```bash
|
||||
$ deno install --name readme-manager --reload --allow-all https://deno.land/x/readme_manager/cli.ts
|
||||
```
|
||||
|
||||
## Usage
|
||||
On the first run without any arguments a setup will happen :
|
||||
- `match` corresponds to the name the README template will have inside the repository
|
||||
it is created on first start but you can always recreate it with `--setup`
|
||||
(default `.README.template.md`)
|
||||
- `templates` corresponds to the path where the rendering function is stored
|
||||
it is boostrapped on first start but you can always access it with `--bootstrap`
|
||||
(default `$USER_CONFIG_DIR/readme-manager`)
|
||||
|
||||
```bash
|
||||
$ readme-manager
|
||||
# Will guide you through setup on first run
|
||||
|
||||
$ readme-manager
|
||||
# Will create readme in current directory with template and config
|
||||
|
||||
$ readme-manager my-project
|
||||
# Will create readme in my-project directory with template and config
|
||||
|
||||
$ readme-manager [...] --templates [path]
|
||||
# Will create a readme with config match and overriden template directory
|
||||
|
||||
$ readme-manager [...] --match [name]
|
||||
# Will create a readme with config template directory and overriden match name
|
||||
|
||||
$ readme-manager [...] --templates [path] --match [name]
|
||||
# Will create a readme and bypass configuration (if it exists)
|
||||
```
|
||||
|
||||
There are also some other commands :
|
||||
```bash
|
||||
$ readme-manager --help
|
||||
# Will print the help page
|
||||
|
||||
$ readme-manager --setup
|
||||
# Re-run setup step and backup old config
|
||||
|
||||
$ readme-manager --bootstrap
|
||||
# Re-run templates boostrapping step and backup old directory
|
||||
```
|
||||
|
||||
There is also a debug flag available that can be added to any command :
|
||||
```bash
|
||||
$ readme-manager [...] --debug
|
||||
# Will print more information to console and save all logs to the log file (instead of only errors by default)
|
||||
```
|
||||
|
||||
## Example
|
||||
You can check out the current templates I use for my project (including this readme) [over here](https://code.eutychia.org/kay/readme-templates).
|
||||
|
||||
## Templating
|
||||
When you bootstrap the templates forlder, 3 examples files will be create for you :
|
||||
- README.template.md: this is the base file that gets used when rendering your readme. You can await stuff in it. **This is the only required file**
|
||||
- HEADER.template.md: is an example header you might use
|
||||
- FOOTER.template.md: is an example footer you might use
|
||||
|
||||
Feel free to adjust, remove or add any files you might want. Simply keep in mind that `README.template.md` is required and will be the base for rendering.
|
||||
|
||||
Any file in the templates folder will be automatically required and available by its filename with `await include(filename)`.
|
||||
|
||||
Any file that starts with `.` will be ignored.
|
||||
|
||||
## Template variables
|
||||
The following variables are available to the template (on `it`):
|
||||
- name: basename of the folder the README is in
|
||||
- readme: content of the readme template file
|
||||
- readmeFilePath: the absolute filepath of the readme
|
||||
- readmeDirectoryPath: the absolute path of the directory containing the readme
|
||||
- gitTag: the current git tag
|
||||
- gitURL: the repository url
|
||||
- gitCommit: the sha of the current commit
|
||||
- gitBranch: the current checkout out branch
|
||||
|
||||
You can use javascript inside the templates and also async templates for data fetching (see Eta docs)
|
||||
|
||||
**Make sure to `await` any includes you do !** As templates are compiled in async mode for await support (even if you are not using it).
|
||||
|
||||
## Templating docs
|
||||
The templating engine use is https://deno.land/x/eta@v1.12.3.
|
||||
|
||||
More information about it can be found on their documentation.
|
||||
|
||||
## Suggestion
|
||||
If you are going to be using this for many repositories you might want tot setup a git template folder and add a precommit hook that runs the `readme-manager`.
|
||||
|
||||
Here is what mine looks like:
|
||||
```bash
|
||||
# ~/.git-templates/hooks/pre-commit
|
||||
# git config --global init.templatedir '~/.git-templates'
|
||||
# git init
|
||||
|
||||
#!/usr/bin/env bash
|
||||
~/.deno/bin/readme-manager
|
||||
git add -u
|
||||
```
|
||||
|
||||
## Documentation
|
||||
Documentation view is currently disabled for third party modules on deno.land/x but you can still view the auto generated docs on [doc.deno.land](https://doc.deno.land/https://deno.land/x/readme_manager)
|
||||
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Most all of my work is now licensed under **a modified** [CC-BY-NC-SA 4.0 AFEdit](https://code.juke.fr/kay/license/raw/branch/main/LICENSE) plus accounting for states existing in our world on top of capitalism.
|
||||
|
||||
This is a weird choice for code right?
|
||||
|
||||
Here are a few key reasons:
|
||||
- my definition of "open" involves being able to share and modify, you are able to do such things, just not make money off of it, or oppress people
|
||||
- my definition of "free" involves being able to share and modify, you are able to do such things, not just make money off of it, or oppressing people
|
||||
|
||||
So no, amongst other things, this list is not exhaustive,
|
||||
- you cannot have somebody work on my tool and redistribute it to your employees
|
||||
- you cannot resell copies of this because in this age distribution is not done with floppy disks and the internet is a thing
|
||||
- you cannot use it to generate revenue yourself
|
||||
- you cannot use it to "generate value" in a capitalistic sense
|
||||
- you cannot use it in any military capacity
|
||||
- you cannot use it in any law enforcement capacity
|
||||
- you cannot use it in any state backed capacity
|
||||
- you cannot use it in any surveillance capacity
|
||||
- you cannot use it if you represent the interests of a state
|
||||
- you cannot use it to oppress, spy, control in any capacity
|
||||
- you cannot use it to injure, harm, kill, whether physically or psychologically
|
||||
|
||||
You can, however,
|
||||
- change it to do whatever you please
|
||||
- share it to anyone you please with attribution and under the same license
|
||||
- use it as much as you please
|
||||
- and probably a bunch of other cool things that are possible outside of a capitalistic, imperialistic frame of reference that permeates the tech scene
|
||||
|
||||
Most of the "arguments" for how "free" and "open" source licenses are done still to this day stem from archaic concepts that might not even be relevant these days and I fail to see the issue with this license not being "interoperable" with a bunch of what I deem to be "bad" licenses, as they all allow for commercial usage.
|
||||
|
||||
I also will not make any attempts to monetize these works and will at most ever offer the possibility to donate to me directly if you enjoy what I do.
|
||||
|
||||
Thank you that is all.
|
||||
|
||||
## Development
|
||||
|
||||
To clone the repository locally:
|
||||
|
||||
```bash
|
||||
$ git clone https://code.juke.fr/kay/readme-manager.git
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
More to come later.
|
||||
|
||||
### Issues
|
||||
Open new issues by mailing [eutychia.gitlab+readme-manager-issue@gmail.com](mailto:eutychia.gitlab+readme-manager-issue@gmail.com)
|
||||
|
||||
---
|
||||
beep boop
|
||||
|
@ -0,0 +1,95 @@
|
||||
import { ensureDir, move } from "https://deno.land/std@0.146.0/fs/mod.ts";
|
||||
import { join, resolve } from "https://deno.land/std@0.146.0/path/mod.ts";
|
||||
|
||||
import { checkExists } from "./utils.ts";
|
||||
|
||||
/**
|
||||
* Base template used to include other.
|
||||
* Allow javascript and async function calls.
|
||||
*/
|
||||
export const readme = `<%~ await include("HEADER.template.md", {...it}) %>
|
||||
|
||||
<% it.javascripted = 13 + 12 %>
|
||||
|
||||
<%= it.javascripted %>
|
||||
|
||||
<% it.asyncJavascripted = await fetch("https://jsonplaceholder.typicode.com/todos/1").then(r => r.json()) %>
|
||||
|
||||
<%= it.readme %>
|
||||
|
||||
<%~ await include("FOOTER.template.md", {...it}) %>`;
|
||||
|
||||
/**
|
||||
* Example header template.
|
||||
*/
|
||||
export const header = `# <%= it.name %>
|
||||
|
||||
<%= it.asyncJavascripted.title %>
|
||||
---
|
||||
`;
|
||||
|
||||
/**
|
||||
* Example footer template.
|
||||
*/
|
||||
export const footer = `---
|
||||
made with k by love
|
||||
|
||||
<%= await fetch("https://jsonplaceholder.typicode.com/todos/2").then(r => r.json()).then(r => JSON.stringify(r)) %>
|
||||
`;
|
||||
|
||||
/**
|
||||
* Bootstrap template files in a specified directory.
|
||||
* Creates the required files for readme-manager.
|
||||
*
|
||||
* ```ts
|
||||
* import { bootstrap } from "./bootstrap.ts"
|
||||
* await bootstrap('/path/to/templates', (errorMsg: string, error?: Error) => {})
|
||||
* ```
|
||||
*
|
||||
* @param {string} templateDirectory Directory where files should be created.
|
||||
* @param {function(string, Error)} error Handler for errors.
|
||||
*/
|
||||
export const bootstrap = async (
|
||||
templateDirectory: string,
|
||||
error: (message: string, error?: Error) => void,
|
||||
) => {
|
||||
if (await checkExists(templateDirectory, error)) {
|
||||
console.log("You ran bootstrap mode with present templates, backing up.");
|
||||
try {
|
||||
await move(templateDirectory, `${templateDirectory}.old`, {
|
||||
overwrite: true,
|
||||
});
|
||||
} catch (e) {
|
||||
error("Something went wrong backing up your templates.", e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await ensureDir(templateDirectory);
|
||||
} catch (e) {
|
||||
error(
|
||||
`Something went wrong trying to create the templates directory at ${templateDirectory}.`,
|
||||
e,
|
||||
);
|
||||
}
|
||||
const readmePath = resolve(join(templateDirectory, "README.template.md"));
|
||||
try {
|
||||
await Deno.writeTextFile(readmePath, readme);
|
||||
} catch (e) {
|
||||
error(`Something went wrong trying to boostrap ${readmePath}.`, e);
|
||||
}
|
||||
const headerPath = resolve(join(templateDirectory, "HEADER.template.md"));
|
||||
try {
|
||||
await Deno.writeTextFile(headerPath, header);
|
||||
} catch (e) {
|
||||
error(`Something went wrong trying to boostrap ${headerPath}.`, e);
|
||||
}
|
||||
const footerPath = resolve(join(templateDirectory, "FOOTER.template.md"));
|
||||
try {
|
||||
await Deno.writeTextFile(footerPath, footer);
|
||||
} catch (e) {
|
||||
error(`Something went wrong trying to boostrap ${footerPath}.`, e);
|
||||
}
|
||||
console.log(`Template bootstrapping done in ${templateDirectory}.`);
|
||||
console.log("Feel free to edit anything to your liking.");
|
||||
};
|
@ -0,0 +1,43 @@
|
||||
import { assertArrayIncludes } from "https://deno.land/std@0.146.0/testing/asserts.ts";
|
||||
import { info } from "https://deno.land/std@0.146.0/log/mod.ts";
|
||||
|
||||
import { bootstrap } from "./bootstrap.ts";
|
||||
|
||||
const testErrorHandler = (message: string, error?: Error) => {
|
||||
info(message);
|
||||
info(error);
|
||||
};
|
||||
|
||||
Deno.test("bootstrap", async (t) => {
|
||||
const testingPath = await Deno.makeTempDir();
|
||||
|
||||
await t.step("creates the required files", async () => {
|
||||
await bootstrap(testingPath, testErrorHandler);
|
||||
|
||||
const files = Array.from(Deno.readDirSync(testingPath));
|
||||
|
||||
assertArrayIncludes(files, [
|
||||
{
|
||||
name: "FOOTER.template.md",
|
||||
isFile: true,
|
||||
isSymlink: false,
|
||||
isDirectory: false,
|
||||
},
|
||||
{
|
||||
name: "HEADER.template.md",
|
||||
isFile: true,
|
||||
isSymlink: false,
|
||||
isDirectory: false,
|
||||
},
|
||||
{
|
||||
name: "README.template.md",
|
||||
isFile: true,
|
||||
isSymlink: false,
|
||||
isDirectory: false,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
await Deno.remove(testingPath, { recursive: true });
|
||||
await Deno.remove(`${testingPath}.old`, { recursive: true });
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
import { parse } from "https://deno.land/std@0.146.0/flags/mod.ts";
|
||||
|
||||
import { help } from "./help.ts";
|
||||
import { manager } from "./manager.ts";
|
||||
|
||||
/**
|
||||
* Cli running mode
|
||||
*
|
||||
* @param {string[]} args The Deno.args array
|
||||
* @returns {Promise<void | string | undefined>}
|
||||
*/
|
||||
export const cli = (args: string[]): Promise<void | string | undefined> => {
|
||||
const parsedArgs = parse(args);
|
||||
|
||||
if (parsedArgs.help) {
|
||||
help.map((msg) => console.log(msg));
|
||||
Deno.exit(0);
|
||||
}
|
||||
|
||||
return manager(parsedArgs, true);
|
||||
};
|
||||
|
||||
await cli(Deno.args);
|
@ -0,0 +1,18 @@
|
||||
{
|
||||
"tasks": {
|
||||
"start": "deno run -A cli.ts",
|
||||
"test": "deno test -A --coverage=cov/"
|
||||
"lint": "deno lint",
|
||||
"fmt": "deno fmt --check",
|
||||
"coverage": "deno coverage --lcov cov/ > cov.lcov"
|
||||
},
|
||||
"importMap": "./import_map.json",
|
||||
"fmt": {
|
||||
"files": {
|
||||
"exclude": [
|
||||
".git",
|
||||
"cov",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
{
|
||||
"version": "2",
|
||||
"remote": {
|
||||
"https://deno.land/std@0.146.0/_deno_unstable.ts": "be3276fd42cffb49f51b705c4b0aa8656aaf2a34be22d769455c8e50ea38e51a",
|
||||
"https://deno.land/std@0.146.0/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74",
|
||||
"https://deno.land/std@0.146.0/_util/os.ts": "3b4c6e27febd119d36a416d7a97bd3b0251b77c88942c8f16ee5953ea13e2e49",
|
||||
"https://deno.land/std@0.146.0/bytes/bytes_list.ts": "aba5e2369e77d426b10af1de0dcc4531acecec27f9b9056f4f7bfbf8ac147ab4",
|
||||
"https://deno.land/std@0.146.0/bytes/equals.ts": "3c3558c3ae85526f84510aa2b48ab2ad7bdd899e2e0f5b7a8ffc85acb3a6043a",
|
||||
"https://deno.land/std@0.146.0/bytes/mod.ts": "763f97d33051cc3f28af1a688dfe2830841192a9fea0cbaa55f927b49d49d0bf",
|
||||
"https://deno.land/std@0.146.0/flags/mod.ts": "594472736e24b2f2afd3451cf7ccd58a21706ce91006478a544fdfa056c69697",
|
||||
"https://deno.land/std@0.146.0/fmt/colors.ts": "6f9340b7fb8cc25a993a99e5efc56fe81bb5af284ff412129dd06df06f53c0b4",
|
||||
"https://deno.land/std@0.146.0/fs/_util.ts": "2cf50bfb1081c2d5f2efec10ac19abbc2baf478e51cd1b057d0da2f30585b6ba",
|
||||
"https://deno.land/std@0.146.0/fs/copy.ts": "9248d1492599957af8c693ceb10a432b09f0b0b61c60a4d6aff29b0c7d3a17b3",
|
||||
"https://deno.land/std@0.146.0/fs/empty_dir.ts": "7274d87160de34cbed0531e284df383045cf43543bbeadeb97feac598bd8f3c5",
|
||||
"https://deno.land/std@0.146.0/fs/ensure_dir.ts": "9dc109c27df4098b9fc12d949612ae5c9c7169507660dcf9ad90631833209d9d",
|
||||
"https://deno.land/std@0.146.0/fs/ensure_file.ts": "7d353e64fee3d4d1e7c6b6726a2a5e987ba402c15fb49566309042887349c545",
|
||||
"https://deno.land/std@0.146.0/fs/ensure_link.ts": "489e23df9fe3e6636048b5830ddf0f111eb29621eb85719255ad9bd645f3471b",
|
||||
"https://deno.land/std@0.146.0/fs/ensure_symlink.ts": "88dc83de1bc90ed883dd458c2d2eae3d5834a4617d12925734836e1f0803b274",
|
||||
"https://deno.land/std@0.146.0/fs/eol.ts": "b92f0b88036de507e7e6fbedbe8f666835ea9dcbf5ac85917fa1fadc919f83a5",
|
||||
"https://deno.land/std@0.146.0/fs/exists.ts": "cb734d872f8554ea40b8bff77ad33d4143c1187eac621a55bf37781a43c56f6d",
|
||||
"https://deno.land/std@0.146.0/fs/expand_glob.ts": "143400698822117018c3646f4b7d2d418bc5cdede1ec837a8c70013b7711c761",
|
||||
"https://deno.land/std@0.146.0/fs/mod.ts": "7111008fcdf935f1bfdf07f881f4d1e152063d146025e9622ae12d1fd5f4d7b8",
|
||||
"https://deno.land/std@0.146.0/fs/move.ts": "0573cedcf583f09a9494f2dfccbf67de68a93629942d6b5e6e74a9e45d4e8a2e",
|
||||
"https://deno.land/std@0.146.0/fs/walk.ts": "6ce8d87fbaeda23383e979599ad27f3f94b3e5ff0c0cd976b5fc5c2aa0df7d92",
|
||||
"https://deno.land/std@0.146.0/io/buffer.ts": "bd0c4bf53db4b4be916ca5963e454bddfd3fcd45039041ea161dbf826817822b",
|
||||
"https://deno.land/std@0.146.0/io/types.d.ts": "0cae3a62da7a37043661746c65c021058bae020b54e50c0e774916e5d4baee43",
|
||||
"https://deno.land/std@0.146.0/log/handlers.ts": "b88c24df61eaeee8581dbef3622f21aebfd061cd2fda49affc1711c0e54d57da",
|
||||
"https://deno.land/std@0.146.0/log/levels.ts": "82c965b90f763b5313e7595d4ba78d5095a13646d18430ebaf547526131604d1",
|
||||
"https://deno.land/std@0.146.0/log/logger.ts": "4d25581bc02dfbe3ad7e8bb480e1f221793a85be5e056185a0cea134f7a7fdf4",
|
||||
"https://deno.land/std@0.146.0/log/mod.ts": "65d2702785714b8d41061426b5c279f11b3dcbc716f3eb5384372a430af63961",
|
||||
"https://deno.land/std@0.146.0/path/_constants.ts": "df1db3ffa6dd6d1252cc9617e5d72165cd2483df90e93833e13580687b6083c3",
|
||||
"https://deno.land/std@0.146.0/path/_interface.ts": "ee3b431a336b80cf445441109d089b70d87d5e248f4f90ff906820889ecf8d09",
|
||||
"https://deno.land/std@0.146.0/path/_util.ts": "c1e9686d0164e29f7d880b2158971d805b6e0efc3110d0b3e24e4b8af2190d2b",
|
||||
"https://deno.land/std@0.146.0/path/common.ts": "bee563630abd2d97f99d83c96c2fa0cca7cee103e8cb4e7699ec4d5db7bd2633",
|
||||
"https://deno.land/std@0.146.0/path/glob.ts": "cb5255638de1048973c3e69e420c77dc04f75755524cb3b2e160fe9277d939ee",
|
||||
"https://deno.land/std@0.146.0/path/mod.ts": "4945b430b759b0b3d98f2a278542cbcf95e0ad2bd8eaaed3c67322b306b2b346",
|
||||
"https://deno.land/std@0.146.0/path/posix.ts": "c1f7afe274290ea0b51da07ee205653b2964bd74909a82deb07b69a6cc383aaa",
|
||||
"https://deno.land/std@0.146.0/path/separator.ts": "fe1816cb765a8068afb3e8f13ad272351c85cbc739af56dacfc7d93d710fe0f9",
|
||||
"https://deno.land/std@0.146.0/path/win32.ts": "bd7549042e37879c68ff2f8576a25950abbfca1d696d41d82c7bca0b7e6f452c",
|
||||
"https://deno.land/std@0.97.0/_util/assert.ts": "2f868145a042a11d5ad0a3c748dcf580add8a0dbc0e876eaa0026303a5488f58",
|
||||
"https://deno.land/std@0.97.0/_util/os.ts": "e282950a0eaa96760c0cf11e7463e66babd15ec9157d4c9ed49cc0925686f6a7",
|
||||
"https://deno.land/std@0.97.0/fs/exists.ts": "b0d2e31654819cc2a8d37df45d6b14686c0cc1d802e9ff09e902a63e98b85a00",
|
||||
"https://deno.land/std@0.97.0/path/_constants.ts": "1247fee4a79b70c89f23499691ef169b41b6ccf01887a0abd131009c5581b853",
|
||||
"https://deno.land/std@0.97.0/path/_interface.ts": "1fa73b02aaa24867e481a48492b44f2598cd9dfa513c7b34001437007d3642e4",
|
||||
"https://deno.land/std@0.97.0/path/_util.ts": "2e06a3b9e79beaf62687196bd4b60a4c391d862cfa007a20fc3a39f778ba073b",
|
||||
"https://deno.land/std@0.97.0/path/common.ts": "eaf03d08b569e8a87e674e4e265e099f237472b6fd135b3cbeae5827035ea14a",
|
||||
"https://deno.land/std@0.97.0/path/glob.ts": "314ad9ff263b895795208cdd4d5e35a44618ca3c6dd155e226fb15d065008652",
|
||||
"https://deno.land/std@0.97.0/path/mod.ts": "4465dc494f271b02569edbb4a18d727063b5dbd6ed84283ff906260970a15d12",
|
||||
"https://deno.land/std@0.97.0/path/posix.ts": "f56c3c99feb47f30a40ce9d252ef6f00296fa7c0fcb6dd81211bdb3b8b99ca3b",
|
||||
"https://deno.land/std@0.97.0/path/separator.ts": "8fdcf289b1b76fd726a508f57d3370ca029ae6976fcde5044007f062e643ff1c",
|
||||
"https://deno.land/std@0.97.0/path/win32.ts": "77f7b3604e0de40f3a7c698e8a79e7f601dc187035a1c21cb1e596666ce112f8",
|
||||
"https://deno.land/x/config_dir@v0.1.1/mod.ts": "02350cd3f96d35dc80f2cfd50cb218ac92cf031893fcc0ba98b80da2172a290a",
|
||||
"https://deno.land/x/eta@v1.12.3/compile-string.ts": "ecd6c10c1f826107758c1d7bbbb609cefeb98f0d6b1f6c7e1088d81febc07f9d",
|
||||
"https://deno.land/x/eta@v1.12.3/compile.ts": "f70e124ef6fc95a359b735dcf73dde5815b0f89611877f5c124f317e0dcff7bc",
|
||||
"https://deno.land/x/eta@v1.12.3/config.ts": "07f2e9f7e7aa135d7e8975b515624fb1831d3f242aa0d5b4b85032fc16dc48e5",
|
||||
"https://deno.land/x/eta@v1.12.3/containers.ts": "c584fb0daa77c11d31ccb74256adad116354411d030378a04e9745c358a3a453",
|
||||
"https://deno.land/x/eta@v1.12.3/err.ts": "7ca5fc2dc4bc222c755f155a9926e56404946fd084a1b0878b0a99d9327ea7dd",
|
||||
"https://deno.land/x/eta@v1.12.3/file-handlers.ts": "aa94b1f185fb9936960cb67faf8b819c754337cfaebc7cd1d24880f8f5386db2",
|
||||
"https://deno.land/x/eta@v1.12.3/file-helpers.ts": "4f031d275be10888ce0b7f99e3509e8cbef24bb4d5f1ebb1760659e41bb538f0",
|
||||
"https://deno.land/x/eta@v1.12.3/file-methods.ts": "c93afbbfa82c318db65c4d6b4e7f617efc6f04d7c2603cfd07ee2768b80ae1f5",
|
||||
"https://deno.land/x/eta@v1.12.3/file-utils.ts": "2a8dd25cc89d57b16df5142bf19350f056d2786ea664814c476e0c36e0f08171",
|
||||
"https://deno.land/x/eta@v1.12.3/mod.ts": "31219e28b55d1ff1777ef0e5513ea3588ebd5f220b512212334ec470030c2e39",
|
||||
"https://deno.land/x/eta@v1.12.3/parse.ts": "df29b6ae1fbdcba15295f8f07ed272b2c1f9927bc716f2863b18971d641f7506",
|
||||
"https://deno.land/x/eta@v1.12.3/polyfills.ts": "048f697fdf0ef002cc59cf7a69cf370e11877c3b7f9c0b68dd84ab4762e0ffdc",
|
||||
"https://deno.land/x/eta@v1.12.3/render.ts": "9173e99002a4169aeae45315bdd07cf4664c8dd9e39ce86d5c7daa989982f90c",
|
||||
"https://deno.land/x/eta@v1.12.3/storage.ts": "46f762d1c04d9095ed6fb694c0d993e9ae507a69bab469a5a3bd23a5a9a79983",
|
||||
"https://deno.land/x/eta@v1.12.3/utils.ts": "77ba806398590f4aff0ca1ea9485e769ba578eeb8776b4f2386067c9735b96c1"
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
import { runCommand } from "./utils.ts";
|
||||
|
||||
/**
|
||||
* Attempt to find the repository remote url.
|
||||
* Silently fails.
|
||||
*
|
||||
* ```ts
|
||||
* import { getRepository } from "./git.ts"
|
||||
* const url = await getRepository('/path/to/git/repo', (errorMsg: string, error?: Error) => {})
|
||||
* ```
|
||||
*
|
||||
* @param {string} directory The path of the git directory.
|
||||
* @param {function(string, Error)} error Handler for errors.
|
||||
*/
|
||||
export const getRepository = (
|
||||
directory: string,
|
||||
error: (message: string, error?: Error) => void,
|
||||
) => {
|
||||
return runCommand(
|
||||
[
|
||||
"git",
|
||||
"-C",
|
||||
directory,
|
||||
"config",
|
||||
"--get",
|
||||
"remote.origin.url",
|
||||
],
|
||||
error,
|
||||
true,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Attempt to find the current repos git tag.
|
||||
* Silently fails.
|
||||
*
|
||||
* ```ts
|
||||
* import { getTag } from "./git.ts"
|
||||
* const tag = await getTag('/path/to/git/repo', (errorMsg: string, error?: Error) => {})
|
||||
* ```
|
||||
*
|
||||
* @param {string} directory The path of the git directory.
|
||||
* @param {function(string, Error)} error Handler for errors.
|
||||
*/
|
||||
export const getTag = (
|
||||
directory: string,
|
||||
error: (message: string, error?: Error) => void,
|
||||
) => {
|
||||
return runCommand(
|
||||
[
|
||||
"git",
|
||||
"-C",
|
||||
directory,
|
||||
"describe",
|
||||
"--tags",
|
||||
"--abbrev=0",
|
||||
],
|
||||
error,
|
||||
true,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Attempt to find the current git branch.
|
||||
* Silently fails.
|
||||
*
|
||||
* ```ts
|
||||
* import { getBranch } from "./git.ts"
|
||||
* const branch = await getBranch('/path/to/git/repo', (errorMsg: string, error?: Error) => {})
|
||||
* ```
|
||||
*
|
||||
* @param {string} directory The path of the git directory.
|
||||
* @param {function(string, Error)} error Handler for errors.
|
||||
*/
|
||||
export const getBranch = (
|
||||
directory: string,
|
||||
error: (message: string, error?: Error) => void,
|
||||
) => {
|
||||
return runCommand(
|
||||
[
|
||||
"git",
|
||||
"-C",
|
||||
directory,
|
||||
"rev-parse",
|
||||
"--abbrev-ref",
|
||||
"HEAD",
|
||||
],
|
||||
error,
|
||||
true,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Attempt to find the current git commit sha.
|
||||
* Silently fails.
|
||||
*
|
||||
* ```ts
|
||||
* import { getCommit } from "./git.ts"
|
||||
* const commit = await getCommit('/path/to/git/repo', (errorMsg: string, error?: Error) => {})
|
||||
* ```
|
||||
*
|
||||
* @param {string} directory The path of the git directory.
|
||||
* @param {function(string, Error)} error Handler for errors.
|
||||
*/
|
||||
export const getCommit = (
|
||||
directory: string,
|
||||
error: (message: string, error?: Error) => void,
|
||||
) => {
|
||||
return runCommand(
|
||||
[
|
||||
"git",
|
||||
"-C",
|
||||
directory,
|
||||
"rev-parse",
|
||||
"HEAD",
|
||||
],
|
||||
error,
|
||||
true,
|
||||
);
|
||||
};
|
@ -0,0 +1,36 @@
|
||||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
} from "https://deno.land/std@0.146.0/testing/asserts.ts";
|
||||
import { info } from "https://deno.land/std@0.146.0/log/mod.ts";
|
||||
|
||||
import { getBranch, getCommit, getRepository, getTag } from "./git.ts";
|
||||
|
||||
const testErrorHandler = (message: string, error?: Error) => {
|
||||
info(message);
|
||||
info(error);
|
||||
};
|
||||
|
||||
Deno.test("git", async (t) => {
|
||||
const testingPath = Deno.cwd();
|
||||
|
||||
await t.step("gets the repository url", async () => {
|
||||
const url = await getRepository(testingPath, testErrorHandler);
|
||||
assertEquals(url, "git@code.eutychia.org:kay/readme-manager.git");
|
||||
});
|
||||
|
||||
await t.step("gets the repository branch", async () => {
|
||||
const branch = await getBranch(testingPath, testErrorHandler);
|
||||
assertEquals(branch, "main");
|
||||
});
|
||||
|
||||
await t.step("gets the repository commit", async () => {
|
||||
const commit = await getCommit(testingPath, testErrorHandler);
|
||||
assert(commit);
|
||||
});
|
||||
|
||||
await t.step("gets the repository tag", async () => {
|
||||
const tag = await getTag(testingPath, testErrorHandler);
|
||||
assert(tag);
|
||||
});
|
||||
});
|
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Prints the available commands.
|
||||
*/
|
||||
export const help = [
|
||||
"readme-manager \t\t\t\t\t\t\t\t Run the manager in current directory.",
|
||||
"readme-manager [project_path] \t\t\t\t\t\t Run the manager in directory.",
|
||||
"readme-manager [project_path] --templates [path] \t\t\t Template path override.",
|
||||
"readme-manager [project_path] --match [name] \t\t\t\t Match name override.",
|
||||
"readme-manager [project_path] --templates [path] --match [name] \t Templates path and match name override.",
|
||||
"readme-manager --bootstrap \t\t\t\t\t\t Create templates.",
|
||||
"readme-manager --setup \t\t\t\t\t\t\t Create configuration.",
|
||||
"readme-manager --help \t\t\t\t\t\t\t Shows this help page.",
|
||||
"readme-manager [...] --debug \t\t\t\t\t\t Enables debugging mode on any command.",
|
||||
];
|
@ -0,0 +1 @@
|
||||
{}
|
@ -0,0 +1,88 @@
|
||||
import {
|
||||
getLogger,
|
||||
handlers,
|
||||
setup,
|
||||
} from "https://deno.land/std@0.146.0/log/mod.ts";
|
||||
|
||||
/**
|
||||
* Setup different loggers used by the application.
|
||||
* The default one hides debugs and detailed error messages.
|
||||
* The debug one shows everything.
|
||||
* The file error one is used in default mode to write error details to file but hide them in console.
|
||||
*
|
||||
* ```ts
|
||||
* import { getLogger } from "https://deno.land/std@0.146.0/log/mod.ts"
|
||||
* import { setupLogs } from "./logs.ts"
|
||||
* await setupLogs('/path/to/logfile.log')
|
||||
* const default = getLogger()
|
||||
* const debug = getLogger('debug')
|
||||
* const fileError = getLogger('fileError')
|
||||
* ```
|
||||
*
|
||||
* @param {string} appLogFile The path the app should log to.
|
||||
*/
|
||||
export const setupLogs = async (appLogFile: string) => {
|
||||
await setup({
|
||||
handlers: {
|
||||
console: new handlers.ConsoleHandler("DEBUG"),
|
||||
file: new handlers.FileHandler("DEBUG", {
|
||||
filename: appLogFile,
|
||||
formatter: `${new Date().toISOString()} {levelName} {msg}`,
|
||||
}),
|
||||
errors: new handlers.FileHandler("ERROR", {
|
||||
filename: appLogFile,
|
||||
formatter: `${new Date().toISOString()} {levelName} {msg}`,
|
||||
}),
|
||||
},
|
||||
loggers: {
|
||||
default: {
|
||||
level: "WARNING",
|
||||
handlers: ["console", "errors"],
|
||||
},
|
||||
debug: {
|
||||
level: "DEBUG",
|
||||
handlers: ["console", "file"],
|
||||
},
|
||||
fileError: {
|
||||
level: "ERROR",
|
||||
handlers: ["errors"],
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Error handler.
|
||||
* Used log information to console and write to file then exit app.
|
||||
*
|
||||
* ```ts
|
||||
* import { error } from "./log.ts"
|
||||
* const errorHandler = error("/path/to/logfile.log", true)
|
||||
* errorHandler('Something went wrong.', new Error('The error'))
|
||||
* ```
|
||||
*
|
||||
* @param {string} appLogFile The path the app should log to.
|
||||
* @param {boolean} cliMode Determines whever the errorHandler should exit or throw.
|
||||
* @param {boolean} debug Show more information be shown to console if true.
|
||||
*/
|
||||
export const error = (appLogFile: string, cliMode?: boolean, debug?: boolean) =>
|
||||
(
|
||||
message: string,
|
||||
error?: Error,
|
||||
) => {
|
||||
const defaultLogger = getLogger();
|
||||
const debugLogger = getLogger("debug");
|
||||
const fileErrorLogger = getLogger("fileError");
|
||||
defaultLogger.error(`${message} Please file an issue.`);
|
||||
if (error) {
|
||||
if (debug) {
|
||||
debugLogger.error("There was an attached error.");
|
||||
debugLogger.error(error);
|
||||
} else {
|
||||
fileErrorLogger.error(error);
|
||||
}
|
||||
defaultLogger.error(`Details logged to ${appLogFile}.`);
|
||||
}
|
||||
cliMode && Deno.exit(1);
|
||||
throw error ? error : new Error(message);
|
||||
};
|
@ -0,0 +1,23 @@
|
||||
import { assertThrows } from "https://deno.land/std@0.146.0/testing/asserts.ts";
|
||||
|
||||
import { error } from "./log.ts";
|
||||
|
||||
Deno.test("log", async (t) => {
|
||||
const testingPath = await Deno.makeTempFile();
|
||||
|
||||
await t.step("error handler", () => {
|
||||
const errorHandler = error(testingPath);
|
||||
assertThrows(() => {
|
||||
errorHandler("Testing.");
|
||||
});
|
||||
});
|
||||
|
||||
await t.step("error handler debug mode", () => {
|
||||
const errorHandler = error(testingPath, false, true);
|
||||
assertThrows(() => {
|
||||
errorHandler("Testing.");
|
||||
});
|
||||
});
|
||||
|
||||
await Deno.remove(testingPath);
|
||||
});
|
@ -0,0 +1,174 @@
|
||||
import { getLogger } from "https://deno.land/std@0.146.0/log/mod.ts";
|
||||
import { Args } from "https://deno.land/std@0.146.0/flags/mod.ts";
|
||||
import { join, resolve } from "https://deno.land/std@0.146.0/path/mod.ts";
|
||||
|
||||
import {
|
||||
checkExists,
|
||||
getAppConfigDirectory,
|
||||
getAppConfigFile,
|
||||
getAppLogFile,
|
||||
} from "./utils.ts";
|
||||
import { setup } from "./setup.ts";
|
||||
import { error, setupLogs } from "./log.ts";
|
||||
import { bootstrap } from "./bootstrap.ts";
|
||||
import { render } from "./render.ts";
|
||||
|
||||
const appName = "readme-manager";
|
||||
|
||||
/**
|
||||
* The main readme-manager module.
|
||||
*
|
||||
* @param {Args} args The parsed Deno.args.
|
||||
* @param {boolean} cliMode
|
||||
*/
|
||||
export const manager = async (args: Args, cliMode?: boolean) => {
|
||||
const appLogFile = getAppLogFile(appName);
|
||||
await setupLogs(appLogFile);
|
||||
const logger = getLogger(args.debug && "debug");
|
||||
if (args.debug) {
|
||||
logger.debug(`Logs will be appended to ${appLogFile}`);
|
||||
}
|
||||
const errorHandler = error(appLogFile, cliMode, args.debug);
|
||||
|
||||
const appConfigFile = getAppConfigFile(appName, errorHandler);
|
||||
logger.info(`App config file will be ${appConfigFile}`);
|
||||
const appConfigDirectory = getAppConfigDirectory(appName, errorHandler);
|
||||
logger.info(`App config file will be ${appConfigDirectory}`);
|
||||
|
||||
if (args.setup) {
|
||||
return setup(
|
||||
appName,
|
||||
appConfigFile,
|
||||
logger,
|
||||
errorHandler,
|
||||
appConfigDirectory,
|
||||
cliMode,
|
||||
);
|
||||
}
|
||||
|
||||
if (args.bootstrap) {
|
||||
return bootstrap(appConfigDirectory, errorHandler);
|
||||
}
|
||||
|
||||
let templates = args?.templates;
|
||||
let match = args?.match;
|
||||
|
||||
if (!args.match || !args.templates) {
|
||||
logger.debug("Checking configuration file.");
|
||||
let appConfigFileContent;
|
||||
if (!(await checkExists(appConfigFile, errorHandler))) {
|
||||
appConfigFileContent = await setup(
|
||||
appName,
|
||||
appConfigFile,
|
||||
logger,
|
||||
errorHandler,
|
||||
appConfigDirectory,
|
||||
cliMode,
|
||||
);
|
||||
}
|
||||
|
||||
if (!appConfigFileContent) {
|
||||
try {
|
||||
appConfigFileContent = await Deno.readTextFile(appConfigFile);
|
||||
} catch (e) {
|
||||
errorHandler(`Something went wrong reading ${appConfigFile}.`, e);
|
||||
}
|
||||
|
||||
if (!appConfigFileContent) {
|
||||
appConfigFileContent = await setup(
|
||||
appName,
|
||||
appConfigFile,
|
||||
logger,
|
||||
errorHandler,
|
||||
appConfigDirectory,
|
||||
cliMode,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
appConfigFileContent = JSON.parse(appConfigFileContent);
|
||||
} catch (e) {
|
||||
errorHandler(
|
||||
`Something went wrong parsing the json in ${appConfigFile}.`,
|
||||
e,
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!appConfigFileContent ||
|
||||
typeof appConfigFileContent !== "object" ||
|
||||
Object.keys(appConfigFileContent).length === 0
|
||||
) {
|
||||
appConfigFileContent = JSON.parse(
|
||||
await setup(
|
||||
appName,
|
||||
appConfigFile,
|
||||
logger,
|
||||
errorHandler,
|
||||
appConfigDirectory,
|
||||
cliMode,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
match = appConfigFileContent.match;
|
||||
if (args.match) match = args.match;
|
||||
|
||||
templates = appConfigFileContent.templates;
|
||||
if (args.templates) templates = appConfigFileContent.templates;
|
||||
}
|
||||
}
|
||||
|
||||
let targetPath = args?._?.[0];
|
||||
if (args._.length === 0) targetPath = Deno.cwd();
|
||||
targetPath = `${targetPath}`; // cast to string
|
||||
try {
|
||||
for await (const file of Deno.readDir(targetPath)) {
|
||||
logger.debug(`Checking ${file.name} in ${targetPath}`);
|
||||
if (file.isFile && file.name === match) {
|
||||
console.log(`Matched ${file.name}.`);
|
||||
try {
|
||||
const readme = await render(
|
||||
resolve(join(targetPath, file.name)),
|
||||
resolve(targetPath),
|
||||
await Deno.readTextFile(resolve(join(targetPath, file.name))),
|
||||
templates,
|
||||
errorHandler,
|
||||
);
|
||||
if (readme) {
|
||||
await Deno.writeTextFile(
|
||||
resolve(join(targetPath, "README.md")),
|
||||
readme,
|
||||
);
|
||||
} else {
|
||||
errorHandler(
|
||||
`Something went wrong, ${
|
||||
resolve(join(targetPath, file.name))
|
||||
} generated an empty render output.`,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
errorHandler(
|
||||
`Something went wrong rendering ${
|
||||
resolve(
|
||||
join(targetPath, "README.md"),
|
||||
)
|
||||
}`,
|
||||
e,
|
||||
);
|
||||
}
|
||||
console.log(`Generated ${join(targetPath, "README.md")}.`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof Deno.errors.PermissionDenied) {
|
||||
logger.error("PermissionDenied on a directory.");
|
||||
logger.error(e.message);
|
||||
} else {
|
||||
errorHandler(
|
||||
"Something went wrong reading the direcotries of the target path.",
|
||||
e,
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|