Skip to content

Commit

Permalink
文件变更监控功能
Browse files Browse the repository at this point in the history
  • Loading branch information
meepobrother committed May 3, 2019
1 parent 18afc2b commit 5e91025
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 260 deletions.
3 changes: 3 additions & 0 deletions framework/template/admin/pages/home/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.nger-home-page{
display: block;
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@types/babel__template": "^7.0.2",
"@types/babel__traverse": "^7.0.6",
"@types/chai": "^4.1.7",
"@types/chokidar": "^2.1.3",
"@types/csso": "^3.5.1",
"@types/enhanced-resolve": "^3.0.6",
"@types/express": "^4.16.1",
Expand Down Expand Up @@ -55,7 +54,7 @@
"browserslist": "^4.5.6",
"caniuse-api": "^3.0.0",
"chai": "^4.2.0",
"chokidar": "^2.1.5",
"chokidar": "^3.0.0",
"cids": "^0.6.0",
"class-validator": "^0.9.1",
"copy-webpack-plugin": "^5.0.3",
Expand Down Expand Up @@ -181,4 +180,4 @@
"platform:ios": "ts-node -r tsconfig-paths/register packages/nger-cli/lib/bin.ts build lib -n nger-platform-ios",
"platform:android": "ts-node -r tsconfig-paths/register packages/nger-cli/lib/bin.ts build lib -n nger-platform-android"
}
}
}
21 changes: 14 additions & 7 deletions packages/nger-compiler-preact/lib/preact.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NgModuleBootstrap, NgModuleRef, PLATFORM_ID, NgerConfig } from 'nger-core';
import { NgModuleBootstrap, NgModuleRef, Logger, PLATFORM_ID, NgerConfig } from 'nger-core';
// 将ng模板编译成preact可以执行的文件
import { NgerCompilerPreactHtml } from './html'
import { NgerCompilerPreactStyle } from './style'
Expand All @@ -7,9 +7,9 @@ import { NgerCompilerPreactTypescript } from './typescript'
import { NgerCompilerNgMetadata } from 'nger-compiler'
import { NgerComponentConfig, NgerControllerConfig } from './types'
import { NgerCompilerPreactController } from './controller'

import chokidar from 'chokidar';
import { Stats } from 'fs-extra'
import { join } from 'path';
import { watcher } from 'nger-watcher';
const root = process.cwd();
// 提供统一的外观
export class NgerCompilerPreact extends NgModuleBootstrap {
Expand All @@ -20,7 +20,8 @@ export class NgerCompilerPreact extends NgModuleBootstrap {
public ts: NgerCompilerPreactTypescript,
public metadata: NgerCompilerNgMetadata,
public controller: NgerCompilerPreactController,
public config: NgerConfig
public config: NgerConfig,
public logger: Logger
) {
super();
}
Expand All @@ -29,8 +30,9 @@ export class NgerCompilerPreact extends NgModuleBootstrap {
// 拿到ngModule的文件名
const framework = join(root, 'framework');
const addon = join(root, 'addon');
watcher([addon, framework], async (opt, fileName) => {
if (fileName && (opt === 'add' || opt === 'change')) {
const handlerFile = async (opt: string, fileName: string, stats: Stats) => {
this.logger.info(`${opt}:${fileName}@${stats.atime}`)
if (fileName && stats.isFile() && (opt === 'add' || opt === 'change')) {
// 拿到ngModuleMetadata
const metadata = this.metadata.getMetadata(fileName);
if (metadata) {
Expand All @@ -54,7 +56,12 @@ export class NgerCompilerPreact extends NgModuleBootstrap {
}
}
}
})
}
chokidar.watch([addon, framework])
.on('add', (opt, file, stats) => handlerFile(opt, file, stats))
.on('change', (opt, file, stats) => handlerFile(opt, file, stats))
.on('error', () => { });

} catch (e) { }
}
}
11 changes: 0 additions & 11 deletions packages/nger-watcher/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions packages/nger-watcher/__tests__/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/nger-watcher/__tests__/test.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/nger-watcher/lib/index.ts

This file was deleted.

33 changes: 0 additions & 33 deletions packages/nger-watcher/package.json

This file was deleted.

Loading

0 comments on commit 5e91025

Please sign in to comment.