init
This commit is contained in:
commit
8d277bf3eb
|
|
@ -0,0 +1,94 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
build
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
package-lock.json
|
||||
src/oak-app-domain
|
||||
*/public/locales
|
||||
# 如果不自动生成allRouters,这里要注释掉
|
||||
web/src/**/allRouters.ts
|
||||
lib/**
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"useTabs": false,
|
||||
"tabWidth": 4,
|
||||
"printWidth": 80,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5",
|
||||
"semi": true,
|
||||
"endOfLine": "lf",
|
||||
"jsxSingleQuote": true
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "ts_lib_test",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"test": "tsc && node lib/index.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"oak-domain": "^5.1.7",
|
||||
"oak-general-business": "^5.5.4",
|
||||
"tslib": "^2.8.0",
|
||||
"typescript": "^5.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.8.1"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,132 @@
|
|||
import { join, dirname, extname } from 'path';
|
||||
import * as ts from 'typescript';
|
||||
import * as fs from 'fs';
|
||||
|
||||
const sourceFilePath = join(__dirname, '..', 'test', 'sourceTest.ts');
|
||||
|
||||
// 创建自定义的 CompilerHost
|
||||
const createCustomCompilerHost = (
|
||||
options: ts.CompilerOptions
|
||||
): ts.CompilerHost => {
|
||||
const defaultHost = ts.createCompilerHost(options);
|
||||
|
||||
return {
|
||||
...defaultHost,
|
||||
resolveModuleNameLiterals(
|
||||
moduleLiterals,
|
||||
containingFile,
|
||||
redirectedReference,
|
||||
options,
|
||||
containingSourceFile
|
||||
) {
|
||||
return moduleLiterals.map((moduleLiteral) => {
|
||||
const { resolvedModule } = ts.resolveModuleName(
|
||||
moduleLiteral.text,
|
||||
containingFile,
|
||||
options,
|
||||
{
|
||||
fileExists: defaultHost.fileExists,
|
||||
readFile: defaultHost.readFile,
|
||||
}
|
||||
);
|
||||
|
||||
if (resolvedModule) {
|
||||
// 如果解析成功,直接返回
|
||||
return { resolvedModule };
|
||||
}
|
||||
|
||||
// 如果解析失败,尝试从 node_modules 目录解析
|
||||
const projectRoot = dirname(containingFile);
|
||||
const LiteralText = moduleLiteral.text;
|
||||
// 如果是相对导入
|
||||
if (LiteralText.startsWith('.')) {
|
||||
const possiblePaths = [
|
||||
join(projectRoot, LiteralText),
|
||||
join(projectRoot, LiteralText + '.ts'),
|
||||
join(projectRoot, LiteralText + '.d.ts'),
|
||||
join(projectRoot, LiteralText, 'index.ts'),
|
||||
join(projectRoot, LiteralText, 'index.d.ts'),
|
||||
];
|
||||
for (const path of possiblePaths) {
|
||||
if (fs.existsSync(path)) {
|
||||
return {
|
||||
resolvedModule: {
|
||||
resolvedFileName: path,
|
||||
isExternalLibraryImport: false,
|
||||
extension: extname(path) as ts.Extension,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
// 绝对导入的话,直接尝试从 node_modules 目录解析
|
||||
const possiblePaths = [
|
||||
join(projectRoot, 'node_modules', moduleLiteral.text),
|
||||
join(
|
||||
projectRoot,
|
||||
'node_modules',
|
||||
moduleLiteral.text,
|
||||
'index.ts'
|
||||
),
|
||||
join(
|
||||
projectRoot,
|
||||
'node_modules',
|
||||
moduleLiteral.text,
|
||||
'index.d.ts'
|
||||
),
|
||||
];
|
||||
|
||||
for (const path of possiblePaths) {
|
||||
if (fs.existsSync(path)) {
|
||||
return {
|
||||
resolvedModule: {
|
||||
resolvedFileName: path,
|
||||
isExternalLibraryImport: true,
|
||||
extension: extname(path) as ts.Extension,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 如果仍然无法解析,返回 undefined,使用默认的导入方式
|
||||
return { resolvedModule: undefined };
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// 创建编译选项
|
||||
const compilerOptions: ts.CompilerOptions = {
|
||||
allowJs: true,
|
||||
};
|
||||
|
||||
// 创建自定义的 CompilerHost
|
||||
const customHost = createCustomCompilerHost(compilerOptions);
|
||||
|
||||
// 创建 Program
|
||||
const program = ts.createProgram([sourceFilePath], compilerOptions, customHost);
|
||||
|
||||
// 进行类型检查
|
||||
const diagnostics = ts.getPreEmitDiagnostics(program);
|
||||
if (diagnostics.length) {
|
||||
console.error(ts.formatDiagnostics(diagnostics, customHost));
|
||||
// process.exit(1);
|
||||
}
|
||||
|
||||
const testSourceFile = join(
|
||||
__dirname,
|
||||
'..',
|
||||
'node_modules',
|
||||
'oak-general-business',
|
||||
'lib',
|
||||
'entities',
|
||||
'User.d.ts'
|
||||
);
|
||||
console.log('testSourceFile', testSourceFile);
|
||||
|
||||
const sourceFile = program.getSourceFile(testSourceFile);
|
||||
console.log('Source file found:', sourceFile ? 'Yes' : 'No');
|
||||
|
||||
// program.getSourceFiles().forEach(sourceFile => {
|
||||
// console.log(sourceFile.fileName);
|
||||
// });
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
import { Schema as User } from 'oak-general-business/lib/entities/User';
|
||||
import { EntityDesc } from 'oak-domain/lib/types';
|
||||
import { String, Int, Text, Boolean, Datetime } from 'oak-domain/lib/types/DataType';
|
||||
|
||||
export interface Schema extends User {
|
||||
hahha: String<32>;
|
||||
}
|
||||
|
||||
export const entityDesc: EntityDesc<
|
||||
Schema
|
||||
> = {
|
||||
locales: {
|
||||
zh_CN: {
|
||||
name: '用户',
|
||||
attr: {
|
||||
hahha: '哈哈',
|
||||
name: '姓名',
|
||||
nickname: '昵称',
|
||||
birth: '生日',
|
||||
password: '密码',
|
||||
passwordSha1: 'sha1加密密码',
|
||||
gender: '性别',
|
||||
idCardType: '证件类型',
|
||||
idNumber: '证件号码',
|
||||
ref: '指向用户',
|
||||
files: '相关文件',
|
||||
codes: '微信分享二维码',
|
||||
isRoot: '是否超级用户',
|
||||
addresses: '收货地址',
|
||||
hasPassword: '用户是否存在密码'
|
||||
},
|
||||
},
|
||||
},
|
||||
indexes: [
|
||||
{
|
||||
name: 'index_birth',
|
||||
attributes: [
|
||||
{
|
||||
name: 'birth',
|
||||
direction: 'ASC',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'index_fulltext',
|
||||
attributes: [
|
||||
{
|
||||
name: 'name',
|
||||
},
|
||||
{
|
||||
name: 'nickname',
|
||||
},
|
||||
],
|
||||
config: {
|
||||
type: 'fulltext',
|
||||
parser: 'ngram',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'index_userState_refId',
|
||||
attributes: [
|
||||
{
|
||||
name: 'userState',
|
||||
},
|
||||
{
|
||||
name: 'ref',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"jsx": "preserve",
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "ESNEXT", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
// "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'. */
|
||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
"importHelpers": true,
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
"skipLibCheck": true,
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "classic", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
/* Advanced Options */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/*.spec.ts",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue