Skip to content

Commit

Permalink
chore: update init script using latest @bndynet/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
bndynet committed Feb 16, 2020
1 parent b4743c1 commit 201113b
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 25 deletions.
240 changes: 237 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.2.2",
"@bndynet/cli": "^1.1.0",
"@bndynet/cli": "^1.2.0",
"@bndynet/typedoc-default-themes": "^0.5.1",
"@commitlint/cli": "^7.1.2",
"@semantic-release/changelog": "^3.0.2",
Expand Down
39 changes: 18 additions & 21 deletions tools/init.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
const path = require('path');
const readline = require('readline');
const { echo, exec } = require('shelljs');
const { readFileSync, writeFileSync } = require('fs');

const cli = require('@bndynet/cli');

cli.info(`
cli.print(cli.styles.info(`
# This utility will walk you through creating a package.json file.
# It only covers the most common items, and tries to guess sensible defaults.
# Use "npm i" to install the default packages.
`);
`));

cli.questions(['Your package name:', 'Your package description:', 'Author name:', 'Author email:', 'Git repository url:']).then((answers: any[]) => {
const pkgName = answers[0];
Expand All @@ -19,7 +15,7 @@ cli.questions(['Your package name:', 'Your package description:', 'Author name:'
const username = answers[2].trim();
const useremail = answers[3].trim();
const repoUrl = answers[4].trim();
const pkgJson = cli.getPackage('../package.json');
const pkgJson = JSON.parse(cli.readFile(path.resolve(__dirname, '..', 'package.json')));

pkgJson.name = pkgName;
pkgJson.description = pkgDescription;
Expand All @@ -33,26 +29,27 @@ cli.questions(['Your package name:', 'Your package description:', 'Author name:'
}
pkgJson.repository.url = repoUrl;

cli.startSection('Generate package.json file');
cli.startSection('init project');

const pkgContent = JSON.stringify(pkgJson, null, 2);
writeFileSync(path.resolve(__dirname, '..', 'package.json'), pkgContent);
cli.print(pkgContent);
cli.success('done', true);
cli.log('generate package.json ...')
cli.writeFile(path.resolve(__dirname, '..', 'package.json'), pkgContent, () => {});
cli.success('done');

cli.startSection('Generate Site');
cli.log('generate project site ...');
const templateIndexFilePath = path.resolve(__dirname, '../_templates', 'index.html');
const indexFilePath = path.resolve(__dirname, '../site', 'index.html');
let siteIndexHtml = readFileSync(templateIndexFilePath, 'utf8');
let siteIndexHtml = cli.readFile(templateIndexFilePath);
siteIndexHtml = siteIndexHtml
.replace(/{{package.name}}/g, pkgJson.name)
.replace(/{{package.subname}}/g, libName)
.replace(/{{package.repository.url}}/g, pkgJson.repository.url);
writeFileSync(indexFilePath, siteIndexHtml, (werr: any) => {
if (werr) {
throw werr;
}
});

cli.startSection('Install dependencies');
cli.run('npm i');
cli.writeFile(indexFilePath, siteIndexHtml, () => {});
cli.success('done');

cli.log('install dependencies ...');
cli.beginRun('npm i', (code: number) => {
code === 0 && cli.success('Your project is ready.')
cli.print('');
});
});

0 comments on commit 201113b

Please sign in to comment.