add tsx support
This commit is contained in:
@@ -1,135 +1,140 @@
|
||||
import resolve from '@rollup/plugin-node-resolve'
|
||||
import commonjs from '@rollup/plugin-commonjs'
|
||||
import bundles from './build/index'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import buble from '@rollup/plugin-buble'
|
||||
import json from "@rollup/plugin-json"
|
||||
import image from '@rollup/plugin-image'
|
||||
import resolve from "@rollup/plugin-node-resolve";
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import bundles from "./build/index";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import buble from "@rollup/plugin-buble";
|
||||
import json from "@rollup/plugin-json";
|
||||
import image from "@rollup/plugin-image";
|
||||
|
||||
function searchImages(dir, images) {
|
||||
const files = fs.readdirSync(dir)
|
||||
files.forEach((item, index) => {
|
||||
var fullPath = path.join(dir, item)
|
||||
const stat = fs.statSync(fullPath)
|
||||
if (stat.isDirectory()) {
|
||||
searchImages(path.join(dir, item), images)
|
||||
} else {
|
||||
if (fullPath.endsWith('.png')) {
|
||||
images.push(fullPath)
|
||||
}
|
||||
}
|
||||
})
|
||||
return images
|
||||
const files = fs.readdirSync(dir);
|
||||
files.forEach((item, index) => {
|
||||
var fullPath = path.join(dir, item);
|
||||
const stat = fs.statSync(fullPath);
|
||||
if (stat.isDirectory()) {
|
||||
searchImages(path.join(dir, item), images);
|
||||
} else {
|
||||
if (fullPath.endsWith(".png")) {
|
||||
images.push(fullPath);
|
||||
}
|
||||
}
|
||||
});
|
||||
return images;
|
||||
}
|
||||
|
||||
const allImages = []
|
||||
searchImages('src', allImages)
|
||||
const allImages = [];
|
||||
searchImages("src", allImages);
|
||||
|
||||
function mkdirsSync(dirname) {
|
||||
if (fs.existsSync(dirname)) {
|
||||
return true
|
||||
} else {
|
||||
if (mkdirsSync(path.dirname(dirname))) {
|
||||
fs.mkdirSync(dirname)
|
||||
return true
|
||||
}
|
||||
if (fs.existsSync(dirname)) {
|
||||
return true;
|
||||
} else {
|
||||
if (mkdirsSync(path.dirname(dirname))) {
|
||||
fs.mkdirSync(dirname);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allImages.forEach((value) => {
|
||||
let path = __dirname + '/build/' + value
|
||||
path = path.split("\\").join("/")
|
||||
let index = path.lastIndexOf('/')
|
||||
mkdirsSync(path.substring(0, index))
|
||||
|
||||
fs.copyFile(__dirname + '/' + value, __dirname + '/build/' + value, error => {
|
||||
if (error)
|
||||
console.log(error)
|
||||
})
|
||||
})
|
||||
let path = __dirname + "/build/" + value;
|
||||
path = path.split("\\").join("/");
|
||||
let index = path.lastIndexOf("/");
|
||||
mkdirsSync(path.substring(0, index));
|
||||
|
||||
fs.copyFile(
|
||||
__dirname + "/" + value,
|
||||
__dirname + "/build/" + value,
|
||||
(error) => {
|
||||
if (error) console.log(error);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
function readDirs(dirPath, files) {
|
||||
if (fs.statSync(dirPath).isDirectory()) {
|
||||
fs.readdirSync(dirPath).forEach(e => {
|
||||
readDirs(path.join(dirPath, e), files)
|
||||
})
|
||||
} else {
|
||||
for (let bundle of bundles) {
|
||||
if (dirPath.replace("\\", "/").match(new RegExp(`^${bundle}`))) {
|
||||
files.push(dirPath)
|
||||
}
|
||||
}
|
||||
if (fs.statSync(dirPath).isDirectory()) {
|
||||
fs.readdirSync(dirPath).forEach((e) => {
|
||||
readDirs(path.join(dirPath, e), files);
|
||||
});
|
||||
} else {
|
||||
for (let bundle of bundles) {
|
||||
if (dirPath.replace("\\", "/").match(new RegExp(`^${bundle}`))) {
|
||||
files.push(dirPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const dirs = fs.readdirSync(".").filter((e) => {
|
||||
for (let bundle of bundles) {
|
||||
if (bundle.match(new RegExp(`^${e}/`))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
const dirs = fs.readdirSync('.')
|
||||
.filter(e => {
|
||||
for (let bundle of bundles) {
|
||||
if (bundle.match(new RegExp(`^${e}/`))) {
|
||||
return true
|
||||
}
|
||||
const allFiles = [];
|
||||
|
||||
dirs.forEach((e) => {
|
||||
readDirs(e, allFiles);
|
||||
});
|
||||
export default allFiles
|
||||
.map((e) => e.replace(/.tsx*/, ""))
|
||||
.map((bundle) => {
|
||||
return {
|
||||
input: `build/${bundle}.js`,
|
||||
output: {
|
||||
format: "cjs",
|
||||
file: `bundle/${bundle}.js`,
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [
|
||||
resolve({ mainFields: ["jsnext"] }),
|
||||
commonjs(),
|
||||
json(),
|
||||
image(),
|
||||
],
|
||||
external: ["reflect-metadata", "doric"],
|
||||
onwarn: function (warning) {
|
||||
if (warning.code === "THIS_IS_UNDEFINED") {
|
||||
return;
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
const allFiles = []
|
||||
|
||||
dirs.forEach(e => {
|
||||
readDirs(e, allFiles)
|
||||
})
|
||||
export default
|
||||
console.warn(warning.message);
|
||||
},
|
||||
};
|
||||
})
|
||||
.concat(
|
||||
allFiles
|
||||
.map(e => e.replace('.ts', ''))
|
||||
.map(bundle => {
|
||||
return {
|
||||
input: `build/${bundle}.js`,
|
||||
output: {
|
||||
format: "cjs",
|
||||
file: `bundle/${bundle}.js`,
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [
|
||||
resolve({ mainFields: ["jsnext"] }),
|
||||
commonjs(),
|
||||
json(),
|
||||
image(),
|
||||
],
|
||||
external: ['reflect-metadata', 'doric'],
|
||||
onwarn: function (warning) {
|
||||
if (warning.code === 'THIS_IS_UNDEFINED') { return }
|
||||
console.warn(warning.message)
|
||||
}
|
||||
.map((e) => e.replace(/.tsx*/, ""))
|
||||
.map((bundle) => {
|
||||
return {
|
||||
input: `build/${bundle}.js`,
|
||||
output: {
|
||||
format: "cjs",
|
||||
file: `bundle/${bundle}.es5.js`,
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [
|
||||
resolve({ mainFields: ["jsnext"] }),
|
||||
commonjs(),
|
||||
json(),
|
||||
buble({
|
||||
transforms: {
|
||||
dangerousForOf: true,
|
||||
generator: false,
|
||||
},
|
||||
}),
|
||||
image(),
|
||||
],
|
||||
external: ["reflect-metadata", "doric"],
|
||||
onwarn: function (warning) {
|
||||
if (warning.code === "THIS_IS_UNDEFINED") {
|
||||
return;
|
||||
}
|
||||
}).concat(
|
||||
allFiles
|
||||
.map(e => e.replace('.ts', ''))
|
||||
.map(bundle => {
|
||||
return {
|
||||
input: `build/${bundle}.js`,
|
||||
output: {
|
||||
format: "cjs",
|
||||
file: `bundle/${bundle}.es5.js`,
|
||||
sourcemap: true,
|
||||
},
|
||||
plugins: [
|
||||
resolve({ mainFields: ["jsnext"] }),
|
||||
commonjs(),
|
||||
json(),
|
||||
buble({
|
||||
transforms: {
|
||||
dangerousForOf: true,
|
||||
generator: false,
|
||||
}
|
||||
}),
|
||||
image(),
|
||||
],
|
||||
external: ['reflect-metadata', 'doric'],
|
||||
onwarn: function (warning) {
|
||||
if (warning.code === 'THIS_IS_UNDEFINED') { return }
|
||||
console.warn(warning.message)
|
||||
}
|
||||
}
|
||||
}))
|
||||
console.warn(warning.message);
|
||||
},
|
||||
};
|
||||
})
|
||||
);
|
||||
|
51
doric-demo/src/TSXDemo.tsx
Normal file
51
doric-demo/src/TSXDemo.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
Panel,
|
||||
Group,
|
||||
VLayout,
|
||||
layoutConfig,
|
||||
Gravity,
|
||||
Text,
|
||||
Color,
|
||||
navbar,
|
||||
jsx,
|
||||
} from "doric";
|
||||
|
||||
@Entry
|
||||
class Example extends Panel {
|
||||
onShow() {
|
||||
navbar(context).setTitle("Example");
|
||||
}
|
||||
build(rootView: Group) {
|
||||
let count = 0;
|
||||
(
|
||||
<VLayout
|
||||
layoutConfig={layoutConfig().just().configAlignment(Gravity.Center)}
|
||||
width={200}
|
||||
height={200}
|
||||
space={20}
|
||||
border={{ color: Color.BLUE, width: 1 }}
|
||||
gravity={Gravity.Center}
|
||||
>
|
||||
<Text
|
||||
tag="Label"
|
||||
text={`${count}`}
|
||||
textSize={40}
|
||||
layoutConfig={layoutConfig().fit()}
|
||||
/>
|
||||
<Text
|
||||
text="Click to count"
|
||||
textSize={20}
|
||||
backgroundColor={Color.parse("#70a1ff")}
|
||||
textColor={Color.WHITE}
|
||||
onClick={() => {
|
||||
count++;
|
||||
const label = rootView.findViewByTag("Label") as Text;
|
||||
label.text = `${count}`;
|
||||
}}
|
||||
width={200}
|
||||
height={50}
|
||||
/>
|
||||
</VLayout>
|
||||
).in(rootView);
|
||||
}
|
||||
}
|
@@ -7,7 +7,9 @@
|
||||
"lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
"jsxFactory": "jsx.createElement",
|
||||
"jsxFragmentFactory": "jsx.Fragment",
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
@@ -58,5 +60,6 @@
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user