Skip to content
Open
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# LIG Interactive Generator

- Last Update : 2021/03/19
- Leatest Version : 0.5.4
- Last Update : 2021/06/04
- Leatest Version : 0.6.3
- Author : LIG inc

## Require

- Node : ^12.18.3
- Node : ^14.16.0
- NPM : ^6.13.4

## Execute latest version
Expand Down
157 changes: 95 additions & 62 deletions lib/interaction.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,117 @@
#!/usr/bin/env node
'use strict';
const inquirer = require('inquirer');
const path = require('path');
const spawn = require('cross-spawn');
const fs = require('fs-extra');
const stable = require('node-latest-stable-version')
const setHusky = require('../util/husky');
"use strict";
const inquirer = require("inquirer");
const path = require("path");
const spawn = require("cross-spawn");
const fs = require("fs-extra");
const stable = require("node-latest-stable-version");
const setHusky = require("../util/husky");
const isFileExist = require("../util/isFileExist");

const TYPES = [
'wordpress',
'static-html',
];
const TYPES = ["wordpress", "static-html"];

const questionType = {
name: 'type',
message: 'Choose Environment Type',
type: 'list',
choices: TYPES
name: "type",
message: "Choose Environment Type",
type: "list",
choices: TYPES,
};

const questionHusky = {
name: 'husky',
message: 'Use husky?',
type: 'list',
choices: [
'yes',
'no'
]
name: "husky",
message: "Use husky?",
type: "list",
choices: ["yes", "no"],
};

const questionNodeVersion = {
name: 'node',
message: 'Type Node Version(Empty will be latest stable version)',
type: 'input',
name: "node",
message: "Type Node Version(Empty will be latest stable version)",
type: "input",
};

const questionName = {
name: 'name',
message: 'Type Project( You can use only a-z0-9 and "-")',
type: 'input',
name: "name",
message: 'Type Project( You can use only a-z0-9 and "-")',
type: "input",
};

module.exports = function (argv) {
process.stdout.write('Current local node version is ' + process.version + "\n")
inquirer.prompt([questionType, questionName, questionNodeVersion, questionHusky]).then((answers) => {
const projectName = (answers.name !== '') ? answers.name : 'new-project';
let projectNode = (answers.node !== '') ? answers.node : 'stable';
process.stdout.write(
"Current local node version is " + process.version + "\n"
);
inquirer
.prompt([questionType, questionName, questionNodeVersion, questionHusky])
.then((answers) => {
const projectName = answers.name !== "" ? answers.name : "new-project";
let projectNode = answers.node !== "" ? answers.node : "stable";

//Create Project Directory
try {
fs.mkdirSync(projectName);
} catch (e) {
console.log("couldn't create '" + projectName + "'");
console.log(e);
process.exit();
}
//Create Project Directory
try {
fs.mkdirSync(projectName);
} catch (e) {
console.log("couldn't create '" + projectName + "'");
console.log(e);
process.exit();
}

const scriptPath = path.join(__dirname, '../script', answers.type + '.js');
const scriptPath = path.join(
__dirname,
"../script",
answers.type + ".js"
);

if (projectNode != "stable") {
CreateEnvironment(scriptPath, projectName, projectNode.replace('/^v/', ''), answers.husky)
} else {
stable.then((version) => {
process.stdout.write('Node version will set to ' + version + "\n")
CreateEnvironment(scriptPath, projectName, version, answers.husky)
})
}
if (projectNode != "stable") {
CreateEnvironment(
scriptPath,
projectName,
projectNode.replace("/^v/", ""),
answers.husky
);
} else {
stable.then((version) => {
process.stdout.write("Node version will set to " + version + "\n");
CreateEnvironment(scriptPath, projectName, version, answers.husky);
});
}
});
};

function CreateEnvironment(scriptPath, projectName, projectNode,husky) {
// childProcess.s
spawn('node', [scriptPath, projectName, projectNode], {
cwd: process.cwd(),
env: process.env,
stdio: 'inherit'
}).on('exit', (code) => {
if (husky === "yes") {
setHusky(path.join(process.cwd(), projectName), path.join(scriptPath,'../../'))
}
process.exit(code);
});
}
function CreateEnvironment(scriptPath, projectName, projectNode, husky) {
// childProcess.s
spawn("node", [scriptPath, projectName, projectNode], {
cwd: process.cwd(),
env: process.env,
stdio: "inherit",
}).on("exit", (code) => {
if (husky === "yes") {
setHusky(
path.join(process.cwd(), projectName),
path.join(scriptPath, "../../")
);
}
const envSamplePath = path.join(process.cwd(), projectName, ".env-sample");
const envPath = path.join(process.cwd(), projectName, ".env");
if (isFileExist(envSamplePath)) {
fs.copySync(envSamplePath, envPath);
}

const packagePath = path.join(process.cwd(), projectName, "package.json");
const pkg = JSON.parse(fs.readFileSync(packagePath, "utf8"))
if ( (Object.keys(pkg).indexOf('author') !== -1)) {
pkg.author = 'LIG inc'
}
if ( (Object.keys(pkg).indexOf('name') !== -1)) {
pkg.name = projectName
}
if ( (Object.keys(pkg).indexOf('description') !== -1)) {
pkg.description = projectName
}
if ( (Object.keys(pkg).indexOf('version') !== -1)) {
pkg.version = '0.0.0'
}
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2))

process.exit(code);
});
}
2 changes: 1 addition & 1 deletion package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "lig-interactive-generator",
"version": "0.5.4",
"description": "- Last Update : 2021/03/19 - Leatest Version : 0.5.4 - Author : LIG inc",
"version": "0.6.3",
"description": "- Last Update : 2021/06/04 - Leatest Version : 0.6.3 - Author : LIG inc",
"main": "index.js",
"engines": {
"node": ">=8.17.0",
"node": ">=14.16.0",
"npm": "^6.13.4"
},
"scripts": {},
Expand Down
Loading