Skip to content

Commit

Permalink
Multiplatform: Generate EmojiProviders into jvmMain. (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech authored May 26, 2022
1 parent d734642 commit 42f7829
Show file tree
Hide file tree
Showing 17 changed files with 301 additions and 5 deletions.
7 changes: 7 additions & 0 deletions emoji-facebook/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ package com.vanniktech.emoji.facebook {
property public com.vanniktech.emoji.EmojiCategory![] categories;
}

public final class FacebookEmojiProvider implements com.vanniktech.emoji.EmojiProvider {
ctor public FacebookEmojiProvider();
method public com.vanniktech.emoji.EmojiCategory![] getCategories();
method public void release();
property public com.vanniktech.emoji.EmojiCategory![] categories;
}

}

2 changes: 1 addition & 1 deletion emoji-facebook/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

metalava {
filename = "api/current.txt"
sourcePaths = ["src/commonMain", "src/androidMain"]
sourcePaths = ["src/commonMain", "src/androidMain", "src/jvmMain"]
}

// CocoaPods requires a version.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vanniktech.emoji.facebook

import com.vanniktech.emoji.EmojiCategory
import com.vanniktech.emoji.EmojiProvider
import com.vanniktech.emoji.facebook.category.ActivitiesCategory
import com.vanniktech.emoji.facebook.category.AnimalsAndNatureCategory
import com.vanniktech.emoji.facebook.category.FlagsCategory
import com.vanniktech.emoji.facebook.category.FoodAndDrinkCategory
import com.vanniktech.emoji.facebook.category.ObjectsCategory
import com.vanniktech.emoji.facebook.category.SmileysAndPeopleCategory
import com.vanniktech.emoji.facebook.category.SymbolsCategory
import com.vanniktech.emoji.facebook.category.TravelAndPlacesCategory

class FacebookEmojiProvider : EmojiProvider {
override val categories: Array<EmojiCategory>
get() = arrayOf(
SmileysAndPeopleCategory(),
AnimalsAndNatureCategory(),
FoodAndDrinkCategory(),
ActivitiesCategory(),
TravelAndPlacesCategory(),
ObjectsCategory(),
SymbolsCategory(),
FlagsCategory(),
)

override fun release() = Unit
}
7 changes: 7 additions & 0 deletions emoji-google-compat/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ package com.vanniktech.emoji.googlecompat {
property public com.vanniktech.emoji.EmojiCategory![] categories;
}

public final class GoogleCompatEmojiProvider implements com.vanniktech.emoji.EmojiProvider {
ctor public GoogleCompatEmojiProvider();
method public com.vanniktech.emoji.EmojiCategory![] getCategories();
method public void release();
property public com.vanniktech.emoji.EmojiCategory![] categories;
}

}

2 changes: 1 addition & 1 deletion emoji-google-compat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

metalava {
filename = "api/current.txt"
sourcePaths = ["src/commonMain", "src/androidMain"]
sourcePaths = ["src/commonMain", "src/androidMain", "src/jvmMain"]
}

// CocoaPods requires a version.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vanniktech.emoji.googlecompat

import com.vanniktech.emoji.EmojiCategory
import com.vanniktech.emoji.EmojiProvider
import com.vanniktech.emoji.googlecompat.category.ActivitiesCategory
import com.vanniktech.emoji.googlecompat.category.AnimalsAndNatureCategory
import com.vanniktech.emoji.googlecompat.category.FlagsCategory
import com.vanniktech.emoji.googlecompat.category.FoodAndDrinkCategory
import com.vanniktech.emoji.googlecompat.category.ObjectsCategory
import com.vanniktech.emoji.googlecompat.category.SmileysAndPeopleCategory
import com.vanniktech.emoji.googlecompat.category.SymbolsCategory
import com.vanniktech.emoji.googlecompat.category.TravelAndPlacesCategory

