diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 65fa1d2..02a0568 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,7 @@ { "recommendations": [ - "golang.go", - "ms-vscode-remote.remote-containers" + "ms-vscode-remote.remote-containers", + "redhat.vscode-yaml", + "golang.go" ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d0a9c41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "yaml.schemas": { + "docs/monoclean-schema.json": [ + "monoclean.yml" + ] + } +} \ No newline at end of file diff --git a/README.md b/README.md index b69884a..1fb539e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # monoclean -A clean mono workspace automation +A clean repository automation for Typescript mono workspace projects. Includes yarn, jest and eslint predifined configurations. Customizations and new automations automations are planned. # install @@ -11,10 +11,6 @@ A clean mono workspace automation ## declare you workspace `monoclean.yml` ``` -engines: - node: "v14.17.3" - npm: "6.14.13" - workspace: name: "example" version: "1.0.0" @@ -37,7 +33,7 @@ It will create and maintain automatically package.json, tsconfig.json, eslint.js `monoclean run [PACKAGE]` use esbuild to fasterly run `src/index.ts` on desired `[PACKAGE]` -### `monoclean` +### `monoclean test` `monoclean test [PACKAGE]` use esbuild and jest to fasterly test all packages in the workspace diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..1e80443 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,38 @@ +## Welcome to GitHub Pages + +You can use the [editor on GitHub](https://github.com/teintinu/monoclean/edit/main/docs/index.md) to maintain and preview the content for your website in Markdown files. + +Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files. + +### Markdown + +Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for + +```markdown +Syntax highlighted code block + +# Header 1 +## Header 2 +### Header 3 + +- Bulleted +- List + +1. Numbered +2. List + +**Bold** and _Italic_ and `Code` text + +[Link](url) and ![Image](src) +``` + +For more details see [GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/). + +### Jekyll Themes + +Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/teintinu/monoclean/settings/pages). The name of this theme is saved in the Jekyll `_config.yml` configuration file. + +### Support or Contact + +Having trouble with Pages? Check out our [documentation](https://docs.github.com/categories/github-pages-basics/) or [contact support](https://support.github.com/contact) and we’ll help you sort it out. + diff --git a/docs/monoclean-schema.json b/docs/monoclean-schema.json new file mode 100644 index 0000000..f66565c --- /dev/null +++ b/docs/monoclean-schema.json @@ -0,0 +1,139 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "A clean repository automation for Typescript mono workspace projects", + "description": "A clean repository automation for Typescript mono workspace projects. Includes yarn, jest and eslint predifined configurations. Customizations and new automations automations are planned.", + "$id": "http://example.com/example.json", + "type": "object", + "required": [ + "packages", + "workspace" + ], + "properties": { + "engines": { + "$id": "#/properties/engines", + "type": "object", + "title": "Define Node engine version", + "required": [ + "node", + "npm" + ], + "properties": { + "node": { + "$id": "#/properties/engines/properties/node", + "type": "string", + "title": "Node.js version", + "examples": [ + "v14.17.3" + ] + }, + "npm": { + "$id": "#/properties/engines/properties/npm", + "type": "string", + "title": "npm version", + "examples": [ + "6.14.13" + ] + } + }, + "additionalProperties": false + }, + "workspace": { + "$id": "#/properties/workspace", + "type": "object", + "title": "Workspace definition", + "required": [ + "name", + "version" + ], + "properties": { + "name": { + "$id": "#/properties/workspace/properties/name", + "$ref": "#/definitions/name", + "title": "The name of workspace" + }, + "version": { + "$id": "#/properties/workspace/properties/version", + "$ref": "#/definitions/version", + "title": "Version used for all packages in that workspaces" + }, + "dependencies": { + "$id": "#/properties/workspace/properties/dependencies", + "$ref": "#/definitions/dependencies", + "title": "The dependencies for all workspace" + } + }, + "additionalProperties": false + }, + "packages": { + "$id": "#/properties/packages", + "$ref": "#/definitions/packageList", + "title": "The packages on this workspace" + }, + "business-rules": { + "$id": "#/properties/packages", + "$ref": "#/definitions/packageList", + "title": "These Clean Architecture packages defines business-rules" + }, + "applications": { + "$id": "#/properties/packages", + "$ref": "#/definitions/packageList", + "title": "These Clean Architecture packages defines applications" + }, + "adapters": { + "$id": "#/properties/packages", + "$ref": "#/definitions/packageList", + "title": "These Clean Architecture packages defines adapters" + } + }, + "definitions": { + "name": { + "type": "string", + "pattern": "^([a-z][a-z1-9\\-]+)|(@[a-z][a-z1-9\\-]+\\/[a-z][a-z1-9\\-]*)$" + }, + "version": { + "type": "string", + "pattern": "^([~^><=]*\\d+\\.\\d+\\.\\d+)|(\\*)$" + }, + "dependencies": { + "type": "object", + "patternProperties": { + "^([a-z][a-z1-9\\-]+)|(@[a-z][a-z1-9\\-]+\\/[a-z][a-z1-9\\-]*)$": { + "$ref": "#/definitions/version" + } + }, + "additionalProperties": false + }, + "packageList": { + "type": "object", + "patternProperties": { + "^([a-z][a-z1-9\\-]+)|(@[a-z][a-z1-9\\-]+\\/[a-z][a-z1-9\\-]*)$": { + "$ref": "#/definitions/packageDef" + } + }, + "additionalProperties": false + }, + "packageDef": { + "type": "object", + "required": [ + "folder" + ], + "properties": { + "folder": { + "type": "string", + "title": "folder of this package relative to workspace", + "pattern": "^[^\\.\\/\\\\]" + }, + "public": { + "type": "boolean", + "title": "Publish this package as public" + }, + "dependencies": { + "$ref": "#/definitions/dependencies", + "title": "The dependencies for all workspace" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false +} \ No newline at end of file diff --git a/examples/new/.gitignore b/examples/new/.gitignore index 6492dcd..fdb51e0 100644 --- a/examples/new/.gitignore +++ b/examples/new/.gitignore @@ -11,5 +11,5 @@ tmp out .eslintrc.json coverage -.vscode/extensions.json +.vscode diff --git a/examples/new/monoclean.yml b/examples/new/monoclean.yml index 475a803..023f490 100644 --- a/examples/new/monoclean.yml +++ b/examples/new/monoclean.yml @@ -1,17 +1,14 @@ + workspace: - name: "new" - version: "1.0.0" - dependencies: - "@types/node": 14.14.31 - react: 17.0.1 - "@types/react": 17.0.2 - + name: new + version: 1.0.0 + packages: "@new/a": public: true folder: "a" dependencies: - "@new/b": "*" + "@new/b": "*" "@new/b": public: true diff --git a/examples/simple-workspace/.gitignore b/examples/simple-workspace/.gitignore index 6492dcd..fdb51e0 100644 --- a/examples/simple-workspace/.gitignore +++ b/examples/simple-workspace/.gitignore @@ -11,5 +11,5 @@ tmp out .eslintrc.json coverage -.vscode/extensions.json +.vscode diff --git a/examples/simple-workspace/monoclean.yml b/examples/simple-workspace/monoclean.yml index 4f4b176..656de9d 100644 --- a/examples/simple-workspace/monoclean.yml +++ b/examples/simple-workspace/monoclean.yml @@ -36,7 +36,3 @@ packages: workspace: name: "simple-workspace" version: "1.0.0" - dependencies: - "@types/node": 14.14.31 - react: 17.0.1 - "@types/react": 17.0.2 diff --git a/internal/setup.go b/internal/setup.go index 4cd0d25..aa26a16 100644 --- a/internal/setup.go +++ b/internal/setup.go @@ -17,6 +17,9 @@ func ConfigureRepository(repo *Repository) error { if err := configureGitIgnore(repo); err != nil { return err } + if err := configureVsCodeSettings(repo); err != nil { + return err + } if err := configureVsCodeRecommendedExtensions(repo); err != nil { return err } @@ -83,7 +86,7 @@ tmp out .eslintrc.json coverage -.vscode/extensions.json +.vscode ` @@ -91,11 +94,26 @@ coverage return err } -func configureVsCodeRecommendedExtensions(repo *Repository) error { +func configureVsCodeSettings(repo *Repository) error { var vscodeDir = path.Join(repo.RootDir, ".vscode") if err := os.MkdirAll(vscodeDir, 0755); err != nil { return err } + var extensionsJson = path.Join(vscodeDir, "settings.json") + var content = `{ + "yaml.schemas": { + "https://teintinu.github.io/monoclean/monoclean-schema.json": [ + "monoclean.yml" + ] + } +} +` + err := ioutil.WriteFile(extensionsJson, []byte(content), 0644) + return err +} + +func configureVsCodeRecommendedExtensions(repo *Repository) error { + var vscodeDir = path.Join(repo.RootDir, ".vscode") var extensionsJson = path.Join(vscodeDir, "extensions.json") var content = `{ "recommendations": [ @@ -111,7 +129,9 @@ func configureNvmRc(repo *Repository) error { npmRc := path.Join(repo.RootDir, ".nvm.rc") var content = repo.Engines["node"] - + if len(content) == 0 { + return nil + } err := ioutil.WriteFile(npmRc, []byte(content), 0644) return err } diff --git a/scripts/create-version.js b/scripts/create-version.js new file mode 100644 index 0000000..6353723 --- /dev/null +++ b/scripts/create-version.js @@ -0,0 +1,17 @@ + +const fs = require("fs"); +const stdinBuffer = fs.readFileSync(0, 'utf-8'); +const versions = stdinBuffer + .split('\n') + .filter((l) => l.startsWith('v')) + .map((l) => l.substr(1).split('.').map(n=>parseInt(n,10))) + .sort((a, b) => { + for (let i = 0; i <= 2; i++) { + const d = b[ i ] - a[ i ] + if (d !== 0) return d + } + return 0 + }) +const last = versions[ 0 ] +const next = [ last[ 0 ], last[ 1 ], last[ 2 ] + 1 ] +console.log("v" + next.join('.')); \ No newline at end of file diff --git a/scripts/create-version.sh b/scripts/create-version.sh new file mode 100755 index 0000000..14e83b9 --- /dev/null +++ b/scripts/create-version.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -e + +ROOT=`realpath $(dirname $0)/..` +cd $ROOT + +next=`git tag -l | node $ROOT/scripts/create-version.js` + +echo "Publish next version: $next" +read -p "Are you sure? " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + git tag $next + git push origin $next +fi diff --git a/scripts/createtag.sh b/scripts/createtag.sh deleted file mode 100755 index 966d10b..0000000 --- a/scripts/createtag.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -set -e - -ROOT=`realpath $(dirname $0)/..` -cd $ROOT - -if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] -then - git tag v$1 - git push origin v$1 -else - echo "invalid version" - exit 1 -fi