Skip to content
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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@

_Note: Gaps between patch versions are faulty, broken or test releases._

## v2.0.0 (2023-08-10)

#### :boom: [Breaking Change]

* `make-test` - the command interface has been changed
* `make` - support for the `make app` has been removed

#### :rocket: [New Feature]

* `create-app` - the function has been added for the easy creation of v4fire app

#### :house: Internal

* Moved to using Handlebars templates

#### :memo: [Documentation]

* `help` - documentation has been updated
* README.md has been updated

## v1.5.2 (2023-04-14)

#### :bug: Bug Fix
Expand Down
45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ v4fire -h

## Usage

### Make app
### Create app

It is the easiest way to start use V4Fire

```bash
v4fire make app my-app && cd my-app && npm run build
v4fire create-app my-app && yarn build
```

It will create application ready for work.
It will create application ready for work in the current directory.

```bash
v4fire create-app my-app/foo/bar && cd my-app/foo/bar && yarn build
```
It will create application ready for work in the target directory.

### Create a workspace

Expand Down Expand Up @@ -45,13 +50,13 @@ It will remove workspace folder, clear package-lock.json and components-lock.jso
v4fire make block hello-world
```

It will create `src/base/b-hello-world` component.
It will create `src/components/b-hello-world` component.

```bash
v4fire make block b-hello-world
```

Also, it will create `src/base/b-hello-world`.
Also, it will create `src/components/b-hello-world`.

```bash
v4fire make page hello-world
Expand Down Expand Up @@ -84,7 +89,7 @@ v4fire make block hello-world --template functional --extend i-data
v4fire rename hello-world app-loader
```

It will rename `src/base/b-hello-world` to `src/base/b-app-loader`.
It will rename `src/components/b-hello-world` to `src/components/b-app-loader`.

### Resolve changelog

Expand All @@ -98,18 +103,28 @@ WARNING: Conflicts within the same record may not be resolved correctly!
### Make test

```bash
v4fire make-test src/base/b-slider
v4fire make-test block hello-world
```
It will generate simple tests for the `src/components/**/b-hello-world` component, if it exists.

You can generate test files for both component and module.
The tool also will take care of updating [demo-page](https://github.com/V4Fire/Client/blob/master/src/pages/p-v4-components-demo/index.js)
dependencies and adding new test cases to [test cases file](https://github.com/V4Fire/Client/blob/master/tests/cases.js).
```bash
v4fire make-test page slider
```
It will generate simple tests for the `src/pages/**/p-slider` page, if it exists.

For both component and module the tool generates `test/index.js` [file](src/templates/test/module/simple/index.js)
that performs basic test setup and executes simple test.
```bash
v4fire make-test block src/foo/bar/componentName
```
It will generate simple `component` tests in the `src/foo/bar/componentName` folder

```bash
v4fire make-test page src/foo/bar/componentName
```
It will generate simple `page` tests in the `src/foo/bar/componentName` folder

The tool also will take care of updating [demo-page](https://github.com/V4Fire/Client/blob/master/src/pages/p-v4-components-demo/index.js)

In case of _module_ test, the tool relies on `b-dummy` [component](https://github.com/V4Fire/Client/tree/master/src/base/b-dummy)
designed specifically for testing purposes.
The tool generates a `test` folder for both components and pages. The [template for component](src/templates/test/block) and the [template for page](src/templates/test/block) contain the basic test setup and can execute these simple tests.

#### Runners

Expand All @@ -118,7 +133,7 @@ and all test code locates in the `test/index.js` file. So if you'd like to have
you can specify them just after the path to module or component being tested.

```bash
v4fire make-test src/base/b-slider analytics render events
v4fire make-test src/components/b-slider analytics render events
```

For each specified runner the tool will create `test/runner/runner-name` file. [Here is the example](src/templates/test/module/with-runners/runners/runner.js)
Expand Down
38 changes: 22 additions & 16 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@ const {Application} = require('../src/application');

const options = yargs
.command(
'make-test <path> [runners..]',
'Make test for module or component',
'create-app [target]',
'Make simple application using basic v4fire template',
(yargs) => {
yargs.positional('target', {
type: 'string'
});
}
)
.command(
'make-test <subject> <target>',
'Make test for page or component',
(yargs) => {
yargs
.positional('path', {
demandOption: true,
type: 'string'
.positional('subject', {
type: 'string',
choices: ['page', 'block']
})
.positional('runners', {
.positional('target', {
demandOption: true,
type: 'string'
});
}
Expand Down Expand Up @@ -67,13 +77,13 @@ const options = yargs

.command(
'make <subject> <name> [path]',
'Make block, page or app',
'Make block or page',
(yargs) => {
yargs
.positional('subject', {
default: 'block',
type: 'string',
choices: ['block', 'page', 'app']
choices: ['block', 'page']
})
.positional('name', {
demandOption: true,
Expand Down Expand Up @@ -148,16 +158,12 @@ const options = yargs
.example('v4fire make block point', 'Make i-block b-point')
.example('v4fire make page card', 'Make i-dynamic-page p-card')
.example(
'v4fire make-test src/core/view-history',
'Make tests for view-history module'
)
.example(
'v4fire make-test src/base/b-slider',
'Make tests for b-slider component'
'v4fire make-test block slider',
'Make tests for src/components/**/b-slider component, if it exists'
)
.example(
'v4fire make-test src/base/b-slider analytics render events',
'Make tests for b-slider component with different runners'
'v4fire make-test page src/foo/bar/p-test',
'Make tests for src/foo/bar/p-test page'
)
.example(
'v4fire resolve-changelog',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@v4fire/cli",
"version": "1.6.0",
"version": "2.0.0",
"description": "Tools for creating V4Fire blocks and pages from CLI",
"main": "index.js",
"bin": {
Expand All @@ -27,6 +27,7 @@
"fs-extra": "11.1.1",
"git-config-path": "2.0.0",
"glob": "9.3.4",
"handlebars": "4.7.7",
"parse-git-config": "3.0.0",
"typescript": "4.4.4",
"yargs": "17.7.1"
Expand Down
10 changes: 5 additions & 5 deletions src/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class Application {

async run() {
try {
const {command, subject} = this.config;
const
{commandNative: command, subject} = this.config;

this.log.info(`Command:${command} ${subject}`);
this.log.info(`Command: ${command} ${subject}`);

const controller =
this.getControllerInstance(
const controller = this.getControllerInstance(
`${ucfirst(camelize(`${command}-${subject}`))}Controller`
) ||
this.getControllerInstance(`${ucfirst(camelize(command))}Controller`);

if (controller == null) {
throw new Error(`Unknown controller: ${controllerName}`);
throw new Error('Unknown controller');
}

await controller.run();
Expand Down
30 changes: 30 additions & 0 deletions src/controllers/create-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require('path');
const {Controller} = require('../core/controller');

class CreateAppController extends Controller {
/** @override */
async run() {
const
source = this.vfs.resolve(__dirname, '../templates/app'),
appName = this.config.target || 'v4fire-app',
appPath = appName.split(path.sep),
directoryExists = this.vfs.exists(this.config.target) && this.vfs.isDirectory(this.config.target);

let
destination = './';

if (appPath.length <= 1 && !directoryExists) {
this.vfs.resolve('./');

} else {
destination = this.vfs.resolve(...appPath);
}

this.handlebarsOptions = {name: appName};

await this.vfs.ensureDir(destination);
await this.copyDir(source, destination, {withFolders: true});
}
}

module.exports = CreateAppController;
4 changes: 3 additions & 1 deletion src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const ResolveChangelogController = require('./resolve-changelog');
const CreateWorkspaceController = require('./create-workspace');
const RemoveWorkspaceController = require('./remove-workspace');
const UpGitController = require('./up-yarn-git-dependencies');
const CreateAppController = require('./create-app');

module.exports = {
MakeController,
Expand All @@ -13,5 +14,6 @@ module.exports = {
ResolveChangelogController,
CreateWorkspaceController,
UpGitController,
RemoveWorkspaceController
RemoveWorkspaceController,
CreateAppController
};
Loading