-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support kinetic #90
Open
vanpho93
wants to merge
4
commits into
trunk
Choose a base branch
from
feat/support-kinetic
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mystore/* | ||
myadmin/* | ||
myshop/* | ||
mykinetic/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
.env | ||
.vscode | ||
node_modules | ||
mydir | ||
myadmin | ||
mystore | ||
mykinetic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { writeFile, readFile } from "fs/promises"; | ||
import simpleGit from "simple-git"; | ||
import { copy } from "fs-extra"; | ||
import Logger from "../utils/logger.js"; | ||
|
||
/** | ||
* @summary modify package.json for use as a thin development project | ||
* @param {String} packageJson - The contents of package.json | ||
* @param {String} projectName - The name of the project | ||
* @returns {String} The modified contents | ||
*/ | ||
function updatePackageJson(packageJson, projectName) { | ||
const packageData = JSON.parse(packageJson); | ||
packageData.name = projectName; | ||
packageData.version = "1.0.0"; | ||
packageData.projectType = "kinetic"; | ||
return JSON.stringify(packageData, null, 2); | ||
} | ||
|
||
/** | ||
* @summary Update the core file for this project | ||
* @param {String} projectName - The name of the project we are creating | ||
* @returns {Promise<Boolean>} True if success | ||
*/ | ||
async function updateCoreFile(projectName) { | ||
const packageJsonPath = `${projectName}/package.json`; | ||
const packageJson = await readFile(packageJsonPath, { encoding: "utf8", flag: "r" }); | ||
const updatedPackageJson = updatePackageJson(packageJson, projectName); | ||
await writeFile(packageJsonPath, updatedPackageJson); | ||
return true; | ||
} | ||
|
||
/** | ||
* @summary clones projects locally from repo | ||
* @param {String} projectName name of the project to create | ||
* @returns {Boolean} true for success | ||
*/ | ||
export default async function createProjectKinetic(projectName) { | ||
Logger.info("Creating kinetic", { projectName }); | ||
const gitOptions = { | ||
baseDir: `${process.cwd()}`, | ||
binary: "git", | ||
maxConcurrentProcesses: 6 | ||
}; | ||
const git = simpleGit(gitOptions); | ||
Logger.info("Cloning project"); | ||
try { | ||
await git.clone("[email protected]:reactioncommerce/kinetic.git", projectName); | ||
} catch (error) { | ||
Logger.error(error); | ||
return false; | ||
} | ||
await updateCoreFile(projectName); | ||
await copy(`${projectName}/.env.example`, `${projectName}/.env`); | ||
Logger.success("Kinetic project created. You can change to this directory and run `pnpm install`"); | ||
return true; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { spawn } from "child_process"; | ||
import diehard from "diehard"; | ||
import Logger from "../utils/logger.js"; | ||
import checkBeforeDevelop from "../utils/checkBeforeDevelop.js"; | ||
|
||
/** | ||
* @summary start develop mode for kinetic | ||
* @param {Object} options - Any options for project creation | ||
* @returns {Boolean} true for success | ||
*/ | ||
export default async function developKinetic(options) { | ||
if (!await checkBeforeDevelop("kinetic")) return; | ||
Logger.info("Starting Open Commerce Kinetic Application Server in dev mode", { options }); | ||
const api = spawn("pnpm", ["run", "dev"]); | ||
api.stdout.on("data", (data) => { | ||
// eslint-disable-next-line no-console | ||
console.log(data.toString().trim()); // Echo output of command to console | ||
}); | ||
|
||
api.stderr.on("data", (data) => { | ||
// eslint-disable-next-line no-console | ||
console.log(data.toString().trim()); // Echo error output | ||
}); | ||
|
||
diehard.register(async (signal, uncaughtErr, done) => { | ||
if (signal === "SIGINT") { | ||
Logger.warn("Shutting down from Ctrl-C"); | ||
} | ||
done(); | ||
}); | ||
|
||
diehard.listen(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable jest/valid-expect */ | ||
import { EOL } from "os"; | ||
import { spawn } from "child_process"; | ||
import rimraf from "rimraf"; | ||
import { expect } from "chai"; | ||
import { sync as cmdExists } from "command-exists"; | ||
import getConfig from "../utils/getConfig.js"; | ||
import execute from "./utils/execute.js"; | ||
|
||
const config = getConfig(); | ||
|
||
beforeEach(async () => { | ||
await rimraf.sync("./mykinetic"); | ||
// Mock that we have alredy used the command to bypass telemetry logs | ||
config.set("runOnce", true); | ||
if (!cmdExists("pnpm")) { | ||
spawn("npm", ["install", "pnpm", "-g"]); | ||
} | ||
}); | ||
|
||
describe("The create-project-kinetic command", () => { | ||
it("should print the correct output", async () => { | ||
const response = await execute("./index.js", ["create-project", "kinetic", "mykinetic"]); | ||
const responseLines = response.trim().split(EOL); | ||
// eslint-disable-next-line jest/valid-expect | ||
expect(responseLines[0]).to.equal('reaction-cli: Creating kinetic: {"projectName":"mykinetic"}'); | ||
}).timeout(350000); // cloning the admin takes a long time | ||
}); | ||
|
||
afterEach(async () => { | ||
config.set("runOnce", false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably drop the "the" here. It's just Kinetic