create-expo-cljs-app
Version:
Create a react native application with Expo and Shadow-CLJS!
120 lines (97 loc) • 2.91 kB
JavaScript
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
;
const _require = require('./Utils'),
getModules = _require.getModules;
const ModuleClassDeclarationTemplate = ({hasteModuleName}) => {
return `/**
* JNI C++ class for module '${hasteModuleName}'
*/
class JSI_EXPORT ${hasteModuleName}SpecJSI : public JavaTurboModule {
public:
${hasteModuleName}SpecJSI(const JavaTurboModule::InitParams ¶ms);
};
`;
};
const HeaderFileTemplate = ({modules, libraryName}) => {
return `
/**
* ${'C'}opyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* ${'@'}generated by codegen project: GenerateModuleJniH.js
*/
#pragma once
#include <ReactCommon/JavaTurboModule.h>
#include <ReactCommon/TurboModule.h>
#include <jsi/jsi.h>
namespace facebook {
namespace react {
${modules}
std::shared_ptr<TurboModule> ${libraryName}_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams ¶ms);
} // namespace react
} // namespace facebook
`;
};
const AndroidMkTemplate = ({libraryName}) => {
return `# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ${libraryName}
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SHARED_LIBRARIES := libreact_nativemodule_core
LOCAL_STATIC_LIBRARIES := libjsi
LOCAL_CFLAGS := \\
-DLOG_TAG=\\"ReactNative\\"
LOCAL_CFLAGS += -fexceptions -frtti -std=c++14 -Wall
include $(BUILD_SHARED_LIBRARY)
`;
};
module.exports = {
generate(libraryName, schema, moduleSpecName, packageName) {
const nativeModules = getModules(schema);
const modules = Object.keys(nativeModules)
.filter(hasteModuleName => {
const module = nativeModules[hasteModuleName];
return !(
module.excludedPlatforms != null &&
module.excludedPlatforms.includes('android')
);
})
.sort()
.map(hasteModuleName =>
ModuleClassDeclarationTemplate({
hasteModuleName,
}),
)
.join('\n');
const fileName = `${moduleSpecName}.h`;
const replacedTemplate = HeaderFileTemplate({
modules: modules,
libraryName: libraryName.replace(/-/g, '_'),
});
return new Map([
[`jni/${fileName}`, replacedTemplate],
[
'jni/Android.mk',
AndroidMkTemplate({
libraryName: `react_codegen_${libraryName.toLowerCase()}`,
}),
],
]);
},
};