From 9179feeb17be27a341f6cc1347425cbb7ef80aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=AE=E5=B1=B1=E8=89=AF=E5=A4=AA?= Date: Thu, 3 Jun 2021 15:18:43 +0900 Subject: [PATCH 1/7] Modify readme merge script --- script/wordpress.js | 2 +- util/download.js | 297 ++++++++++++++++++++++++++++---------------- 2 files changed, 190 insertions(+), 109 deletions(-) diff --git a/script/wordpress.js b/script/wordpress.js index edf9fda..d9d466c 100644 --- a/script/wordpress.js +++ b/script/wordpress.js @@ -44,7 +44,7 @@ inquirer.prompt([{ download('https://github.com/liginc/lig-docker-wordpress.git'); }) .then(() => { - download('https://github.com/liginc/laravel-mix-boilerplate-wordpress.git') + download('https://github.com/liginc/laravel-mix-boilerplate-wordpress.git',{mergeReadme:false}) }) .then(() => { if (answer.wordpress_type == 'with theme') { diff --git a/util/download.js b/util/download.js index 6b07c38..d8e6e77 100644 --- a/util/download.js +++ b/util/download.js @@ -1,129 +1,210 @@ -'use strict'; -const path = require('path'); -const childProcess = require('child_process'); -const ora = require('ora'); -const fs = require('fs-extra'); -const promise = require('promise'); +"use strict"; +const path = require("path"); +const childProcess = require("child_process"); +const ora = require("ora"); +const fs = require("fs-extra"); +const promise = require("promise"); -const isFileExist = require('../util/isFileExist.js'); +const isFileExist = require("../util/isFileExist.js"); async function download( - repository, - { - branchName = 'master', - destDir = false, - removeReadme = false, - mergeEnvSample = true - } = {} + repository, + { + branchName = "master", + destDir = false, + mergeReadme = true, + mergeEnvSample = true, + } = {} ) { - const spinner = ora(`[download] ${repository}`).start(); - const result = childProcess.spawnSync('git', ["clone", "--depth", "1", repository, process.argv[2] + "/tmp", "-b", branchName]); - const tmpDir = path.join(process.cwd(), process.argv[2], 'tmp'); - const projectDir = path.join(process.cwd(), process.argv[2]); - const destPath = (destDir === false) ? path.join(projectDir) : path.join(projectDir, destDir); - - if (result.status !== 0) { - process.stderr.write(result.stderr); - process.exit(result.status); - } else { - process.stdout.write(result.stdout); - process.stderr.write(result.stderr); - spinner.succeed(); - - const removeGitFiles = new Promise(function (resolve, reject) { - if (removeReadme) { - try { - const readmePath = path.join(tmpDir, 'README.md'); - fs.removeSync(readmePath); - } catch (e) { - console.log("couldn't remove README.md"); - console.log(e); - } - } + const spinner = ora(`[download] ${repository}`).start(); + const result = childProcess.spawnSync("git", [ + "clone", + "--depth", + "1", + repository, + process.argv[2] + "/tmp", + "-b", + branchName, + ]); + const tmpDir = path.join(process.cwd(), process.argv[2], "tmp"); + const projectDir = path.join(process.cwd(), process.argv[2]); + const destPath = + destDir === false ? path.join(projectDir) : path.join(projectDir, destDir); + + if (result.status !== 0) { + process.stderr.write(result.stderr); + process.exit(result.status); + } else { + process.stdout.write(result.stdout); + process.stderr.write(result.stderr); + spinner.succeed(); + const removeGitFiles = new Promise(function (resolve, reject) { + try { + const dotGitPath = path.join(tmpDir, ".git"); + fs.removeSync(dotGitPath); + } catch (e) { + console.log("couldn't remove .git"); + console.log(e); + } + }); + + const mergeReadmePromise = new Promise(() => { + const readmeSrcPath = path.join(tmpDir, "README.md"); + const readmeDistPath = path.join(projectDir, "README.md"); + + if (isFileExist(readmeSrcPath)) { + if (mergeReadme) { + const readmeText = + fs + .readFileSync(readmeSrcPath, { encoding: "utf-8" }) + .replace(/^[\s\S]*?---/g, "") + "\n\n---\n"; + if (readmeText != "") { try { - const dotGitPath = path.join(tmpDir, '.git'); - fs.removeSync(dotGitPath); + fs.appendFileSync(readmeDistPath, readmeText, function (err) { + if (err) { + throw err; + } + }); } catch (e) { - console.log("couldn't remove .git"); - console.log(e); + console.log("couldn't append text README.md"); + console.log(e); } + } + } + try { + fs.removeSync(readmeSrcPath); + } catch (e) { + console.log("couldn't remove README.md"); + console.log(e); + } + } + }); + + const mergeEnvPromise = new Promise(function () { + const srcPath = path.join(tmpDir, ".env-sample"); + const destPath = path.join(projectDir, ".env-sample"); + const envDestPath = path.join(projectDir, ".env"); + if (!isFileExist(destPath)) { + fs.appendFileSync(destPath, "", function (err) { + if (err) { + throw err; + } }); + } + if (isFileExist(srcPath)) { + const destData = fs.readFileSync(destPath, { encoding: "utf-8" }); + let destDataArr = destData.split(/\r\n|\r|\n/); + const srcData = fs.readFileSync(srcPath, { encoding: "utf-8" }); + let srcDataArr = srcData.split(/\r\n|\r|\n/); - const mergeEnv = new Promise(function () { - const srcPath = path.join(tmpDir, '.env-sample'); - const destPath = path.join(projectDir, '.env-sample'); - const envDestPath = path.join(projectDir, '.env'); - if (!isFileExist(destPath)) { - fs.appendFileSync(destPath, "", function (err) { - if (err) { - throw err; - } - }); - } - if (isFileExist(srcPath)) { - const destData = fs.readFileSync(destPath, {encoding: "utf-8"}); - let destDataArr = destData.split(/\r\n|\r|\n/) - const srcData = fs.readFileSync(srcPath, {encoding: "utf-8"}); - let srcDataArr = srcData.split(/\r\n|\r|\n/) - - if ( !srcDataArr.length ) return - srcDataArr.forEach(data => { - if ( !destDataArr.includes(data) ) { - destDataArr.push(data) - } - }) - fs.removeSync(srcPath); - fs.writeFileSync(destPath,destDataArr.join("\n")) - fs.copyFile(destPath,envDestPath) - } + if (!srcDataArr.length) return; + srcDataArr.forEach((data) => { + if (!destDataArr.includes(data)) { + destDataArr.push(data); + } }); + fs.removeSync(srcPath); + fs.writeFileSync(destPath, destDataArr.join("\n")); + fs.copyFile(destPath, envDestPath); + } + }); - const mergeGitignore = new Promise(function () { - const srcPath = path.join(tmpDir, '.gitignore'); - const destPath = path.join(projectDir, '.gitignore'); - if (!isFileExist(destPath)) { - fs.appendFileSync(destPath, "", function (err) { - if (err) { - throw err; - } - }); - } - if (isFileExist(srcPath)) { - const destData = fs.readFileSync(destPath, {encoding: "utf-8"}); - let destDataArr = destData.split(/\r\n|\r|\n/) - const srcData = fs.readFileSync(srcPath, {encoding: "utf-8"}); - let srcDataArr = srcData.split(/\r\n|\r|\n/) - - if ( !srcDataArr.length ) return - srcDataArr.forEach(data => { - if ( !destDataArr.includes(data) ) { - destDataArr.push(data) - } - }) - fs.removeSync(srcPath); - fs.writeFileSync(destPath,destDataArr.join("\n")) - } + const mergeGitignorePromise = new Promise(function () { + const srcPath = path.join(tmpDir, ".gitignore"); + const destPath = path.join(projectDir, ".gitignore"); + if (!isFileExist(destPath)) { + fs.appendFileSync(destPath, "", function (err) { + if (err) { + throw err; + } }); + } + if (isFileExist(srcPath)) { + const destData = fs.readFileSync(destPath, { encoding: "utf-8" }); + let destDataArr = destData.split(/\r\n|\r|\n/); + const srcData = fs.readFileSync(srcPath, { encoding: "utf-8" }); + let srcDataArr = srcData.split(/\r\n|\r|\n/); - const moveFiles = new Promise(function (resolve, reject) { - if (destDir !== false) { - fs.mkdirsSync(destPath); - } - fs.copySync(tmpDir, destPath); - fs.removeSync(tmpDir); + if (!srcDataArr.length) return; + srcDataArr.forEach((data) => { + if (!destDataArr.includes(data)) { + destDataArr.push(data); + } }); + fs.removeSync(srcPath); + fs.writeFileSync(destPath, destDataArr.join("\n")); + } + }); + + const appendPackagePromise = new Promise(function (resolve, reject) { + const appendPackageDir = path.join(tmpDir, "append_package"); + if (!isFileExist(appendPackageDir)) return resolve(); - const afterClone = new Promise(function (resolve, reject) { - if (fs.existsSync(path.join(destPath, 'after_clone.sh'))) { - childProcess.execSync('$SHELL ' + path.join(destPath, 'after_clone.sh') + ' ' + destPath) - fs.removeSync(path.join(destPath, 'after_clone.sh')) + const packageDestPath = path.join(destPath, "package.json"); + const packageSrcPath = path.join(appendPackageDir, "package.json") + if (isFileExist(packageDestPath) && isFileExist(packageSrcPath)) { + const pkg = JSON.parse(fs.readFileSync(packageDestPath, 'utf8')) + const appendPkg = JSON.parse(fs.readFileSync(packageSrcPath, "utf8")) + if ( (Object.keys(pkg).indexOf('dependencies') === -1)) { + pkg.dependencies = {} + } + for (let k of Object.keys(appendPkg.dependencies)) { + if (!(k in pkg.dependencies)) { + pkg.dependencies[k] = appendPkg.dependencies[k]; + } + } + fs.writeFileSync(packageDestPath, JSON.stringify(pkg, null, 2)) + ora(`Update package.json`).succeed() + } + + const packageLockDestPath = path.join(destPath, "package-lock.json"); + const packageLockSrcPath = path.join(appendPackageDir, "package-lock.json") + if (isFileExist(packageLockDestPath) && isFileExist(packageLockSrcPath)) { + const pkgLock = JSON.parse(fs.readFileSync(packageLockDestPath, 'utf8')) + const appendLockPkg = JSON.parse(fs.readFileSync(packageLockSrcPath, "utf8")) + if ( (Object.keys(pkgLock).indexOf('dependencies') === -1)) { + pkgLock.dependencies = {} + } + for (let k of Object.keys(appendLockPkg.dependencies)) { + // package-lock.jsonはバージョン比較をする + if (!(k in pkgLock.dependencies) || pkgLock.dependencies[k]['version'] < appendLockPkg.dependencies[k]['version']) { + pkgLock.dependencies[k] = appendLockPkg.dependencies[k] } - }); + } + fs.writeFileSync(packageLockDestPath, JSON.stringify(pkgLock, null, 2)) + ora(`Update package-lock.json`).succeed() + } + + fs.removeSync(appendPackageDir) + }); + + const moveFilesPromise = new Promise(function (resolve, reject) { + if (destDir !== false) { + fs.mkdirsSync(destPath); + } + fs.copySync(tmpDir, destPath); + fs.removeSync(tmpDir); + }); + + const afterClonePromise = new Promise(function (resolve, reject) { + if (fs.existsSync(path.join(destPath, "after_clone.sh"))) { + childProcess.execSync( + "$SHELL " + path.join(destPath, "after_clone.sh") + " " + destPath + ); + fs.removeSync(path.join(destPath, "after_clone.sh")); + } + }); - removeGitFiles.then(mergeEnv).then(mergeGitignore).then(moveFiles).then(afterClone); - return await destPath - } + removeGitFiles + .then(mergeEnvPromise) + .then(mergeReadmePromise) + .then(mergeGitignorePromise) + .then(appendPackagePromise) + .then(moveFilesPromise) + .then(afterClonePromise); + return await destPath; + } } module.exports = download; From aa2fabedf815f77c978f8e7d60a8fd4ab65e405c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=AE=E5=B1=B1=E8=89=AF=E5=A4=AA?= Date: Thu, 3 Jun 2021 18:37:32 +0900 Subject: [PATCH 2/7] Modify env copy function --- lib/interaction.js | 140 +++++++++++++++++++++++++-------------------- util/download.js | 2 - 2 files changed, 78 insertions(+), 64 deletions(-) diff --git a/lib/interaction.js b/lib/interaction.js index 393d182..e099035 100755 --- a/lib/interaction.js +++ b/lib/interaction.js @@ -1,84 +1,100 @@ #!/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); - }); -} \ No newline at end of file +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); + } + process.exit(code); + }); +} diff --git a/util/download.js b/util/download.js index d8e6e77..46d1599 100644 --- a/util/download.js +++ b/util/download.js @@ -84,7 +84,6 @@ async function download( const mergeEnvPromise = new Promise(function () { const srcPath = path.join(tmpDir, ".env-sample"); const destPath = path.join(projectDir, ".env-sample"); - const envDestPath = path.join(projectDir, ".env"); if (!isFileExist(destPath)) { fs.appendFileSync(destPath, "", function (err) { if (err) { @@ -106,7 +105,6 @@ async function download( }); fs.removeSync(srcPath); fs.writeFileSync(destPath, destDataArr.join("\n")); - fs.copyFile(destPath, envDestPath); } }); From 76479c2a032f35a5aece02176eebffd049032aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=AE=E5=B1=B1=E8=89=AF=E5=A4=AA?= Date: Fri, 4 Jun 2021 07:32:50 +0900 Subject: [PATCH 3/7] Update version --- README.md | 6 +++--- package-lock.json | 2 +- package.json | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fe16bfe..06e43de 100644 --- a/README.md +++ b/README.md @@ -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.0 - Author : LIG inc ## Require -- Node : ^12.18.3 +- Node : ^14.16.0 - NPM : ^6.13.4 ## Execute latest version diff --git a/package-lock.json b/package-lock.json index 3affced..67c8bc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "lig-interactive-generator", - "version": "0.5.1", + "version": "0.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a0f1462..85107d1 100755 --- a/package.json +++ b/package.json @@ -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.0", + "description": "- Last Update : 2021/06/04 - Leatest Version : 0.6.0 - Author : LIG inc", "main": "index.js", "engines": { - "node": ">=8.17.0", + "node": ">=14.16.0", "npm": "^6.13.4" }, "scripts": {}, From f6a6f66cea37457b03167fc0f0ac809728b830ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=AE=E5=B1=B1=E8=89=AF=E5=A4=AA?= Date: Fri, 4 Jun 2021 09:43:07 +0900 Subject: [PATCH 4/7] Include webpackmix replacer --- lib/interaction.js | 17 +++ script/wordpress.js | 288 ++++++++++++++++++++++++++++++-------------- util/download.js | 22 ++-- 3 files changed, 224 insertions(+), 103 deletions(-) diff --git a/lib/interaction.js b/lib/interaction.js index e099035..0966354 100755 --- a/lib/interaction.js +++ b/lib/interaction.js @@ -95,6 +95,23 @@ function CreateEnvironment(scriptPath, projectName, projectNode, husky) { 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); }); } diff --git a/script/wordpress.js b/script/wordpress.js index d9d466c..a963723 100644 --- a/script/wordpress.js +++ b/script/wordpress.js @@ -1,109 +1,215 @@ #!/usr/bin/env node -'use strict'; -const promise = require('promise'); -const childProcess = require('child_process'); -const inquirer = require('inquirer'); -const fs = require('fs-extra'); -const path = require('path'); -const ora = require('ora'); +"use strict"; +const promise = require("promise"); +const childProcess = require("child_process"); +const inquirer = require("inquirer"); +const fs = require("fs-extra"); +const path = require("path"); +const ora = require("ora"); -const download = require('../util/download'); +const download = require("../util/download"); const preparing = ora(`[preparing]`); const scriptPath = process.argv[1]; const projectName = process.argv[2]; const rootDir = path.join(process.cwd(), projectName); -const pkgPath = path.join(rootDir, 'package.json') +const pkgPath = path.join(rootDir, "package.json"); const nodeVersion = process.argv[3]; const env = path.join(rootDir, ".env-sample"); const webpackMixJs = path.join(rootDir, "webpack.mix.js"); -inquirer.prompt([{ - name: 'wordpress_ver', - message: 'Type WordPress version (Empty will be "latest")', - type: 'input', -}, { - name: 'wordpress_type', - message: 'Choose WP including file type', - type: 'list', - choices: ['with theme', 'only functions'] -}, { - name: 'php_ver', - message: 'Choose PHP version', - type: 'list', - choices: ['8.0', '7.4','7.3'] -}, { - name: 'mysql_ver', - message: 'Choose MySQL version', - type: 'list', - choices: ['8.0', '5.7','5.6'] -}]).then((answer) => { +inquirer + .prompt([ + { + name: "wordpress_ver", + message: 'Type WordPress version (Empty will be "latest")', + type: "input", + }, + { + name: "wordpress_type", + message: "Choose WP including file type", + type: "list", + choices: ["with theme", "only functions"], + }, + { + name: "php_ver", + message: "Choose PHP version", + type: "list", + choices: ["8.0", "7.4", "7.3"], + }, + { + name: "mysql_ver", + message: "Choose MySQL version", + type: "list", + choices: ["8.0", "5.7", "5.6"], + }, + ]) + .then((answer) => { const thePromise = Promise.resolve(); thePromise - .then(() => { - download('https://github.com/liginc/lig-docker-wordpress.git'); - }) - .then(() => { - download('https://github.com/liginc/laravel-mix-boilerplate-wordpress.git',{mergeReadme:false}) - }) - .then(() => { - if (answer.wordpress_type == 'with theme') { - fs.removeSync(path.join(rootDir, "resources")) - fs.removeSync(path.join(rootDir, "wp/wp-content/themes/input-theme-name")) - download('https://github.com/liginc/lig-wordpress-template.git').then(() => { - fs.renameSync(path.join(rootDir, 'wp/wp-content/themes/lig-wordpress-template'), path.join(rootDir, 'wp/wp-content/themes', projectName)); - fs.renameSync(path.join(rootDir, 'resources/themes/lig-wordpress-template'), path.join(rootDir, 'resources/themes', projectName)); - }).then(()=>{ - download('https://github.com/liginc/lig-wordpress-functions.git', { - destDir: 'wp/wp-content/themes/' + projectName, - }); - }); - } else { - fs.renameSync(path.join(rootDir, 'wp/wp-content/themes/input-theme-name'), path.join(rootDir, 'wp/wp-content/themes', projectName)); - fs.renameSync(path.join(rootDir, 'resources/themes/input-theme-name'), path.join(rootDir, 'resources/themes', projectName)); - download('https://github.com/liginc/lig-wordpress-functions.git', { - destDir: 'wp/wp-content/themes/' + projectName, - }); - } - }) - .then(() => { - preparing.start(); + .then(() => { + download("https://github.com/liginc/lig-docker-wordpress.git"); + }) + .then(() => { + download( + "https://github.com/liginc/laravel-mix-boilerplate-wordpress.git", + { mergeReadme: false } + ); + }) + .then(() => { + if (answer.wordpress_type == "with theme") { + fs.removeSync(path.join(rootDir, "resources")); + fs.removeSync( + path.join(rootDir, "wp/wp-content/themes/input-theme-name") + ); + download("https://github.com/liginc/lig-wordpress-template.git") + .then(() => { + fs.renameSync( + path.join( + rootDir, + "wp/wp-content/themes/lig-wordpress-template" + ), + path.join(rootDir, "wp/wp-content/themes", projectName) + ); + fs.renameSync( + path.join(rootDir, "resources/themes/lig-wordpress-template"), + path.join(rootDir, "resources/themes", projectName) + ); + }) + .then(() => { + download( + "https://github.com/liginc/lig-wordpress-functions.git", + { + destDir: "wp/wp-content/themes/" + projectName, + } + ); + }); + } else { + fs.renameSync( + path.join(rootDir, "wp/wp-content/themes/input-theme-name"), + path.join(rootDir, "wp/wp-content/themes", projectName) + ); + fs.renameSync( + path.join(rootDir, "resources/themes/input-theme-name"), + path.join(rootDir, "resources/themes", projectName) + ); + download("https://github.com/liginc/lig-wordpress-functions.git", { + destDir: "wp/wp-content/themes/" + projectName, + }); + } + }) + .then(() => { + preparing.start(); - // Replace text on .env - childProcess.spawnSync('sed', ["-i", "", "-e", "s|PHP_VER=.*$|PHP_VER=" + answer.php_ver + "|g", env]); - childProcess.spawnSync('sed', ["-i", "", "-e", "s|MYSQL_VER=.*$|MYSQL_VER=" + answer.mysql_ver + "|g", env]); - if (answer.wordpress_ver !== '') { - childProcess.spawnSync('sed', ["-i", "", "-e", "s|WP_VERSION=.*$|WP_VERSION=" + answer.wordpress_ver + "|g", env]); - } else { - const wpLatestVersion = childProcess.spawnSync('git', ["ls-remote", "--tags", "--refs", "--sort='v:refname'", "https://github.com/WordPress/WordPress", "|", "tail", "-n1", "|","sed", "'s/.*\\///'"],{ - shell: true - }); - childProcess.spawnSync('sed', ["-i", "", "-e", "s|WP_VERSION=.*$|WP_VERSION=" + wpLatestVersion.stdout.toString().replace(/\r?\n/g,"") + "|g", env]).stderr.toString(); - process.stdout.write('WP version will set to ' + wpLatestVersion.stdout.toString() + "\n") + // Replace text on .env + childProcess.spawnSync("sed", [ + "-i", + "", + "-e", + "s|PHP_VER=.*$|PHP_VER=" + answer.php_ver + "|g", + env, + ]); + childProcess.spawnSync("sed", [ + "-i", + "", + "-e", + "s|MYSQL_VER=.*$|MYSQL_VER=" + answer.mysql_ver + "|g", + env, + ]); + if (answer.wordpress_ver !== "") { + childProcess.spawnSync("sed", [ + "-i", + "", + "-e", + "s|WP_VERSION=.*$|WP_VERSION=" + answer.wordpress_ver + "|g", + env, + ]); + } else { + const wpLatestVersion = childProcess.spawnSync( + "git", + [ + "ls-remote", + "--tags", + "--refs", + "--sort='v:refname'", + "https://github.com/WordPress/WordPress", + "|", + "tail", + "-n1", + "|", + "sed", + "'s/.*\\///'", + ], + { + shell: true, } + ); + childProcess + .spawnSync("sed", [ + "-i", + "", + "-e", + "s|WP_VERSION=.*$|WP_VERSION=" + + wpLatestVersion.stdout.toString().replace(/\r?\n/g, "") + + "|g", + env, + ]) + .stderr.toString(); + process.stdout.write( + "WP version will set to " + wpLatestVersion.stdout.toString() + "\n" + ); + } - childProcess.spawnSync('sed', ["-i", "", "-e", "s|WP_THEME_NAME=.*$|WP_THEME_NAME=" + projectName + "|g", env]); - childProcess.spawnSync('sed', ["-i", "", "-e", "s|input-theme-name|" + projectName + "|g", env]); - childProcess.spawnSync('sed', ["-i", "", "-e", "s|wordpress.test|localhost|g", env]); + childProcess.spawnSync("sed", [ + "-i", + "", + "-e", + "s|WP_THEME_NAME=.*$|WP_THEME_NAME=" + projectName + "|g", + env, + ]); + childProcess.spawnSync("sed", [ + "-i", + "", + "-e", + "s|input-theme-name|" + projectName + "|g", + env, + ]); + childProcess.spawnSync("sed", [ + "-i", + "", + "-e", + "s|wordpress.test|localhost|g", + env, + ]); - fs.readFile(webpackMixJs, 'utf8', function (err,data) { - if (err) { - return console.log(err); - } - data = data.replace(/(const srcRelativePath =).+?\((.+?)\s.+?.replace\(.+?\)/s, '$1 $2;'); - data = data.replace(/(const distRelativePath =).+?\((.+?)\s.+?.replace\(.+?\)/s, '$1 $2;'); - fs.writeFile(webpackMixJs, data, 'utf8', function (err) { - if (err) return console.log(err); - }); - }); + fs.readFile(webpackMixJs, "utf8", function (err, data) { + if (err) { + return console.log(err); + } + data = data.replace( + /(const srcRelativePath =).+?\((.+?)\s.+?.replace\(.+?\)/s, + "$1 $2;" + ); + data = data.replace( + /(const distRelativePath =).+?\((.+?)\s.+?.replace\(.+?\)/s, + "$1 $2;" + ); + data = data.replace( + /(^\s+?\.sass\($)/m, + " .webpackConfig(\n module: \n rules: [\n test: /\\\.scss/,\n enforce: 'pre',\n loader: 'import-glob-loader'\n }]\n }\n })\n$1" + ); + fs.writeFile(webpackMixJs, data, "utf8", function (err) { + if (err) return console.log(err); + }); + }); - preparing.succeed(); - }) - .then(() => { - let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) - pkg.engineStrict = true - pkg.engines.node = nodeVersion - fs.writeFileSync(pkgPath, JSON.stringify(pkg,null,2)); - process.stdout.write("Set node version into package.json \n") - }) -}); + preparing.succeed(); + }) + .then(() => { + let pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")); + pkg.engineStrict = true; + pkg.engines.node = nodeVersion; + fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)); + process.stdout.write("Set node version into package.json \n"); + }); + }); diff --git a/util/download.js b/util/download.js index 46d1599..8db84e3 100644 --- a/util/download.js +++ b/util/download.js @@ -39,7 +39,7 @@ async function download( process.stderr.write(result.stderr); spinner.succeed(); - const removeGitFiles = new Promise(function (resolve, reject) { + const removeGitFilesPromise = new Promise(function (resolve, reject) { try { const dotGitPath = path.join(tmpDir, ".git"); fs.removeSync(dotGitPath); @@ -152,6 +152,14 @@ async function download( pkg.dependencies[k] = appendPkg.dependencies[k]; } } + if ( (Object.keys(pkg).indexOf('devDependencies') === -1)) { + pkg.devDependencies = {} + } + for (let k of Object.keys(appendPkg.devDependencies)) { + if (!(k in pkg.devDependencies)) { + pkg.devDependencies[k] = appendPkg.devDependencies[k]; + } + } fs.writeFileSync(packageDestPath, JSON.stringify(pkg, null, 2)) ora(`Update package.json`).succeed() } @@ -185,22 +193,12 @@ async function download( fs.removeSync(tmpDir); }); - const afterClonePromise = new Promise(function (resolve, reject) { - if (fs.existsSync(path.join(destPath, "after_clone.sh"))) { - childProcess.execSync( - "$SHELL " + path.join(destPath, "after_clone.sh") + " " + destPath - ); - fs.removeSync(path.join(destPath, "after_clone.sh")); - } - }); - - removeGitFiles + removeGitFilesPromise .then(mergeEnvPromise) .then(mergeReadmePromise) .then(mergeGitignorePromise) .then(appendPackagePromise) .then(moveFilesPromise) - .then(afterClonePromise); return await destPath; } } From 538a2416b1fe663d1105c131ad924b7b1e16d73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=AE=E5=B1=B1=E8=89=AF=E5=A4=AA?= Date: Fri, 4 Jun 2021 09:43:59 +0900 Subject: [PATCH 5/7] Update version --- README.md | 2 +- package-lock.json | 2 +- package.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 06e43de..90d6471 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LIG Interactive Generator - Last Update : 2021/06/04 -- Leatest Version : 0.6.0 +- Leatest Version : 0.6.1 - Author : LIG inc ## Require diff --git a/package-lock.json b/package-lock.json index 67c8bc7..c41ac9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "lig-interactive-generator", - "version": "0.6.0", + "version": "0.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 85107d1..31dd7b7 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lig-interactive-generator", - "version": "0.6.0", - "description": "- Last Update : 2021/06/04 - Leatest Version : 0.6.0 - Author : LIG inc", + "version": "0.6.1", + "description": "- Last Update : 2021/06/04 - Leatest Version : 0.6.1 - Author : LIG inc", "main": "index.js", "engines": { "node": ">=14.16.0", From d124962c02c5a7753af22d9ab81af2a43a086a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=AE=E5=B1=B1=E8=89=AF=E5=A4=AA?= Date: Fri, 4 Jun 2021 10:25:11 +0900 Subject: [PATCH 6/7] Update version --- README.md | 2 +- package-lock.json | 2 +- package.json | 4 ++-- script/wordpress.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 90d6471..1e44674 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LIG Interactive Generator - Last Update : 2021/06/04 -- Leatest Version : 0.6.1 +- Leatest Version : 0.6.2 - Author : LIG inc ## Require diff --git a/package-lock.json b/package-lock.json index c41ac9a..1a8b223 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "lig-interactive-generator", - "version": "0.6.1", + "version": "0.6.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 31dd7b7..ad7bb1d 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lig-interactive-generator", - "version": "0.6.1", - "description": "- Last Update : 2021/06/04 - Leatest Version : 0.6.1 - Author : LIG inc", + "version": "0.6.2", + "description": "- Last Update : 2021/06/04 - Leatest Version : 0.6.2 - Author : LIG inc", "main": "index.js", "engines": { "node": ">=14.16.0", diff --git a/script/wordpress.js b/script/wordpress.js index a963723..d17f94f 100644 --- a/script/wordpress.js +++ b/script/wordpress.js @@ -196,7 +196,7 @@ inquirer ); data = data.replace( /(^\s+?\.sass\($)/m, - " .webpackConfig(\n module: \n rules: [\n test: /\\\.scss/,\n enforce: 'pre',\n loader: 'import-glob-loader'\n }]\n }\n })\n$1" + " .webpackConfig({\n module: {\n rules: [{\n test: /\\\.scss/,\n enforce: 'pre',\n loader: 'import-glob-loader'\n }]\n }\n })\n$1" ); fs.writeFile(webpackMixJs, data, "utf8", function (err) { if (err) return console.log(err); From caaa56383a143d2f4175164fdf40a72dd608a4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=AE=E5=B1=B1=E8=89=AF=E5=A4=AA?= Date: Fri, 4 Jun 2021 10:59:19 +0900 Subject: [PATCH 7/7] Add gitignore replace function --- README.md | 2 +- package-lock.json | 2 +- package.json | 4 ++-- script/wordpress.js | 8 ++++++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1e44674..42bee0e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LIG Interactive Generator - Last Update : 2021/06/04 -- Leatest Version : 0.6.2 +- Leatest Version : 0.6.3 - Author : LIG inc ## Require diff --git a/package-lock.json b/package-lock.json index 1a8b223..05f6f30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "lig-interactive-generator", - "version": "0.6.2", + "version": "0.6.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ad7bb1d..9515d17 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lig-interactive-generator", - "version": "0.6.2", - "description": "- Last Update : 2021/06/04 - Leatest Version : 0.6.2 - 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": ">=14.16.0", diff --git a/script/wordpress.js b/script/wordpress.js index d17f94f..a8d024d 100644 --- a/script/wordpress.js +++ b/script/wordpress.js @@ -16,6 +16,7 @@ const rootDir = path.join(process.cwd(), projectName); const pkgPath = path.join(rootDir, "package.json"); const nodeVersion = process.argv[3]; const env = path.join(rootDir, ".env-sample"); +const gitIgnore = path.join(rootDir, ".gitignore"); const webpackMixJs = path.join(rootDir, "webpack.mix.js"); inquirer @@ -174,6 +175,13 @@ inquirer "s|input-theme-name|" + projectName + "|g", env, ]); + childProcess.spawnSync("sed", [ + "-i", + "", + "-e", + "s|lig-wordpress-template|" + projectName + "|g", + gitIgnore, + ]); childProcess.spawnSync("sed", [ "-i", "",