class GoogleCompatEmojiProvider : EmojiProvider {
override val categories: Array<EmojiCategory>
get() = arrayOf(
SmileysAndPeopleCategory(),
AnimalsAndNatureCategory(),
FoodAndDrinkCategory(),
ActivitiesCategory(),
TravelAndPlacesCategory(),
ObjectsCategory(),
SymbolsCategory(),
FlagsCategory(),
)

override fun release() = Unit
}
7 changes: 7 additions & 0 deletions emoji-google/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ package com.vanniktech.emoji.google {
property public com.vanniktech.emoji.EmojiCategory![] categories;
}

public final class GoogleEmojiProvider implements com.vanniktech.emoji.EmojiProvider {
ctor public GoogleEmojiProvider();
method public com.vanniktech.emoji.EmojiCategory![] getCategories();
method public void release();
property public com.vanniktech.emoji.EmojiCategory![] categories;
}

}

2 changes: 1 addition & 1 deletion emoji-google/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

metalava {
filename = "api/current.txt"
sourcePaths = ["src/commonMain", "src/androidMain"]
sourcePaths = ["src/commonMain", "src/androidMain", "src/jvmMain"]
}

// CocoaPods requires a version.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vanniktech.emoji.google

import com.vanniktech.emoji.EmojiCategory
import com.vanniktech.emoji.EmojiProvider
import com.vanniktech.emoji.google.category.ActivitiesCategory
import com.vanniktech.emoji.google.category.AnimalsAndNatureCategory
import com.vanniktech.emoji.google.category.FlagsCategory
import com.vanniktech.emoji.google.category.FoodAndDrinkCategory
import com.vanniktech.emoji.google.category.ObjectsCategory
import com.vanniktech.emoji.google.category.SmileysAndPeopleCategory
import com.vanniktech.emoji.google.category.SymbolsCategory
import com.vanniktech.emoji.google.category.TravelAndPlacesCategory

class GoogleEmojiProvider : EmojiProvider {
override val categories: Array<EmojiCategory>
get() = arrayOf(
SmileysAndPeopleCategory(),
AnimalsAndNatureCategory(),
FoodAndDrinkCategory(),
ActivitiesCategory(),
TravelAndPlacesCategory(),
ObjectsCategory(),
SymbolsCategory(),
FlagsCategory(),
)

override fun release() = Unit
}
7 changes: 7 additions & 0 deletions emoji-ios/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ package com.vanniktech.emoji.ios {
property public com.vanniktech.emoji.EmojiCategory![] categories;
}

public final class IosEmojiProvider implements com.vanniktech.emoji.EmojiProvider {
ctor public IosEmojiProvider();
method public com.vanniktech.emoji.EmojiCategory![] getCategories();
method public void release();
property public com.vanniktech.emoji.EmojiCategory![] categories;
}

}

2 changes: 1 addition & 1 deletion emoji-ios/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

metalava {
filename = "api/current.txt"
sourcePaths = ["src/commonMain", "src/androidMain"]
sourcePaths = ["src/commonMain", "src/androidMain", "src/jvmMain"]
}

// CocoaPods requires a version.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vanniktech.emoji.ios

import com.vanniktech.emoji.EmojiCategory
import com.vanniktech.emoji.EmojiProvider
import com.vanniktech.emoji.ios.category.ActivitiesCategory
import com.vanniktech.emoji.ios.category.AnimalsAndNatureCategory
import com.vanniktech.emoji.ios.category.FlagsCategory
import com.vanniktech.emoji.ios.category.FoodAndDrinkCategory
import com.vanniktech.emoji.ios.category.ObjectsCategory
import com.vanniktech.emoji.ios.category.SmileysAndPeopleCategory
import com.vanniktech.emoji.ios.category.SymbolsCategory
import com.vanniktech.emoji.ios.category.TravelAndPlacesCategory

class IosEmojiProvider : EmojiProvider {
override val categories: Array<EmojiCategory>
get() = arrayOf(
SmileysAndPeopleCategory(),
AnimalsAndNatureCategory(),
FoodAndDrinkCategory(),
ActivitiesCategory(),
TravelAndPlacesCategory(),
ObjectsCategory(),
SymbolsCategory(),
FlagsCategory(),
)

override fun release() = Unit
}
7 changes: 7 additions & 0 deletions emoji-twitter/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ package com.vanniktech.emoji.twitter {
property public com.vanniktech.emoji.EmojiCategory![] categories;
}

