Skip to content

Commit

Permalink
feat: first release
Browse files Browse the repository at this point in the history
  • Loading branch information
neikvon committed Mar 8, 2020
1 parent 01307b2 commit 3aa23c1
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/commands/build.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export default class CommandBuild extends Command {
id: string;
alias: string;
args: string;
flags: never[];
description: string;
flags: (string | boolean)[][];
constructor(factory: Factory);
run(args: any, flags: any): Promise<void>;
}
24 changes: 18 additions & 6 deletions lib/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,35 @@ class CommandBuild extends fbi_1.Command {
this.id = 'build';
this.alias = 'b';
this.args = '';
this.flags = [];
this.description = 'command build description';
this.flags = [['-d, --dev-dependencies', 'with devDependencies', false]];
}
async run(args, flags) {
var _a;
this.debug(`Factory: (${this.factory.id})`, 'from command', `"${this.id}"`);
const spinner = this.createSpinner(`Start building...`).start();
const tsconifgFile = path_1.join(process.cwd(), 'tsconfig.json');
const outDir = fbi_1.utils.isModuleAvailable(tsconifgFile)
? require(tsconifgFile).compilerOptions.outDir
: 'lib';
await this.fs.remove(path_1.join(process.cwd(), outDir));
const tsconfigPath = path_1.join(process.cwd(), 'tsconfig.json');
const hasTsconfigFile = await this.fs.pathExists(tsconfigPath);
const tsconifg = hasTsconfigFile ? require(tsconfigPath) : null;
const distDir = path_1.join(process.cwd(), ((_a = tsconifg === null || tsconifg === void 0 ? void 0 : tsconifg.compilerOptions) === null || _a === void 0 ? void 0 : _a.outDir) || 'dist');
// const srcDir = join(process.cwd(), tsconifg.compilerOptions.rootDir||'src')
await this.fs.remove(distDir);
const execOpts = {
...this.factory.execOpts,
stdio: flags.debug ? 'inherit' : 'pipe'
};
await this.exec.command('prisma2 generate', execOpts);
await this.exec.command('tsc', execOpts);
if (flags.devDependencies) {
const pkg = require(path_1.join(process.cwd(), 'package.json'));
const ver = this.factory.version ? `#${this.factory.version}` : '';
pkg['devDependencies'] = fbi_1.utils.merge(pkg['devDependencies'], {
[this.factory.id]: `github:fbi-js/${this.factory.id}${ver}`,
fbi: 'next'
});
await this.fs.writeFile(path_1.join(distDir, 'package.json'), JSON.stringify(pkg, null, 2));
await this.fs.copy(path_1.join(process.cwd(), '.fbi.config.js'), path_1.join(distDir, '.fbi.config.js'));
}
spinner.succeed('build successfully');
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import CommandGenerate from './commands/generate';
import TemplateGraphql from './templates/graphql';
export default class FactoryNode extends Factory {
id: string;
version: any;
description: string;
commands: (CommandServe | CommandDb | CommandGenerate | CommandBuild)[];
commands: (CommandBuild | CommandServe | CommandDb | CommandGenerate)[];
templates: TemplateGraphql[];
execOpts: any;
}
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ const serve_1 = require("./commands/serve");
const db_1 = require("./commands/db");
const generate_1 = require("./commands/generate");
const graphql_1 = require("./templates/graphql");
// @ts-ignore
const package_json_1 = require("../package.json");
class FactoryNode extends fbi_1.Factory {
constructor() {
super(...arguments);
this.id = 'factory-node';
this.version = package_json_1.version;
this.description = 'factory for node.js application development';
this.commands = [
new build_1.default(this),
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "factory-node",
"version": "0.0.0",
"version": "0.0.1",
"description": "factory factory-node description",
"private": true,
"main": "lib/index.js",
Expand All @@ -13,16 +13,15 @@
"license": "MIT",
"dependencies": {
"ejs": "^3.0.1",
"fbi": "workspace:*",
"fbi": "^4.0.0-alpha.1",
"create-nexus-type": "^1.1.7",
"prisma2": "2.0.0-preview022",
"prisma2": "2.0.0-preview023",
"ts-node": "^8.6.2",
"ts-node-dev": "^1.0.0-pre.44",
"tslib": "^1.11.0",
"typescript": "^3.8.2"
"tslib": "^1.11.1",
"typescript": "^3.8.3"
},
"devDependencies": {
"tslib": "^1.11.0",
"@types/node": "^13.7.6",
"@types/ejs": "^3.0.1"
}
Expand Down
25 changes: 19 additions & 6 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default class CommandBuild extends Command {
id = 'build'
alias = 'b'
args = ''
flags = []
description = 'command build description'
flags = [['-d, --dev-dependencies', 'with devDependencies', false]]

constructor(public factory: Factory) {
super()
Expand All @@ -18,12 +18,13 @@ export default class CommandBuild extends Command {

const spinner = this.createSpinner(`Start building...`).start()

const tsconifgFile = join(process.cwd(), 'tsconfig.json')
const outDir = utils.isModuleAvailable(tsconifgFile)
? require(tsconifgFile).compilerOptions.outDir
: 'lib'
const tsconfigPath = join(process.cwd(), 'tsconfig.json')
const hasTsconfigFile = await this.fs.pathExists(tsconfigPath)
const tsconifg = hasTsconfigFile ? require(tsconfigPath) : null
const distDir = join(process.cwd(), tsconifg?.compilerOptions?.outDir || 'dist')
// const srcDir = join(process.cwd(), tsconifg.compilerOptions.rootDir||'src')

await this.fs.remove(join(process.cwd(), outDir))
await this.fs.remove(distDir)

const execOpts: any = {
...this.factory.execOpts,
Expand All @@ -33,6 +34,18 @@ export default class CommandBuild extends Command {
await this.exec.command('prisma2 generate', execOpts)
await this.exec.command('tsc', execOpts)

if (flags.devDependencies) {
const pkg = require(join(process.cwd(), 'package.json'))
const ver = this.factory.version ? `#${this.factory.version}` : ''
pkg['devDependencies'] = utils.merge(pkg['devDependencies'], {
[this.factory.id]: `github:fbi-js/${this.factory.id}${ver}`,
fbi: '^4.0.0-alpha.1'
})

await this.fs.writeFile(join(distDir, 'package.json'), JSON.stringify(pkg, null, 2))
await this.fs.copy(join(process.cwd(), '.fbi.config.js'), join(distDir, '.fbi.config.js'))
}

spinner.succeed('build successfully')
}
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import CommandServe from './commands/serve'
import CommandDb from './commands/db'
import CommandGenerate from './commands/generate'
import TemplateGraphql from './templates/graphql'
// @ts-ignore
import { version } from '../package.json'

export default class FactoryNode extends Factory {
id = 'factory-node'
version = version
description = 'factory for node.js application development'
commands = [
new CommandBuild(this),
Expand Down
6 changes: 2 additions & 4 deletions templates/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
"version": "0.0.0",
"description": "<%= project.description %>",
"private": true,
"main": "lib/index.js",
"keywords": [],
"author": "",
"license": "MIT",
"scripts": {
"start": "node dist/server",
"start": "node index",
"dev": "fbi s",
"build": "fbi b"
<%_ if (project.features.prisma) { _%>
,"db:up": "fbi d -u",
"db:down": "fbi d -d",
,"db": "fbi d",
"generate": "fbi g"
<%_ } _%>
},
Expand Down
2 changes: 1 addition & 1 deletion templates/graphql/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"importHelpers": true,
"module": "commonjs",
"rootDir": "src",
"outDir": "lib",
"outDir": "dist",
"strict": true,
"pretty": true,
"target": "es2019",
Expand Down

0 comments on commit 3aa23c1

Please sign in to comment.