make medusa-dev-cli compatible with yarn 2/3 (#1765)
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const Configstore = require(`configstore`);
|
||||
const pkg = require(`../package.json`);
|
||||
const _ = require(`lodash`);
|
||||
const path = require(`path`);
|
||||
const os = require(`os`);
|
||||
const watch = require(`./watch`);
|
||||
const { getVersionInfo } = require(`./utils/version`);
|
||||
const Configstore = require(`configstore`)
|
||||
const pkg = require(`../package.json`)
|
||||
const _ = require(`lodash`)
|
||||
const path = require(`path`)
|
||||
const os = require(`os`)
|
||||
const watch = require(`./watch`)
|
||||
const { getVersionInfo } = require(`./utils/version`)
|
||||
const argv = require(`yargs`)
|
||||
.usage(`Usage: medusa-dev [options]`)
|
||||
.alias(`q`, `quiet`)
|
||||
@@ -19,7 +19,7 @@ const argv = require(`yargs`)
|
||||
.nargs(`p`, 1)
|
||||
.describe(
|
||||
`p`,
|
||||
`Set path to Medusa repository.
|
||||
`Set path to medusa repository.
|
||||
You typically only need to configure this once.`
|
||||
)
|
||||
.nargs(`force-install`, 0)
|
||||
@@ -27,6 +27,11 @@ You typically only need to configure this once.`
|
||||
`force-install`,
|
||||
`Disables copying files into node_modules and forces usage of local npm repository.`
|
||||
)
|
||||
.nargs(`external-registry`, 0)
|
||||
.describe(
|
||||
`external-registry`,
|
||||
`Run 'yarn add' commands without the --registry flag.`
|
||||
)
|
||||
.alias(`C`, `copy-all`)
|
||||
.nargs(`C`, 0)
|
||||
.describe(
|
||||
@@ -39,87 +44,101 @@ You typically only need to configure this once.`
|
||||
.alias(`h`, `help`)
|
||||
.nargs(`v`, 0)
|
||||
.alias(`v`, `version`)
|
||||
.describe(`v`, `Print the currently installed version of Medusa Dev CLI`)
|
||||
.argv;
|
||||
.describe(`v`, `Print the currently installed version of Medusa Dev CLI`).argv
|
||||
|
||||
if (argv.version) {
|
||||
console.log(getVersionInfo());
|
||||
process.exit();
|
||||
console.log(getVersionInfo())
|
||||
process.exit()
|
||||
}
|
||||
|
||||
const conf = new Configstore(pkg.name);
|
||||
const conf = new Configstore(pkg.name)
|
||||
|
||||
const fs = require(`fs-extra`);
|
||||
const fs = require(`fs-extra`)
|
||||
|
||||
let pathToRepo = argv.setPathToRepo;
|
||||
let pathToRepo = argv.setPathToRepo
|
||||
|
||||
if (pathToRepo) {
|
||||
if (pathToRepo.includes(`~`)) {
|
||||
pathToRepo = path.join(os.homedir(), pathToRepo.split(`~`).pop());
|
||||
pathToRepo = path.join(os.homedir(), pathToRepo.split(`~`).pop())
|
||||
}
|
||||
conf.set(`medusa-location`, path.resolve(pathToRepo));
|
||||
process.exit();
|
||||
conf.set(`medusa-location`, path.resolve(pathToRepo))
|
||||
process.exit()
|
||||
}
|
||||
|
||||
const havePackageJsonFile = fs.existsSync(`package.json`);
|
||||
const havePackageJsonFile = fs.existsSync(`package.json`)
|
||||
|
||||
if (!havePackageJsonFile) {
|
||||
console.error(`Current folder must have a package.json file!`);
|
||||
process.exit();
|
||||
console.error(`Current folder must have a package.json file!`)
|
||||
process.exit()
|
||||
}
|
||||
|
||||
const medusaLocation = conf.get(`medusa-location`);
|
||||
const medusaLocation = conf.get(`medusa-location`)
|
||||
|
||||
if (!medusaLocation) {
|
||||
console.error(
|
||||
`
|
||||
You haven't set the path yet to your cloned
|
||||
version of medusa. Do so now by running:
|
||||
|
||||
medusa-dev --set-path-to-repo /path/to/my/cloned/version/medusa
|
||||
`
|
||||
);
|
||||
process.exit();
|
||||
)
|
||||
process.exit()
|
||||
}
|
||||
|
||||
// get list of packages from monorepo
|
||||
const monoRepoPackages = [];
|
||||
const packageNameToPath = new Map()
|
||||
const monoRepoPackages = fs
|
||||
.readdirSync(path.join(medusaLocation, `packages`))
|
||||
.map((dirName) => {
|
||||
try {
|
||||
const localPkg = JSON.parse(
|
||||
fs.readFileSync(
|
||||
path.join(medusaLocation, `packages`, dirName, `package.json`)
|
||||
)
|
||||
)
|
||||
|
||||
const pkgsDirs = fs.readdirSync(path.join(medusaLocation, `packages`));
|
||||
for (const dir of pkgsDirs) {
|
||||
const pack = JSON.parse(
|
||||
fs.readFileSync(path.join(medusaLocation, `packages`, dir, `package.json`))
|
||||
);
|
||||
monoRepoPackages.push(pack.name);
|
||||
}
|
||||
if (localPkg?.name) {
|
||||
packageNameToPath.set(
|
||||
localPkg.name,
|
||||
path.join(medusaLocation, `packages`, dirName)
|
||||
)
|
||||
return localPkg.name
|
||||
}
|
||||
} catch (error) {
|
||||
// fallback to generic one
|
||||
}
|
||||
|
||||
const localPkg = JSON.parse(fs.readFileSync(`package.json`));
|
||||
packageNameToPath.set(
|
||||
dirName,
|
||||
path.join(medusaLocation, `packages`, dirName)
|
||||
)
|
||||
return dirName
|
||||
})
|
||||
|
||||
const localPkg = JSON.parse(fs.readFileSync(`package.json`))
|
||||
// intersect dependencies with monoRepoPackages to get list of packages that are used
|
||||
const localPackages = _.intersection(
|
||||
monoRepoPackages,
|
||||
Object.keys(_.merge({}, localPkg.dependencies, localPkg.devDependencies))
|
||||
);
|
||||
)
|
||||
|
||||
if (!argv.packages && _.isEmpty(localPackages)) {
|
||||
console.error(
|
||||
`
|
||||
You haven't got any medusa dependencies into your current package.json
|
||||
|
||||
You probably want to pass in a list of packages to start
|
||||
developing on! For example:
|
||||
|
||||
medusa-dev --packages @medusajs/medusa
|
||||
|
||||
medusa-dev --packages medusa medusa-js
|
||||
If you prefer to place them in your package.json dependencies instead,
|
||||
medusa-dev will pick them up.
|
||||
`
|
||||
);
|
||||
)
|
||||
if (!argv.forceInstall) {
|
||||
process.exit();
|
||||
process.exit()
|
||||
} else {
|
||||
console.log(
|
||||
`Continuing other dependencies installation due to "--forceInstall" flag`
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,4 +148,6 @@ watch(medusaLocation, argv.packages, {
|
||||
scanOnce: argv.scanOnce,
|
||||
forceInstall: argv.forceInstall,
|
||||
monoRepoPackages,
|
||||
});
|
||||
packageNameToPath,
|
||||
externalRegistry: argv.externalRegistry,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user