Skip to content
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

[Minor] [Feature] added xarc path as cwd in packages #1760

Merged
merged 39 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
06164d4
[PATCH] Bug fix for reading xarcOptions while populating legacy
Nov 17, 2020
61fc9bd
[PATCH] Bug fix for reading xarcOptions
Nov 17, 2020
9a8e225
[Patch][Bug] fix for reading xarcOptions
Nov 17, 2020
4122def
[Patch][Bug] fixed linting issue
Nov 17, 2020
1bf5100
[Patch][Bug] merging xarcOption to user
Nov 17, 2020
272a3c8
[MINOR][FEATURE] added xarc path as cwd in packages
Nov 19, 2020
430ccc3
Merge branch 'master' into master
durrab Nov 19, 2020
fb7e3f0
[MINOR][FEATURE] fixed linting issues
Nov 19, 2020
338b18a
Merge branch 'master' of https://github.com/durrab/electrode
Nov 19, 2020
17ab841
[MINOR][FEATURE] fixed linting dll-output.ts
Nov 19, 2020
a6ef18c
[MINOR][FEATURE] fixed cachedarchrType for xarc cwd
Nov 19, 2020
f4b364e
[MINOR][FEATURE] added required instead of import
Nov 19, 2020
9807a63
[MINOR][FEATURE] added cwd in xarcOptions and fixed process.env.XARC_…
Nov 20, 2020
d0e35e3
[MINOR][FEATURE] fixed linting issue for dll-output.ts
Nov 20, 2020
64c3b98
[MINOR][FEATURE] removed console.log
Nov 20, 2020
7952c49
[MINOR][FEATURE] merged cwd in legacy and fixed dev-task linting
Nov 20, 2020
3147baf
[MINOR][FEATURE] fixed and refactored xarcPath to xarcCwd
Nov 20, 2020
715a8df
[MINOR][FEATURE] fixes
Nov 20, 2020
f12f1b7
[MINOR][FEATURE] refactored and removed detectXARCPath
Nov 20, 2020
8928a0a
[MINOR][FEATURE] loadDevOption fixes
Nov 20, 2020
152da31
[MINOR][FEATURE] fix for options.ts if xarcOptions.cwd is undefined t…
Nov 21, 2020
87d97b3
[MINOR][FEATURE] fix clap dev error for xarcOptions.json file
Nov 23, 2020
a6a3cbb
[MINOR][FEATURE] changed comment for xarc-options.ts for cwd
Nov 23, 2020
c96a924
[MINOR][FEATURE] fixed linting issues
Nov 23, 2020
42be114
[MINOR][FEATURE] removed process.cwd() and using cwd from top
Nov 23, 2020
eeb3fe4
[MINOR][FEATURE] unformatted create-app.spec
Nov 23, 2020
3da58ac
[MINOR][FEATURE] fixed linting formatting
Nov 23, 2020
983602a
[MINOR][FEATURE] fixed dir param with default values
Nov 23, 2020
96cac34
[MINOR][FEATURE] removed changes for get-dev-proxy.ts
Nov 23, 2020
1b008a6
[MINOR][FEATURE] fixed params for both utils.ts and load-xarc-options.ts
Nov 24, 2020
895eda5
[MINOR][FEATURE] comment for cwd in xarc-options.ts
Nov 24, 2020
af7043d
[MINOR][FEATURE] added for get-dev-proxy as xarc-cwd
Nov 24, 2020
232e09d
[MINOR][FEATURE] removed legacy.cwd
Nov 24, 2020
ff170f6
[MINOR][FEATURE] fixed archetype required for multiple methods
Nov 24, 2020
302e69b
[MINOR][FEATURE] fixed linting and spacing issues
Nov 24, 2020
f5ff8fa
[MINOR][FEATURE] fixed options.rootDir = options.rootDir || Path.reso…
Nov 24, 2020
178f6fa
[MINOR][FEATURE] fixed linting for module-processor.ts
Nov 24, 2020
b8c33fd
[MINOR][FEATURE] added new line at the end
Nov 24, 2020
fe2c537
[MINOR][FEATURE] refactored babel.ts
Nov 24, 2020
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
5 changes: 5 additions & 0 deletions packages/xarc-app-dev/src/config/archetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ module.exports = function getDevOptions(user: XarcOptions = {}) {
addOnFeatures: undefined
});

//added XARC CMD option
if (!_.isNil(user) && !_.isNil(user.XARC_CWD)) {
legacy.options.XARC_CWD = user.XARC_CWD;
}

saveXarcOptions(legacy);

cachedArchetype = legacy;
Expand Down
7 changes: 5 additions & 2 deletions packages/xarc-app-dev/src/config/get-dev-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ const Path = require("path");
const Fs = require("fs");

let cachedProxy = null;
import { loadXarcOptions, detectXARCPath } from "../lib/utils"

