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

enhance/enterprise build #3306

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions bootstrap/scripts/buildPatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ EXT_TARGET=dendron
if [ $SCRIPT_EXT_TARGET = "nightly" ]; then
EXT_TARGET=nightly
fi
if [ $SCRIPT_EXT_TARGET = "enterprise" ]; then
EXT_TARGET=enterprise
fi

if [ -z $FAST ]; then
LOG_LEVEL=info $DENDRON_CLI dev build --upgradeType $UPGRADE_TYPE --publishEndpoint $PUBLISH_ENDPOINT --extensionTarget $EXT_TARGET
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"build:patch:local": "cross-env UPGRADE_TYPE=patch PUBLISH_ENDPOINT=local USE_IN_MEMORY_REGISTRY=1 ./bootstrap/scripts/buildPatch.sh",
"build:patch:local:ci": "cross-env UPGRADE_TYPE=patch PUBLISH_ENDPOINT=local BUILD_ENV=ci USE_IN_MEMORY_REGISTRY=1 ./bootstrap/scripts/buildPatch.sh",
"build:patch:local:ci:nightly": "cross-env UPGRADE_TYPE=patch PUBLISH_ENDPOINT=local BUILD_ENV=ci USE_IN_MEMORY_REGISTRY=1 EXT_TARGET=nightly ./bootstrap/scripts/buildPatch.sh",
"build:patch:local:ci:enterprise": "cross-env UPGRADE_TYPE=patch PUBLISH_ENDPOINT=local BUILD_ENV=ci USE_IN_MEMORY_REGISTRY=1 EXT_TARGET=enterprise ./bootstrap/scripts/buildPatch.sh",
"build:patch:remote": "cross-env UPGRADE_TYPE=patch PUBLISH_ENDPOINT=remote ./bootstrap/scripts/buildPatch.sh",
"build:patch:remote:ci": "cross-env UPGRADE_TYPE=patch PUBLISH_ENDPOINT=remote BUILD_ENV=ci ./bootstrap/scripts/buildPatch.sh",
"build:minor:local": "cross-env UPGRADE_TYPE=minor PUBLISH_ENDPOINT=local ./bootstrap/scripts/buildPatch.sh",
Expand Down
9 changes: 2 additions & 7 deletions packages/dendron-cli/src/commands/devCLICommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ export class DevCLICommand extends CLICommand<CommandOpts, CommandOutput> {
this.print("sync assets...");
await this.syncAssets(opts);

this.print("prep repo...");
await BuildUtils.prepPluginPkg();
this.print(`prep repo... extensionTarget: ${opts.extensionTarget}`);
await BuildUtils.prepPluginPkg(opts.extensionTarget);

if (!shouldPublishLocal) {
this.print(
Expand All @@ -468,11 +468,6 @@ export class DevCLICommand extends CLICommand<CommandOpts, CommandOutput> {
this.print("compiling plugin...");
await BuildUtils.compilePlugin(opts);

if (opts.extensionTarget === ExtensionTarget.NIGHTLY) {
this.print("modifying plugin manifest for nightly target...");
await BuildUtils.prepPluginPkg(ExtensionTarget.NIGHTLY);
}

this.print("package deps...");
await BuildUtils.packagePluginDependencies(opts);

Expand Down
48 changes: 39 additions & 9 deletions packages/dendron-cli/src/utils/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* eslint-disable no-console */
import { DendronError, error2PlainObject } from "@dendronhq/common-all";
import {
assertUnreachable,
DendronError,
error2PlainObject,
} from "@dendronhq/common-all";
import { createLogger, findUpTo } from "@dendronhq/common-server";
import execa from "execa";
import fs from "fs-extra";
Expand All @@ -16,6 +20,7 @@ type PkgJson = {
repository: PkgRepository;
devDependencies: { [key: string]: string };
icon: string;
license: string;
};

type PkgRepository = {
Expand All @@ -39,6 +44,7 @@ export enum PublishEndpoint {
export enum ExtensionTarget {
DENDRON = "dendron",
NIGHTLY = "nightly",
ENTERPRISE = "enterprise",
}

const LOCAL_NPM_ENDPOINT = "http://localhost:4873";
Expand Down Expand Up @@ -193,18 +199,39 @@ export class BuildUtils {
let version;
let description;
let icon;

if (target === ExtensionTarget.NIGHTLY) {
version = await this.getIncrementedVerForNightly();
description =
"This is a prerelease version of Dendron that may be unstable. Please install the main dendron extension instead.";
icon = "media/logo-bw.png";
let license: string = "GPLv3";
let name: string;
switch (target) {
case ExtensionTarget.DENDRON: {
name = target.toString();
break;
}
case ExtensionTarget.NIGHTLY: {
name = target.toString();
version = await this.getIncrementedVerForNightly();
description =
"This is a prerelease version of Dendron that may be unstable. Please install the main dendron extension instead.";
icon = "media/logo-bw.png";
break;
}
case ExtensionTarget.ENTERPRISE: {
name = `dendron-enterprise`;
version = await this.getIncrementedVerForNightly();
description = "Dendron - Enterprise Version";
license =
"see license in https://github.com/dendronhq/dendron/wiki/Enterprise-EULA";
break;
}
default: {
assertUnreachable(target);
}
}

this.updatePkgMeta({
pkgPath,
name: target.toString(),
displayName: target.toString(),
name,
license,
displayName: name,
description,
main: "./dist/extension.js",
repository: {
Expand Down Expand Up @@ -430,11 +457,13 @@ export class BuildUtils {
main,
repository,
version,
license,
icon,
}: {
pkgPath: string;
name: string;
displayName: string;
license: string;
} & Partial<PkgJson>) {
const pkg = fs.readJSONSync(pkgPath) as PkgJson;
pkg.name = name;
Expand All @@ -457,6 +486,7 @@ export class BuildUtils {
pkg.icon = icon;
}
pkg.main = "dist/extension.js";
pkg.license = license;
fs.writeJSONSync(pkgPath, pkg, { spaces: 4 });
}

Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Dendron sends out a weekly newsletter highlighting:

There are a variety of ways to connect with Dendron devs, contributors, and other members of the Dendron community:

- Join the [Dendron on Discord](https://link.dendron.so/discord)
- Join the [Dendron on Discord](https://link.dendron.so/discord)
- Follow [Dendron on Twitter (`@dendronhq`)](https://link.dendron.so/twitter)
- Checkout [Dendron on GitHub](https://link.dendron.so/github)
- Read the [Dendron Blog](https://blog.dendron.so/)
Expand Down Expand Up @@ -363,3 +363,5 @@ This project follows the [all-contributors](https://github.com/all-contributors/
Dendron is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3.

See [LICENSE](https://github.com/dendronhq/dendron/blob/master/LICENSE.md) and [NOTICE](https://github.com/dendronhq/dendron/blob/master/NOTICE.md) for more information.

Dendron Enterprise is distributed and licensed separately under the [Dendron Enterprise END-USER LICENSE AGREEMENT](https://github.com/dendronhq/dendron/wiki/Enterprise-EULA)
20 changes: 20 additions & 0 deletions packages/plugin-core/src/_extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import { DendronExtension, getDWorkspace, getExtension } from "./workspace";
import { TutorialInitializer } from "./workspace/tutorialInitializer";
import { WorkspaceActivator } from "./workspace/workspaceActivator";
import { WSUtils } from "./WSUtils";
import { SurveyUtils } from "./survey";
import _ from "lodash";

const MARKDOWN_WORD_PATTERN = new RegExp("([\\w\\.\\#]+)");
// === Main
Expand Down Expand Up @@ -353,6 +355,24 @@ export async function _activate(
showcase.showToast();
}, ONE_MINUTE_IN_MS);
}
if (ExtensionUtils.isEnterprise(context)) {
let resp: boolean | undefined | string = true;
while (!ExtensionUtils.hasValidLicense() && resp !== undefined) {
// eslint-disable-next-line no-await-in-loop
resp = await SurveyUtils.showEnterpriseLicenseSurvey();
}
if (resp === undefined) {
vscode.window.showInformationMessage(
"Please reload to enter your license key",
{
modal: true,
detail:
"Dendron will be inactive until you enter a license key. You can reload your vscode instance to be prompted again",
}
);
return false;
}
}
} else {
// ws not active
Logger.info({ ctx, msg: "dendron not active" });
Expand Down
43 changes: 37 additions & 6 deletions packages/plugin-core/src/survey.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ConfirmStatus, getStage, SurveyEvents } from "@dendronhq/common-all";
import { AnalyticsUtils } from "./utils/analytics";
import * as vscode from "vscode";
import _ from "lodash";
import { Logger } from "./logger";
import { resolve } from "path";
import { VSCodeUtils } from "./vsCodeUtils";
import {
InactvieUserMsgStatusEnum,
InitialSurveyStatusEnum,
LapsedUserSurveyStatusEnum,
MetadataService,
PriorTools,
} from "@dendronhq/engine-server";
import _ from "lodash";
import { resolve } from "path";
import * as vscode from "vscode";
import { Logger } from "./logger";
import { AnalyticsUtils } from "./utils/analytics";
import { VSCodeUtils } from "./vsCodeUtils";

export class DendronQuickInputSurvey {
opts: {
Expand Down Expand Up @@ -491,6 +491,37 @@ export class LapsedUserPlugDiscordSurvey extends DendronQuickPickSurvey {
}

export class SurveyUtils {
static async showEnterpriseLicenseSurvey() {
AnalyticsUtils.track("EnterpriseLicenseSurveyPrompted");
return vscode.window
.showInformationMessage(
"Welcome to Dendron! 🌱",
{
modal: true,
detail: "Please enter your enterprise license key to proceed",
},
{ title: "Enter" }
)
.then(async (resp) => {
if (resp === undefined) {
return undefined;
}
const licenseKey = await vscode.window.showInputBox({
ignoreFocusOut: true,
placeHolder: "license key",
prompt: "Please paste your license key here",
title: "License key",
});
const meta = MetadataService.instance();
if (licenseKey !== undefined) {
// @ts-ignore
meta.setMeta("enterpriseLicense", licenseKey);
return true;
}
return undefined;
});
}

/**
* Asks three questions about background, use case, and prior tools used.
*/
Expand Down
18 changes: 18 additions & 0 deletions packages/plugin-core/src/utils/ExtensionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,23 @@ export class ExtensionUtils {
return ext as vscode.Extension<any>;
}

static isEnterprise(context: vscode.ExtensionContext) {
// return context.extension.id === "dendron.@dendronhq/plugin-core";
return context.extension.id === "dendron.dendron-enterprise";
}

static hasValidLicense() {
// @ts-ignore
const enterpriseLicense = MetadataService.instance().getMeta()[
"enterpriseLicense"
] as string;
// TODO
if (!enterpriseLicense) {
return false;
}
return true;
}

static _TUTORIAL_IDS: Set<string> | undefined;
static getTutorialIds(): Set<string> {
if (_.isUndefined(ExtensionUtils._TUTORIAL_IDS)) {
Expand Down Expand Up @@ -399,6 +416,7 @@ export class ExtensionUtils {
const workspaceConfig = ConfigUtils.getWorkspace(dendronConfig);
const { workspaceFile, workspaceFolders } = vscode.workspace;
const trackProps = {
extensionId: ext.context.extension.id,
duration: durationReloadWorkspace,
noCaching: dendronConfig.noCaching || false,
numNotes,
Expand Down