fix: path resolve problem

This commit is contained in:
春希 2020-04-07 16:55:15 +08:00
parent 55630d6347
commit b12c0f8350
46 changed files with 117 additions and 158 deletions

View File

@ -7,8 +7,7 @@
"lib"
],
"scripts": {
"compile": "rimraf lib && tsc",
"build": "rimraf lib && webpack",
"build": "rimraf lib && tsc",
"demo": "ts-node -r tsconfig-paths/register ./src/demo/main.ts",
"test": "ava"
},
@ -24,11 +23,7 @@
"rimraf": "^3.0.2",
"ts-loader": "^6.2.2",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.9.0",
"tsconfig-paths-webpack-plugin": "^3.2.0",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11",
"webpack-node-externals": "^1.7.2"
"tsconfig-paths": "^3.9.0"
},
"ava": {
"compileEnhancements": false,

View File

@ -1,7 +1,7 @@
import { IResultDir, IResultFile } from '@/types';
import { IResultDir, IResultFile } from '../types';
import CodeGenerator from '@/index';
import { createDiskPublisher } from '@/publisher/disk';
import CodeGenerator from '../index';
import { createDiskPublisher } from '../publisher/disk';
import demoSchema from './simpleDemo';
function flatFiles(rootName: string | null, dir: IResultDir): IResultFile[] {

View File

@ -1,9 +1,4 @@
import { IProjectSchema } from '@/types';
// meta: {
// title: '测试',
// router: '/',
// },
import { IProjectSchema } from '../types';
const demoData: IProjectSchema = {
version: '1.0.0',

View File

@ -11,10 +11,10 @@ import {
PostProcessor,
} from '../types';
import ResultDir from '@/model/ResultDir';
import SchemaParser from '@/parser/SchemaParser';
import ResultDir from '../model/ResultDir';
import SchemaParser from '../parser/SchemaParser';
import { createModuleBuilder } from '@/generator/ModuleBuilder';
import { createModuleBuilder } from '../generator/ModuleBuilder';
interface IModuleInfo {
moduleName?: string;
@ -67,7 +67,7 @@ export class ProjectBuilder implements IProjectBuilder {
// Parse / Format
// Preprocess
// Colllect Deps
// Collect Deps
// Parse JSExpression
const parseResult: IParseResult = schemaParser.parse(schema);
let buildResult: IModuleInfo[] = [];

View File

@ -2,9 +2,9 @@
* Schema
*
*/
import { createProjectBuilder } from '@/generator/ProjectBuilder';
import { createDiskPublisher } from '@/publisher/disk';
import createIceJsProjectBuilder from '@/solutions/icejs';
import { createProjectBuilder } from './generator/ProjectBuilder';
import { createDiskPublisher } from './publisher/disk';
import createIceJsProjectBuilder from './solutions/icejs';
export * from './types';

View File

@ -6,10 +6,8 @@
import { SUPPORT_SCHEMA_VERSION_LIST } from '../const';
import { handleChildren } from '../utils/children';
import { uniqueArray } from '../utils/common';
import {
ChildNodeItem,
ChildNodeType,
CodeGeneratorError,
CompatibilityError,
@ -86,7 +84,7 @@ class SchemaParser implements ISchemaParser {
});
}
} else {
throw new CodeGeneratorError(`Can't find anything to generator.`);
throw new CodeGeneratorError(`Can't find anything to generate.`);
}
// 建立所有容器的内部依赖索引

View File

@ -5,7 +5,6 @@ import {
ChunkType,
FileType,
ICodeStruct,
IContainerInfo,
} from '../../../types';
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {

View File

@ -11,7 +11,7 @@ import {
IJSExpression,
} from '../../../types';
import { handleChildren } from '@/utils/children';
import { handleChildren } from '../../../utils/children';
import { generateCompositeType } from '../../utils/compositeType';
import { REACT_CHUNK_NAME } from './const';

View File

@ -1,12 +1,12 @@
import { COMMON_CHUNK_NAME } from '@/const/generator';
import { generateCompositeType } from '@/plugins/utils/compositeType';
import { COMMON_CHUNK_NAME } from '../../const/generator';
import { generateCompositeType } from '../../plugins/utils/compositeType';
import {
BuilderComponentPlugin,
ChunkType,
FileType,
ICodeStruct,
IProjectInfo,
} from '@/types';
} from '../../types';
// TODO: How to merge this logic to common deps
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {

View File

@ -1,4 +1,4 @@
import { COMMON_CHUNK_NAME } from '@/const/generator';
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import {
BuilderComponentPlugin,
@ -6,7 +6,7 @@ import {
FileType,
ICodeStruct,
IProjectInfo,
} from '@/types';
} from '../../../../../types';
// TODO: How to merge this logic to common deps
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {

View File

@ -1,4 +1,4 @@
import { COMMON_CHUNK_NAME } from '@/const/generator';
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import {
BuilderComponentPlugin,
@ -6,7 +6,7 @@ import {
FileType,
ICodeStruct,
IProjectInfo,
} from '@/types';
} from '../../../../../types';
// TODO: How to merge this logic to common deps
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {

View File

@ -1,4 +1,4 @@
import { COMMON_CHUNK_NAME } from '@/const/generator';
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import {
BuilderComponentPlugin,
@ -6,7 +6,7 @@ import {
FileType,
ICodeStruct,
IProjectInfo,
} from '@/types';
} from '../../../../../types';
// TODO: How to merge this logic to common deps
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {

View File

@ -1,4 +1,4 @@
import { COMMON_CHUNK_NAME } from '@/const/generator';
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import {
BuilderComponentPlugin,
@ -7,7 +7,7 @@ import {
ICodeStruct,
IPackageJSON,
IProjectInfo,
} from '@/types';
} from '../../../../../types';
interface IIceJsPackageJSON extends IPackageJSON {
ideMode: {

View File

@ -1,4 +1,4 @@
import { COMMON_CHUNK_NAME } from '@/const/generator';
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import {
BuilderComponentPlugin,
@ -6,7 +6,7 @@ import {
FileType,
ICodeStruct,
IRouterInfo,
} from '@/types';
} from '../../../../../types';
// TODO: How to merge this logic to common deps
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,5 @@
import ResultFile from '@/model/ResultFile';
import { IResultFile } from '@/types';
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(

View File

@ -1,5 +1,9 @@
import ResultDir from '@/model/ResultDir';
import { IProjectTemplate, IResultDir, IResultFile } from '@/types';
import ResultDir from '../../../../../model/ResultDir';
import {
IProjectTemplate,
IResultDir,
IResultFile,
} from '../../../../../types';
import file12 from './files/abc.json';
import file11 from './files/build.json';

View File

@ -1,12 +1,12 @@
import { COMMON_CHUNK_NAME } from '@/const/generator';
import { generateCompositeType } from '@/plugins/utils/compositeType';
import { COMMON_CHUNK_NAME } from '../../const/generator';
import { generateCompositeType } from '../../plugins/utils/compositeType';
import {
BuilderComponentPlugin,
ChunkType,
FileType,
ICodeStruct,
IProjectInfo,
} from '@/types';
} from '../../types';
// TODO: How to merge this logic to common deps
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {

View File

@ -1,13 +1,12 @@
import { COMMON_CHUNK_NAME } from '@/const/generator';
import { generateCompositeType } from '@/plugins/utils/compositeType';
// import { } from '@/plugins/utils/jsExpression';
import { COMMON_CHUNK_NAME } from '../../const/generator';
import {
BuilderComponentPlugin,
ChunkType,
FileType,
ICodeStruct,
IUtilInfo,
} from '@/types';
} from '../../types';
// TODO: How to merge this logic to common deps
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {

View File

@ -1,4 +1,4 @@
import { CompositeArray, CompositeValue, ICompositeObject } from '@/types';
import { CompositeArray, CompositeValue, ICompositeObject } from '../../types';
import { generateValue, isJsExpression } from './jsExpression';
function generateArray(value: CompositeArray): string {

View File

@ -1,6 +1,6 @@
import prettier from 'prettier';
import { PostProcessor } from '@/types';
import { PostProcessor } from '../../types';
const PARSERS = ['css', 'scss', 'less', 'json', 'html', 'vue'];

View File

@ -1,4 +1,4 @@
import { CodeGeneratorError, IResultDir } from '@/types';
import { CodeGeneratorError, IResultDir } from '../../types';
export type PublisherFactory<T, U> = (configuration?: Partial<T>) => U;

View File

@ -1,7 +1,7 @@
import { existsSync, mkdir, writeFile } from 'fs';
import { join } from 'path';
import { IResultDir, IResultFile } from '@/types';
import { IResultDir, IResultFile } from '../../types';
export const writeFolder = async (
folder: IResultDir,

View File

@ -1,27 +1,27 @@
import { IProjectBuilder } from '@/types';
import { IProjectBuilder } from '../types';
import { createProjectBuilder } from '@/generator/ProjectBuilder';
import { createProjectBuilder } from '../generator/ProjectBuilder';
import esmodule from '@/plugins/common/esmodule';
import containerClass from '@/plugins/component/react/containerClass';
import containerInitState from '@/plugins/component/react/containerInitState';
// import containerInjectUtils from '@/plugins/component/react/containerInjectUtils';
import containerLifeCycle from '@/plugins/component/react/containerLifeCycle';
import containerMethod from '@/plugins/component/react/containerMethod';
import jsx from '@/plugins/component/react/jsx';
import reactCommonDeps from '@/plugins/component/react/reactCommonDeps';
import css from '@/plugins/component/style/css';
import constants from '@/plugins/project/constants';
import iceJsEntry from '@/plugins/project/framework/icejs/plugins/entry';
import iceJsEntryHtml from '@/plugins/project/framework/icejs/plugins/entryHtml';
import iceJsGlobalStyle from '@/plugins/project/framework/icejs/plugins/globalStyle';
import iceJsPackageJSON from '@/plugins/project/framework/icejs/plugins/packageJSON';
import iceJsRouter from '@/plugins/project/framework/icejs/plugins/router';
import template from '@/plugins/project/framework/icejs/template';
import i18n from '@/plugins/project/i18n';
import utils from '@/plugins/project/utils';
import esmodule from '../plugins/common/esmodule';
import containerClass from '../plugins/component/react/containerClass';
import containerInitState from '../plugins/component/react/containerInitState';
import containerInjectUtils from '../plugins/component/react/containerInjectUtils';
import containerLifeCycle from '../plugins/component/react/containerLifeCycle';
import containerMethod from '../plugins/component/react/containerMethod';
import jsx from '../plugins/component/react/jsx';
import reactCommonDeps from '../plugins/component/react/reactCommonDeps';
import css from '../plugins/component/style/css';
import constants from '../plugins/project/constants';
import iceJsEntry from '../plugins/project/framework/icejs/plugins/entry';
import iceJsEntryHtml from '../plugins/project/framework/icejs/plugins/entryHtml';
import iceJsGlobalStyle from '../plugins/project/framework/icejs/plugins/globalStyle';
import iceJsPackageJSON from '../plugins/project/framework/icejs/plugins/packageJSON';
import iceJsRouter from '../plugins/project/framework/icejs/plugins/router';
import template from '../plugins/project/framework/icejs/template';
import i18n from '../plugins/project/i18n';
import utils from '../plugins/project/utils';
import { prettier } from '@/postprocessor';
import { prettier } from '../postprocessor';
export default function createIceJsProjectBuilder(): IProjectBuilder {
return createProjectBuilder({
@ -31,7 +31,7 @@ export default function createIceJsProjectBuilder(): IProjectBuilder {
reactCommonDeps,
esmodule,
containerClass,
// containerInjectUtils,
containerInjectUtils,
containerInitState,
containerLifeCycle,
containerMethod,
@ -42,7 +42,7 @@ export default function createIceJsProjectBuilder(): IProjectBuilder {
reactCommonDeps,
esmodule,
containerClass,
// containerInjectUtils,
containerInjectUtils,
containerInitState,
containerLifeCycle,
containerMethod,

View File

@ -143,3 +143,8 @@ export interface IProjectBuilder {
}
export type PostProcessor = (content: string, fileType: string) => string;
// TODO: temp interface, need modify
export interface IPluginOptions {
fileDirDepth: number;
}

View File

@ -3,7 +3,7 @@ import {
ChildNodeType,
IComponentNodeItem,
IJSExpression,
} from '@/types';
} from '../types';
// tslint:disable-next-line: no-empty
const noop = () => [];

View File

@ -1,17 +1,12 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es5",
"strictNullChecks": true,
"inlineSources": false,
"lib": ["es6"],
"downlevelIteration": true,
"paths": {
"@/*": ["./src/*"]
},
"outDir": "./lib",
"lib": [
"es6"
],
"types": ["node"],
"baseUrl": "." /* Base directory to resolve non-absolute module names. */
"baseUrl": ".", /* Base directory to resolve non-absolute module names. */
},
"include": [
"src/**/*"

View File

@ -1,31 +0,0 @@
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
mode: 'production',
target: 'node',
entry: {
index: './src/index.ts',
// demo: './src/demo/main.ts',
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
plugins: [new TsconfigPathsPlugin({/* options: see below */})],
},
output: {
// filename: 'bundle.js',
filename: '[name].js',
path: path.resolve(__dirname, 'lib'),
},
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
};