module.exports = function createDevProxy() {
const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);
if (cachedProxy) {
return cachedProxy;
}
Expand Down Expand Up @@ -65,8 +68,8 @@ module.exports = function createDevProxy() {

const searchDirs = ["", "config", "test", "src"];
for (const f of searchDirs) {
const key = Path.resolve(f, "dev-proxy.key");
const cert = Path.resolve(f, "dev-proxy.crt");
const key = Path.resolve(xarcPath, f, "dev-proxy.key");
const cert = Path.resolve(xarcPath, f, "dev-proxy.crt");
if (Fs.existsSync(key) && Fs.existsSync(cert)) {
return { key, cert };
}
Expand Down
5 changes: 3 additions & 2 deletions packages/xarc-app-dev/src/config/jest/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ const optRequire = getOptArchetypeRequire(["@xarc/opt-jest", "electrode-archetyp
const jestPkg = optRequire("jest/package.json");
const jestMajVersion = parseInt(jestPkg.version.split(".")[0], 10);

import { loadXarcOptions } from "../../lib/utils";
import { loadXarcOptions, detectXARCPath } from "../../lib/utils";

const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);

const { enableTypeScript } = xarcOptions.babel;

// https://jestjs.io/docs/en/configuration.html#testregex-string
const scrTypes = enableTypeScript ? "jt" : "j";
const testRegex = `(/_?_tests?_?_/.*|(\\.|\/)(test|spec))\\.[${scrTypes}]sx?$`;

const rootDir = process.cwd();
const rootDir = xarcPath;

const jestDefaultConfig = {
rootDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ const webpackCovCfg = require(customCheck.getWebpackStartConfig(
"../webpack/webpack.config.coverage",
false
));
import { loadXarcOptions, detectXARCPath } from "../../lib/utils";

module.exports = function(config) {
const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);

karmaConf(config);
const settings = {
reporters: ["spec", "sonarqubeUnit", "coverage"],
Expand All @@ -28,12 +32,12 @@ module.exports = function(config) {
{ type: "lcov", subdir: "." },
{ type: "text", subdir: "." }
],
dir: Path.resolve("coverage", "client")
dir: Path.resolve(xarcPath, "coverage", "client")
},
sonarQubeUnitReporter: {
sonarQubeVersion: "5.x",
outputFile: "gunit.xml",
outputDir: Path.resolve("coverage", "client"),
outputDir: Path.resolve(xarcPath, "coverage", "client"),
useBrowserName: false
}
};
Expand Down
5 changes: 4 additions & 1 deletion packages/xarc-app-dev/src/config/karma/karma.conf.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ export {};
const loadUserConfig = require("./util/load-user-config");
const Path = require("path");
const browserSettings = require("./browser-settings");
import { loadXarcOptions, detectXARCPath } from "../../lib/utils";

module.exports = function(config) {
const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);
const settings = {
frameworks: ["mocha"],
reporters: ["spec"],
basePath: process.cwd(), // repository root.
basePath: xarcPath, // repository root.
files: [
// Test bundle (must be created via `npm run dev|server-test`)
"http://127.0.0.1:3001/assets/bundle.js"
Expand Down
13 changes: 9 additions & 4 deletions packages/xarc-app-dev/src/config/karma/karma.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const customCheck = require("@xarc/webpack/lib/util/custom-check");
const loadUserConfig = require("./util/load-user-config");
const browserSettings = require("./browser-settings");
const loadElectrodeDll = require("./util/load-electrode-dll");
import { loadXarcOptions, detectXARCPath } from "../../lib/utils";

function getXarcOptPlugins() {
try {
Expand Down Expand Up @@ -54,7 +55,9 @@ function getArchetypeOptPlugins() {
let MAIN_PATH;

try {
MAIN_PATH = require.resolve(Path.resolve("test/karma-entry"));
const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);
MAIN_PATH = require.resolve(Path.resolve(xarcPath, "test/karma-entry"));
} catch (err) {
if (getXarcOptPlugins()) {
MAIN_PATH = require.resolve("./entry-xarc.js");
Expand Down Expand Up @@ -89,8 +92,10 @@ module.exports = function(config) {
console.error("ERROR: @xarc/opt-karma not found - running karma tests is not possible");
plugins = [];
}
const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);
const settings = {
basePath: process.cwd(),
basePath: xarcPath,
frameworks: ["mocha", "intl-shim"],
files: DLL_PATHS.concat(MAIN_PATH),
plugins,
Expand Down Expand Up @@ -123,12 +128,12 @@ module.exports = function(config) {
{ type: "lcov", subdir: "." },
{ type: "text", subdir: "." }
],
dir: Path.resolve("coverage", "client")
dir: Path.resolve(xarcPath, "coverage", "client")
},
sonarQubeUnitReporter: {
sonarQubeVersion: "5.x",
outputFile: "gunit.xml",
outputDir: Path.resolve("coverage", "client"),
outputDir: Path.resolve(xarcPath, "coverage", "client"),
useBrowserName: false
},
captureTimeout: 100000,
Expand Down
7 changes: 5 additions & 2 deletions packages/xarc-app-dev/src/config/load-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ export {};

const Path = require("path");
const optionalRequire = require("optional-require")(require);
import { loadXarcOptions, detectXARCPath } from "../lib/utils";

function checkTopDevArchetype(devArchName) {
const topPkg = optionalRequire(Path.resolve("package.json"));
const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);
const topPkg = optionalRequire(Path.resolve(xarcPath, "package.json"));
if (topPkg && topPkg.name === devArchName) {
// In case @xarc/app is being used for test/dev in the -dev archetype
// resolve config/archetype in @xarc/app-dev's own dir
return optionalRequire(Path.resolve("config/archetype"));
return optionalRequire(Path.resolve(xarcPath, "config/archetype"));
} else {
return optionalRequire(`${devArchName}/config/archetype`);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/xarc-app-dev/src/config/opt2/xarc-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ export type XarcOptions = {
* options related to babel transpiler
*/
babelOptions?: BabelOptions;

/**
* option for app cwd to be used from xarc-options
jchip marked this conversation as resolved.
Show resolved Hide resolved
*/
XARC_CWD?: string;
};
11 changes: 8 additions & 3 deletions packages/xarc-app-dev/src/config/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const utils = require("../lib/utils");
const _ = require("lodash");
const xenvConfig = require("xenv-config");
const makeAppMode = require("@xarc/app/lib/app-mode");
import { loadXarcOptions, detectXARCPath } from "../lib/utils";

export function checkOptArchetypeInAppDep(dependencies, isDev = undefined) {
const options = dependencies
Expand Down Expand Up @@ -47,9 +48,11 @@ export function checkOptArchetypeInAppDep(dependencies, isDev = undefined) {
}

export const getUserConfigOptions = (packageNames, devPackageNames) => {
const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);
return {
reactLib: "react",
...optionalRequire(Path.resolve("archetype/config"), { default: {} }).options,
...optionalRequire(Path.resolve(xarcPath, "archetype/config"), { default: {} }).options,
//
// Check for any optional archetype in application's devDependencies or dependencies
//
Expand All @@ -69,7 +72,9 @@ export function getDefaultArchetypeOptions() {
// and devDependencies for modules that enable add on features.
// Basically any package named electrode-archetype-opt-* or @xarc/opt-*
//
const appPkg = optionalRequire(Path.resolve("package.json")) || {
const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);
const appPkg = optionalRequire(Path.resolve(xarcPath, "package.json")) || {
dependencies: {},
devDependencies: {}
};
Expand All @@ -79,7 +84,7 @@ export function getDefaultArchetypeOptions() {
const { myPkg: pkg } = utils.getMyPkg();

return {
dir: Path.resolve(__dirname, ".."),
dir: Path.resolve(xarcPath,__dirname, ".."),
pkg,
options: getUserConfigOptions(packageNames, devPackageNames),
prodDir: constants.PROD_DIR,
Expand Down
6 changes: 5 additions & 1 deletion packages/xarc-app-dev/src/lib/app-dev-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
WEBPACK_EVENT_STATS
} from "./dev-admin/webpack-dev-relay";

import { loadXarcOptions, detectXARCPath } from "./utils";

class AppDevMiddleware {
webpackDev: any;

Expand Down Expand Up @@ -43,7 +45,9 @@ class AppDevMiddleware {
if (!_.isEmpty(data.refreshModules)) {
data.refreshModules.forEach(m => {
try {
const moduleFullPath = require.resolve(Path.resolve(m));
const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);
const moduleFullPath = require.resolve(Path.resolve(xarcPath, m));
delete require.cache[moduleFullPath];
} catch (err) {
//
Expand Down
14 changes: 7 additions & 7 deletions packages/xarc-app-dev/src/lib/babel-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ export {};
*/
const Path = require("path");

import { loadXarcOptions } from "../lib/utils";
import { loadXarcOptions, detectXARCPath } from "../lib/utils";

const serverDir = process.argv[2] || "src/server";

let start;

const xarcOptions = loadXarcOptions();
const xarcPath = detectXARCPath(xarcOptions.options.XARC_CWD);
try {
// Try to load user's dev.js under src/server
start = require(Path.resolve(serverDir, "dev.js"));
start = require(Path.resolve(xarcPath, serverDir, "dev.js"));
} catch (e) {
const xarcOptions = loadXarcOptions();
const cwdNM = Path.resolve("node_modules");
const cwd = process.cwd();
const cwdNM = Path.resolve(xarcPath, "node_modules");
const cwd = xarcPath;

// fallback to default action that loads babel-register and then requires
// src/server, under which there should be an index.js file.
Expand All @@ -44,7 +44,7 @@ try {
cache: true
});

const fullServerDir = Path.resolve(serverDir);
const fullServerDir = Path.resolve(xarcPath, serverDir);

start = require(fullServerDir);
}
Expand Down
Loading