public final class TwitterEmojiProvider implements com.vanniktech.emoji.EmojiProvider {
ctor public TwitterEmojiProvider();
method public com.vanniktech.emoji.EmojiCategory![] getCategories();
method public void release();
property public com.vanniktech.emoji.EmojiCategory![] categories;
}

}

2 changes: 1 addition & 1 deletion emoji-twitter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

metalava {
filename = "api/current.txt"
sourcePaths = ["src/commonMain", "src/androidMain"]
sourcePaths = ["src/commonMain", "src/androidMain", "src/jvmMain"]
}

// CocoaPods requires a version.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vanniktech.emoji.twitter

import com.vanniktech.emoji.EmojiCategory
import com.vanniktech.emoji.EmojiProvider
import com.vanniktech.emoji.twitter.category.ActivitiesCategory
import com.vanniktech.emoji.twitter.category.AnimalsAndNatureCategory
import com.vanniktech.emoji.twitter.category.FlagsCategory
import com.vanniktech.emoji.twitter.category.FoodAndDrinkCategory
import com.vanniktech.emoji.twitter.category.ObjectsCategory
import com.vanniktech.emoji.twitter.category.SmileysAndPeopleCategory
import com.vanniktech.emoji.twitter.category.SymbolsCategory
import com.vanniktech.emoji.twitter.category.TravelAndPlacesCategory

class TwitterEmojiProvider : EmojiProvider {
override val categories: Array<EmojiCategory>
get() = arrayOf(
SmileysAndPeopleCategory(),
AnimalsAndNatureCategory(),
FoodAndDrinkCategory(),
ActivitiesCategory(),
TravelAndPlacesCategory(),
ObjectsCategory(),
SymbolsCategory(),
FlagsCategory(),
)

override fun release() = Unit
}
11 changes: 11 additions & 0 deletions generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ async function generateCode(map, targets) {
const categoryChunkTemplate = await fs.readFile("template/CategoryChunk.kt", "utf-8");
const emojiProviderTemplate = await fs.readFile("template/EmojiProvider.kt", "utf-8");
const emojiProviderCompatTemplate = await fs.readFile("template/EmojiProviderCompat.kt", "utf-8");
const emojiProviderJvm = await fs.readFile("template/EmojiProviderJvm.kt", "utf-8");

const entries = stable([...map.entries()], (first, second) => {
return categoryInfo.findIndex(it => it.name === first[0]) - categoryInfo.findIndex(it => it.name === second[0]);
Expand All @@ -398,6 +399,7 @@ async function generateCode(map, targets) {
for (const target of targets) {
const srcDir = `../emoji-${target.module}/src/androidMain/kotlin/com/vanniktech/emoji/${target.package}`;
const commonSrcDir = `../emoji-${target.module}/src/commonMain/kotlin/com/vanniktech/emoji/${target.package}`;
const jvmSrcDir = `../emoji-${target.module}/src/jvmMain/kotlin/com/vanniktech/emoji/${target.package}`;

if (target.module !== "google-compat") {
await fs.emptyDir(commonSrcDir);
Expand All @@ -406,6 +408,8 @@ async function generateCode(map, targets) {
await fs.emptyDir(`${commonSrcDir}/category`)
}

await fs.emptyDir(jvmSrcDir);

let strips = 0;
for (const [category, emojis] of entries) {
emojis.forEach(emoji => strips = Math.max(strips, emoji.x + 1));
Expand Down Expand Up @@ -468,6 +472,13 @@ async function generateCode(map, targets) {
}));
}

await fs.writeFile(`${jvmSrcDir}/${target.name}Provider.kt`, template(emojiProviderJvm)({
package: target.package,
imports: imports,
name: target.name,
categories: categories,
}));

if (target.module !== "google-compat") {
await fs.writeFile(`${commonSrcDir}/${target.name}.kt`, template(emojiTemplate)({
package: target.package,
Expand Down
Loading

0 comments on commit 42f7829

Please sign in to comment.