Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add served dirs to gro config #82

Merged
merged 3 commits into from
Feb 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"request": "launch",
"name": "gro",
"program": "${workspaceFolder}/dist/cli/gro.js",
"args": ["project/dev"],
"args": ["dev"],
"runtimeArgs": [],
"outFiles": [
"${workspaceRoot}/.gro/dev/node/**/*.js",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ npm run bootstrap # builds and links `gro` - needed only once
gro test # make sure everything looks good - same as `npm test`

# development
gro project/dev # build in watch mode
gro dev # build in watch mode
gro project/dist # update the `gro` CLI

# release
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"test": "gro test",
"bootstrap": "rm -rf .gro dist && tsc; cp -r .gro/prod/node/ dist/ && npm link",
"b": "npm run bootstrap",
"dev": "clear && rm -rf .gro && gro project/dev",
"dev": "clear && rm -rf .gro && gro dev",
"d": "npm run dev",
"redev": "clear && npm run bootstrap && gro project/dev",
"redev": "clear && npm run bootstrap && gro dev",
"r": "npm run redev",
"preversion": "npm run bootstrap && gro check && npm run bootstrap && gro project/build"
},
Expand Down
3 changes: 3 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {pathExists} from '../fs/nodeFs.js';
import {DEFAULT_BUILD_CONFIG} from './defaultBuildConfig.js';
import {DEFAULT_ECMA_SCRIPT_TARGET, EcmaScriptTarget} from '../build/tsBuildHelpers.js';
import {omitUndefined} from '../utils/object.js';
import type {ServedDirPartial} from '../build/ServedDir.js';

/*

Expand Down Expand Up @@ -40,6 +41,7 @@ export interface GroConfig {
readonly target: EcmaScriptTarget;
readonly sourceMap: boolean;
readonly logLevel: LogLevel;
readonly servedDirs?: ServedDirPartial[];
readonly primaryNodeBuildConfig: BuildConfig;
readonly primaryBrowserBuildConfig: BuildConfig | null;
}
Expand All @@ -49,6 +51,7 @@ export interface PartialGroConfig {
readonly target?: EcmaScriptTarget;
readonly sourceMap?: boolean;
readonly logLevel?: LogLevel;
readonly servedDirs?: ServedDirPartial[];
}

export interface GroConfigModule {
Expand Down
48 changes: 38 additions & 10 deletions src/dev.task.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,60 @@
import {Task} from './task/task.js';
import {Filer} from './build/Filer.js';
import {createDevServer} from './server/server.js';
import {printTiming} from './utils/print.js';
import {Timings} from './utils/time.js';
import {createDefaultBuilder} from './build/defaultBuilder.js';
import {paths, toBuildOutPath} from './paths.js';
import {loadGroConfig} from './config/config.js';
import {createDevServer} from './server/server.js';
import {GroConfig, loadGroConfig} from './config/config.js';
import {configureLogLevel} from './utils/log.js';
import {ServedDirPartial} from './build/ServedDir.js';

export const task: Task = {
description: 'start development server',
run: async (): Promise<void> => {
description: 'start dev server',
run: async ({log}) => {
const timings = new Timings();

const timingToLoadConfig = timings.start('load config');
const config = await loadGroConfig();
configureLogLevel(config.logLevel);
// TODO should this be `findServedBuildConfig`? or should this be a property on the config itself?
// maybe that gets added by a normalization step?
const buildConfigToServe = config.primaryBrowserBuildConfig ?? config.primaryNodeBuildConfig;
const buildOutDirToServe = toBuildOutPath(true, buildConfigToServe.name, '');
timingToLoadConfig();

const timingToCreateFiler = timings.start('create filer');
const filer = new Filer({
builder: await createDefaultBuilder(),
sourceDirs: [paths.source],
servedDirs: [buildOutDirToServe],
servedDirs: config.servedDirs || getDefaultServedDirs(config),
buildConfigs: config.builds,
target: config.target,
sourceMap: config.sourceMap,
});
timingToCreateFiler();

const timingToCreateDevServer = timings.start('create dev server');
const server = createDevServer({filer});
timingToCreateDevServer();

await Promise.all([filer.init(), server.start()]);
await Promise.all([
(async () => {
const timingToInitFiler = timings.start('init filer');
await filer.init();
timingToInitFiler();
})(),
(async () => {
const timingToStartDevServer = timings.start('start dev server');
await server.start();
timingToStartDevServer();
})(),
]);

for (const [key, timing] of timings.getAll()) {
log.trace(printTiming(key, timing));
}
},
};

const getDefaultServedDirs = (config: GroConfig): ServedDirPartial[] => {
const buildConfigToServe = config.primaryBrowserBuildConfig ?? config.primaryNodeBuildConfig;
const buildOutDirToServe = toBuildOutPath(true, buildConfigToServe.name, '');
return [buildOutDirToServe];
};
3 changes: 1 addition & 2 deletions src/docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ What is a task? See [`src/tasks/README.md`](../task).
- [clean](../clean.task.ts) - remove build and temp files
- [compile](../compile.task.ts) - compiles all files to the build directory
- [deploy](../deploy.task.ts) - deploy to gh-pages
- [dev](../dev.task.ts) - start development server
- [dev](../dev.task.ts) - start dev server
- [dist](../dist.task.ts) - create the distribution
- [format](../format.task.ts) - format source files
- [gen](../gen.task.ts) - run code generation scripts
- [project/build](../project/build.task.ts) - build, create, and link the distribution
- [project/compilerBenchmark](../project/compilerBenchmark.task.ts) - benchmark compilation with different libraries
- [project/dev](../project/dev.task.ts) - build typescript in watch mode for development
- [project/dist](../project/dist.task.ts) - create and link the distribution
- [project/echo](../project/echo.task.ts) - diagnostic task that logs CLI args
- [project/link](../project/link.task.ts) - link the distribution
Expand Down
2 changes: 2 additions & 0 deletions src/gro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {createFilter} from '@rollup/pluginutils';

// import {createDirectoryFilter} from './build/utils.js';
import {GroConfigCreator, PartialGroConfig} from './config/config.js';
import {toBuildOutPath} from './paths.js';
import {LogLevel} from './utils/log.js';

// This is the config for the Gro project itself.
Expand All @@ -26,6 +27,7 @@ const createConfig: GroConfigCreator = async () => {
},
],
logLevel: LogLevel.Trace,
servedDirs: [toBuildOutPath(true, 'browser', 'client'), toBuildOutPath(true, 'browser', '')],
};
return config;
};
Expand Down
45 changes: 0 additions & 45 deletions src/project/dev.task.ts

This file was deleted.