Files
cocos4/rollup/babel-plugin-mix-ts-js.js
T
Leslie Leigh 3ed9edfbc6 phy framework (#3644)
* phy framework

* phy mat

* framework/index.ts

* a node can have more than one collider

* rename physical to physics

* fix

* fix

* support mix ts js

* fix

* fix problems in issue

* fix

* remove RigidBodyType, add DataFlow

* useGravity, freezeRotation, isKinematic

* raycasts

* fit buildin-world raycast options

* add contact material

* lint

* add rigid-body-component.ts

* some improvements

* improvements

* fix bug
2018-12-27 12:03:10 +08:00

31 lines
1.1 KiB
JavaScript

const fs = require('fs');
const path = require('path');
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = function(babel) {
return {
visitor: {
ImportDeclaration(babelPath, state) {
const currentFileName = state.filename;
const currentFileFolder = path.dirname(currentFileName);
const source = babelPath.node.source;
const oldSourcePath = source.value;
const destPath = path.resolve(currentFileFolder, oldSourcePath);
if (!fs.existsSync(`${destPath}.ts`)) {
return;
}
const newSourcePath = `${oldSourcePath}.ts`;
const newSource = babel.types.stringLiteral(newSourcePath);
console.log(`Resolve ${oldSourcePath}(${currentFileName}) to ${newSourcePath}`);
const newPath = babel.types.importDeclaration(babelPath.node.specifiers, newSource);
babelPath.replaceWith(newPath);
},
}
};
}