From 15f8c78164f73f51c33a73e8e31b4986753da092 Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Sun, 13 Jan 2019 19:32:25 +0100 Subject: [PATCH] Add build scripts. Add CircleCI config. Add project maven settings file. Add changelog. Update README. --- .circleci/config.yml | 57 +++++++++++ .mvn/settings.xml | 12 +++ CHANGELOG.md | 14 +++ CHANGELOG_LATEST.md | 14 +++ CODEOWNERS | 1 + README.md | 173 +++++++++++++++++++++++++++++++- scripts/prepare-release.sh | 64 ++++++++++++ scripts/start-next-iteration.sh | 54 ++++++++++ 8 files changed, 388 insertions(+), 1 deletion(-) create mode 100644 .circleci/config.yml create mode 100644 .mvn/settings.xml create mode 100644 CHANGELOG.md create mode 100644 CHANGELOG_LATEST.md create mode 100644 CODEOWNERS create mode 100755 scripts/prepare-release.sh create mode 100755 scripts/start-next-iteration.sh diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..41d1b63 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,57 @@ +version: 2 +jobs: + build: + # directory where steps will run + working_directory: ~/typescript-mapper + docker: + - image: daniloarcidiacono/ci-java-node:0.4.0 + + steps: + # check out source code to working directory + - checkout + + # restore the saved cache after the first run or if `pom.xml` has changed + - restore_cache: + key: typescript-mapper-{{ checksum "pom.xml" }} + + # gets the project dependencies + - run: mvn dependency:go-offline + + # saves the project dependencies + - save_cache: + paths: + - ~/.m2 + key: typescript-mapper-{{ checksum "pom.xml" }} + + # Build + - run: mvn clean package verify -Pdocs + + # Deploy + - deploy: + name: "Create GitHub release" + command: | + hub release create -a target/typescript-mapper-$CIRCLE_TAG-javadoc.jar -F CHANGELOG_LATEST.md $CIRCLE_TAG + + # Upload test coverage + - run: bash <(curl -s https://codecov.io/bash) + + # uploads the test metadata from the `target/surefire-reports` directory so that it can show up in the CircleCI dashboard. + - store_test_results: + path: target/surefire-reports + + # store the jar as an artifact + - store_artifacts: + path: target/typescript-mapper-{{ .Environment.CIRCLE_TAG }}.jar + +workflows: + version: 2 + build_and_deploy: + jobs: + - build: + filters: + tags: + only: /.*/ + branches: + ignore: /.*/ + + diff --git a/.mvn/settings.xml b/.mvn/settings.xml new file mode 100644 index 0000000..6881249 --- /dev/null +++ b/.mvn/settings.xml @@ -0,0 +1,12 @@ + + + + ossrh + ${ossrh.username} + ${ossrh.password} + + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..55bfc1e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# typescript-mapper 0.1.0 (2019-01-13) + +### Features + +* Recursive mapping of classes and enumerations; +* Support for Java generics, including wildcard types; +* Support for standard collection types (sets, maps, ...); +* Java annotations `@TypescriptDTO`, `@TypescriptComments` and `@TypescriptField` for specific customizations; +* Multi-file output with fully customizable logic (default: one file per package); +* Import generation; +* Empty DTOs/sources elimination; +* Support for Jackson annotations `@JsonTypeInfo` and `@JsonSubTypes`; +* Fluent API for configuration; +* Maven plugin; diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md new file mode 100644 index 0000000..0474054 --- /dev/null +++ b/CHANGELOG_LATEST.md @@ -0,0 +1,14 @@ +typescript-mapper 0.1.0 + +### Features + +* Recursive mapping of classes and enumerations; +* Support for Java generics, including wildcard types; +* Support for standard collection types (sets, maps, ...); +* Java annotations `@TypescriptDTO`, `@TypescriptComments` and `@TypescriptField` for specific customizations; +* Multi-file output with fully customizable logic (default: one file per package); +* Import generation; +* Empty DTOs/sources elimination; +* Support for Jackson annotations `@JsonTypeInfo` and `@JsonSubTypes`; +* Fluent API for configuration; +* Maven plugin; diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..4152899 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @daniloarcidiacono diff --git a/README.md b/README.md index e1a22e5..7229bc0 100644 --- a/README.md +++ b/README.md @@ -1 +1,172 @@ -# Typescript Template \ No newline at end of file +[![Maven Central](https://img.shields.io/maven-central/v/io.github.daniloarcidiacono/typescript-mapper.svg?label=Maven%20Central)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.github.daniloarcidiacono%22%20a%3A%22typescript-mapper%22) +[![codecov](https://codecov.io/gh/daniloarcidiacono/typescript-mapper/branch/master/graph/badge.svg)](https://codecov.io/gh/daniloarcidiacono/typescript-mapper) +[![CircleCI](https://circleci.com/gh/daniloarcidiacono/typescript-mapper/tree/master.svg?style=svg)](https://circleci.com/gh/daniloarcidiacono/typescript-mapper/tree/master) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) + +# What? +Typescript mapper is a tool for generating TypeScript .d.ts files from Java source code. + +See the CHANGELOG for a more complete list of available features. + +# How? +Include the plugin in your Maven project: + +src/pom.xml +```xml + + + 4.0.0 + + com.example + myapp + 0.0.1-SNAPSHOT + + + LATEST + + + + + + io.github.daniloarcidiacono.typescriptmapper + typescript-mapper-core + ${typescript-mapper.version} + compile + + + + + + + io.github.daniloarcidiacono.typescriptmapper + typescript-mapper-maven-plugin + ${typescript-mapper.version} + + com.example.myapp + + + + + map + + + + + + + +``` + +Consider the following classes: + +src/main/java/com/example/myapp/domain/Person.java +```java +package com.example.myapp.domain; + +import com.example.myapp.info.Tag; +import io.github.daniloarcidiacono.typescriptmapper.core.annotation.TypescriptComments; +import io.github.daniloarcidiacono.typescriptmapper.core.annotation.TypescriptDTO; +import java.util.List; +import java.util.Map; + +@TypescriptDTO +public class Person { + @TypescriptComments("The name of the domain.") + private String name; + private int age; + private boolean hasChildren; + private List tags; + + @TypescriptComments({ + "The emails of the domain.", + "Key is provider, value is email." + }) + private Map emails; + + // ... rest of the code ... +} +``` + +src/main/java/com/example/myapp/info/Tag.java +```java +package com.example.myapp.info; + +import io.github.daniloarcidiacono.typescriptmapper.core.annotation.TypescriptComments; +import io.github.daniloarcidiacono.typescriptmapper.core.annotation.TypescriptDTO; +import io.github.daniloarcidiacono.typescriptmapper.core.annotation.TypescriptField; + +@TypescriptDTO +@TypescriptComments("Colored tag.") +public class Tag { + private String name; + + @TypescriptComments("Optional tag color") + @TypescriptField(required = false) + private Color color; + + // ... rest of the code ... +} + +@TypescriptDTO +@TypescriptComments("Tag colors") +enum Color { + RED, + GREEN +} +``` + +Running `mvn compile` produces the following output: + + +target/mapped/com/example/myapp/domain.ts +```typescript +/** + * This file is automatically generated by TypescriptMapper. + * Do not modify this file -- YOUR CHANGES WILL BE ERASED! + */ +import { Tag } from './info'; +export interface Person { + // The name of the domain. + name: string; + age: number; + hasChildren: boolean; + tags: Tag[]; + + /** + * The emails of the domain. + * Key is provider, value is email. + */ + emails: { [ index: string ]: string }; +} +``` + +target/mapped/com/example/myapp/info.ts +```typescript +/** + * This file is automatically generated by TypescriptMapper. + * Do not modify this file -- YOUR CHANGES WILL BE ERASED! + */ +// Colored tag. +export interface Tag { + name: string; + + // Optional tag color + color?: Color; +} + +// Tag colors +export enum Color { + RED = 'RED', + GREEN = 'GREEN' +} +``` + +The folder structure can be customized with any logic (the imports will be adjusted accordingly). + +# Why? +Type-safe DTOs exchanged by back-end and front-end components. + +# Where? +The latest version is available on [Maven Central](https://search.maven.org/artifact/io.github.daniloarcidiacono/typescript-mapper). diff --git a/scripts/prepare-release.sh b/scripts/prepare-release.sh new file mode 100755 index 0000000..f99a08e --- /dev/null +++ b/scripts/prepare-release.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# Check that we are in the root folder +if ! [[ -f "./scripts/prepare-release.sh" ]]; then + (>&2 echo "Script must be run from the root folder, actual $(pwd)") + exit 1 +fi + +# Get the current branch +branch_name=$(git symbolic-ref -q HEAD) +branch_name=${branch_name##refs/heads/} +branch_name=${branch_name:-HEAD} + +# Check that we are in master +if [[ ${branch_name} != 'master' ]]; then + (>&2 echo "Releases can be prepared only on master branch, current one is ${branch_name}!") + exit 1 +fi + +# Check the arguments +if [[ "$#" -ne 1 ]]; then + (>&2 echo "Invalid number of arguments, found $#, expected 1") + echo "prepare-release " + exit 1 +fi + +# Fetch (for picking tags) +git fetch +existing_tag=$(git tag --list | grep $1 | wc -l) +if [[ ${existing_tag} -gt 0 ]]; then + (>&2 echo "Tag $1 already exists, stop.") + exit 1 +fi + +# Merge +echo "Merging from dev" +git merge origin/dev --no-ff --no-commit + +# Check if there are any conflicts +conflicts=$(git ls-files -u | wc -l) +if [[ ${conflicts} -gt 0 ]]; then + (>&2 echo "There are merge conflicts, stop (use git merge --abort to undo changes).") + exit 1 +fi + +# Update the version +echo "Setting project version to $1" +mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$1 + +# Compile with tests +mvn clean verify + +if [[ $? -ne 0 ]]; then + (>&2 echo "Project build failed, stop (use git merge --abort to undo changes).") + exit 1 +fi + +# Success: commit and tag +echo "Build success, creating tagged commit" +git commit -am "chore: version $1" +git tag -a $1 -m "$1" + +# Ready to push! +# git push origin master --tags \ No newline at end of file diff --git a/scripts/start-next-iteration.sh b/scripts/start-next-iteration.sh new file mode 100755 index 0000000..b4c1f23 --- /dev/null +++ b/scripts/start-next-iteration.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +# Check that we are in the root folder +if ! [[ -f "./scripts/start-next-iteration.sh" ]]; then + (>&2 echo "Script must be run from the root folder, actual $(pwd)") + exit 1 +fi + +# Get the current branch +branch_name=$(git symbolic-ref -q HEAD) +branch_name=${branch_name##refs/heads/} +branch_name=${branch_name:-HEAD} + +# Check that we are in dev +if [[ ${branch_name} != 'dev' ]]; then + (>&2 echo "Next iterations can be started only on dev branch, current one is ${branch_name}!") + exit 1 +fi + +# Check the arguments +if [[ "$#" -ne 1 ]]; then + (>&2 echo "Invalid number of arguments, found $#, expected 1") + echo "start-next-iteration " + exit 1 +fi + +# Check that the working tree is clean +if [[ -n $(git status -s) ]]; then + (>&2 echo "Working tree is not clean, stop") + exit 1 +fi + +# Update +git fetch + +# Try to fast forward the dev branch +git merge origin/dev --ff-only + +# Check for no conflicts +if [[ $? -ne 0 ]]; then + (>&2 echo "There are remote changes in dev branch that could not be merged automatically, stop.") + exit 1 +fi + +# Change the version +echo "Setting project version to $1" +mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$1 + +# Success: commit +echo "Success, creating commit" +git commit -am "chore: start next development iteration ($1)" + +# Ready to push! +#git push origin dev \ No newline at end of file