Skip to content

Commit 41b89bd

Browse files
author
Ovidiu Barabula
committed
feat(core): implement init task
1 parent e1d0114 commit 41b89bd

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

src/tasks/task-init-project.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,45 @@
88
import * as gulp from 'gulp';
99
import frontvue from '../core';
1010
import { PluginProvider } from '../plugin-manager/installable';
11-
import { AnyFunction, sleep } from '../util/utility-functions';
11+
import { AnyFunction } from '../util/utility-functions';
1212

1313

1414
// Configuration defaults
1515
const configDefaults = {
16-
fullName: 'John Smith',
17-
useDefault: true,
16+
buildDir: 'build',
17+
plugins: [],
18+
sourceDir: 'source',
1819
};
1920

2021
// Configuration wizard questions
2122
const questions = [
2223
{
23-
default: configDefaults.fullName,
24-
message: 'Type in your full name',
25-
name: 'fullName',
24+
default: configDefaults.sourceDir,
25+
message: 'Main source directory',
26+
name: 'sourceDir',
2627
type: 'input',
2728
},
29+
{
30+
default: configDefaults.buildDir,
31+
message: 'Main build directory',
32+
name: 'buildDir',
33+
type: 'input',
34+
},
35+
{
36+
choices: ['stylus', 'vue', 'html'],
37+
message: 'What plugins would you like to use?',
38+
name: 'plugins',
39+
type: 'checkbox',
40+
},
2841
];
2942

3043
// Object to be exported
3144
const taskExport = {
32-
// configDefaults,
33-
// configQuestionnaire: {
34-
// namespace: 'init',
35-
// questions,
36-
// },
45+
configDefaults,
46+
configQuestionnaire: {
47+
namespace: 'init',
48+
questions,
49+
},
3750
description: 'Task for initializing a new project',
3851
hook: 'init',
3952
name: 'init',
@@ -47,14 +60,20 @@ const taskExport = {
4760
* @param pluginProvider Assortment of tools for plugins and tasks (e.g. logger, config manager, etc.)
4861
*/
4962
async function taskFn(done: AnyFunction, { config, logger }: PluginProvider): Promise<any> {
50-
console.log(JSON.stringify(await config.get(), null, 2));
51-
// return gulp.series('template', 'clean', 'process', 'watch');
52-
return done && done();
63+
return new Promise(async resolve => {
64+
const core = await frontvue;
65+
66+
for (const hook of ['config', 'template']) {
67+
await core.run(hook);
68+
}
69+
70+
resolve();
71+
});
5372
}
5473

5574

5675
/* test:start */
57-
export { taskFn };
76+
export { taskFn, configDefaults };
5877
/* test:end */
5978

6079
export default taskExport;

src/tasks/task-init-projects.spec.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@ describe('#Task: Init project', () => {
2020
};
2121
});
2222

23-
it('does what it is supposed to do', () => {
24-
expect(taskFn(callback, pluginProvider)).to.not.throw;
25-
});
26-
2723

28-
it('calls the callback function', async () => {
24+
it('returns a promise', async () => {
2925
let wasCalled = false;
3026
const customCallback = () => wasCalled = true;
31-
await taskFn(customCallback, pluginProvider);
32-
expect(wasCalled).to.have.been.true;
27+
expect(taskFn(customCallback, pluginProvider)).to.satisfy(subject => subject instanceof Promise);
3328
});
3429
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy