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

Refactor/scripts standalone #2035

Merged
merged 23 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
03c98dd
chore: add nx dep
chrismclarke Dec 16, 2022
8752ba8
feat: add nx to project
chrismclarke Dec 16, 2022
c9a9b64
Merge branch 'master' of https://github.com/IDEMSInternational/parent…
chrismclarke Aug 10, 2023
c175c81
chore: bump nx version and re-init
chrismclarke Aug 10, 2023
4ba823e
Merge branch 'refactor/workflows' of https://github.com/IDEMSInternat…
chrismclarke Aug 16, 2023
145671f
fix: cordova-res import and build script
chrismclarke Aug 16, 2023
c813d74
fix: remove direct ts invocation to support build
chrismclarke Aug 17, 2023
9e2ec8b
refactor: shared exports
chrismclarke Aug 17, 2023
ff7bc86
chore: data-models code tidying
chrismclarke Aug 17, 2023
696c5d6
chore: remove deprecated package
chrismclarke Aug 17, 2023
46f7572
refactor: scripts standalone updates
chrismclarke Aug 17, 2023
c3e18a8
Merge branch 'master' into refactor/scripts-standalone
chrismclarke Aug 18, 2023
e0686de
Merge branch 'master' of https://github.com/IDEMSInternational/parent…
chrismclarke Aug 23, 2023
fee2332
chore: code tidying
chrismclarke Aug 23, 2023
bdfb127
chore: remove nx integration
chrismclarke Aug 23, 2023
6ffd105
chore: code tidying
chrismclarke Aug 23, 2023
8e59e4d
chore: restore angular json
chrismclarke Aug 23, 2023
4130a74
feat: script version checking
chrismclarke Aug 23, 2023
77a55da
Merge branch 'master' of https://github.com/IDEMSInternational/parent…
chrismclarke Aug 24, 2023
82d0eee
fix: standalone app-data child spawn
chrismclarke Aug 24, 2023
0383308
chore: remove deprecated workflow
chrismclarke Aug 24, 2023
ed076b8
chore: bump scripts version
chrismclarke Aug 24, 2023
f7beb77
chore: remove deprecated workflow
chrismclarke Aug 24, 2023
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
6 changes: 3 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"Syler.sass-indented",
"Angular.ng-template"
"Angular.ng-template",
]
}
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"compodoc:generate": "compodoc --tsconfig tsconfig.docs.json --theme material --assetsFolder 'documentation/docs/assets' --output documentation/docs/generated --disablePrivate --disableLifeCycleHooks",
"compodoc:serve": "yarn compodoc:generate --serve --watch --open",
"scripts": "yarn workspace scripts start",
"workflow": "yarn scripts workflow run",
"workflow": "yarn workspace scripts start workflow run",
"server": "yarn workspace server",
"translations": "yarn workspace translations start",
"test:workspaces": "yarn workspace shared test && yarn workspace scripts test",
Expand Down Expand Up @@ -69,7 +69,6 @@
"bootstrap-datepicker": "^1.10.0",
"capacitor-blob-writer": "^1.1.14",
"clone": "^2.1.2",
"cordova-res": "^0.15.4",
"core-js": "^3.27.1",
"data-models": "workspace:*",
"date-fns": "^2.22.1",
Expand Down Expand Up @@ -110,6 +109,8 @@
"devDependencies": {
"@angular-devkit/architect": "0.1500.4",
"@angular-devkit/build-angular": "~15.0.4",
"@angular-devkit/core": "~15.0.4",
"@angular-devkit/schematics": "~15.0.4",
"@angular-eslint/builder": "15.2.1",
"@angular-eslint/eslint-plugin": "15.2.1",
"@angular-eslint/eslint-plugin-template": "15.2.1",
Expand All @@ -123,6 +124,8 @@
"@compodoc/compodoc": "^1.1.19",
"@ionic/angular-toolkit": "^7.0.0",
"@ionic/cli": "^6.18.0",
"@schematics/angular": "~15.0.4",
"@swc/helpers": "^0.5.1",
"@types/clone": "^2.1.1",
"@types/howler": "^2.2.2",
"@types/intro.js": "^3.0.1",
Expand Down Expand Up @@ -156,7 +159,7 @@
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"lint-staged": "^13.0.3",
"prettier": "2.4.1",
"prettier": "^2.6.2",
"typescript": "4.8.4"
},
"lint-staged": {
Expand Down
5 changes: 0 additions & 5 deletions packages/actions/lib/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ async function writeActionOutput(
console.log(chalk.blue("\nAction created successfully\n"), filepath);
}

if (require.main === module) {
// when running direct assume no deployment configured
setupActions({} as any);
}

/**
* Generate a local yml tag used to store metadata
* @returns tag representation of action config metadata, e.g.
Expand Down
4 changes: 2 additions & 2 deletions packages/data-models/flowTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint @typescript-eslint/sort-type-constituents: "warn" */

import type { IDataPipeOperation } from "shared/src/models/dataPipe/types";
import type { IDataPipeOperation } from "shared";
import type { IAppConfig } from "./appConfig";

/*********************************************************************************************
Expand Down Expand Up @@ -398,7 +398,7 @@ export namespace FlowTypes {
export interface TemplateRowAction {
/** actions have an associated trigger */
trigger: TemplateRowActionTrigger;
action_id: typeof ACTION_ID_LIST[number];
action_id: (typeof ACTION_ID_LIST)[number];
args: any[]; // should be boolean | string, but breaks type-checking for templates;
params?: any; // additional params also used by args (does not require position argument)
// TODO - CC 2022-04-29 - ideally args should be included as part of params
Expand Down
3 changes: 0 additions & 3 deletions packages/data-models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"name": "data-models",
"version": "1.0.0",
"description": "",
"files": [
"dist"
],
"main": "./index.ts",
"types": "./index.ts",
"dependencies": {
Expand Down
6 changes: 6 additions & 0 deletions packages/scripts/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parserOptions": {
"sourceType": "module",
"ecmaVersion": "latest"
}
}
1 change: 1 addition & 0 deletions packages/scripts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ config/*
!config/public.key
!config/*.enc
build
dist
exec

test/data/cache
Expand Down
65 changes: 31 additions & 34 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,57 @@
# App Scripts

The app scripts are designed to automated various aspects of the development and deployment cycle.
The consist of a set of `commands` that are executed within an interactive CLI, alongside a base set of reusable `tasks`

Most scripts require additional configuration files which are not publically available within this repo.
To use the scripts you should first contact the development team for the required configurations.
Scripts also act as a wrapper around the `workflows` package, which can be used to execute series of commands

## Required Configuration

In order to run most scripts require specific configuration files which are stored as encrypted in the `config` folder. In order to decrypt the files you must place the `private.key` file obtained from one of the repo admin in the folder. Files will automatically decrypt on run.

## Running scripts from this folder

Scripts may be added to the `package.json` and can also be listed in the default `index.ts` file which
is called via `yarn start`. E.g.
## Running scripts
Both scripts and workflows are called via an interactive CLI

**Runtime**
Scripts can be executed directly from source typescript files using utility functions defined in the root package.json
```sh
yarn scripts [command-name]
```
yarn start
```sh
yarn workflow [workflow-name]
```
This will compile typescript and execute at runtime (slower process but scripts always up-to-date)

will call the interactive cli script selection
**NOTE** - this method will be deprecated in the future in favor of always running
prebuild

**Prebuild**
It is also possible to pre-compile and package the scripts for direct execution from `bin`

```sh
yarn app-scripts [command-name]
```
yarn version

or to run a pre-configured workflow
```sh
yarn app-workflow [workflow-name]
```

will call the version script
Both of these shorthand methods are exposed via the `bin` folder of this workspace

## Running scripts from parent folder
The methods include a check to see if the relevant scripts workspace has been prebuilt
(based on scripts `package.json` version number), building only if updated.

If calling scripts from the main parent repo, all calls should be prefixed with `scripts`, i.e.
If for any reason manual building is required, this can be achieved by the command

```sh
yarn workspace scripts build
```
yarn scripts
```

will call the interactive cli script selection

```
yarn scripts version
```

will call the version script

## Developing scripts

To easy development, an additional `dev` script has been created that will start a
nodemon server, live-reloading the chosen script whenever an input `.ts` file changes.

```
yarn dev
```

will run live-reload of the main start scripts

```
yarn dev version
```sh
yarn workspace scripts dev [name]
```

will run live-reload of the version script
will run live-reload of the named script
18 changes: 18 additions & 0 deletions packages/scripts/bin/app-scripts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node

"use strict";

const { resolve } = require("path");
const { ensureBuild } = require("./ensureBuild");
const scriptsVersion = require("../package.json").version;

process.title = `app-scripts-${scriptsVersion}`;
console.log(`[Scripts ${scriptsVersion}]`);

const execPath = resolve(__dirname, "../dist/index.js");

ensureBuild();

const { program } = require(execPath);

program.parseAsync(process.argv);
22 changes: 22 additions & 0 deletions packages/scripts/bin/app-workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node

"use strict";

const { resolve } = require("path");
const { ensureBuild } = require("./ensureBuild");

// Utility method to allow calling workflow (via scripts workflow run)
// Call via `yarn workflow`

process.title = "app-workflow";

const execPath = resolve(__dirname, "../dist/index.js");

ensureBuild();

const { program } = require(execPath);

// add extra commands for workflow run
process.argv.splice(2, 0, "workflow", "run");

program.parseAsync(process.argv);
27 changes: 27 additions & 0 deletions packages/scripts/bin/ensureBuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { spawnSync } = require("child_process");
const { existsSync } = require("fs");

const { resolve } = require("path");
const scriptsVersion = require("../package.json").version;
const execPath = resolve(__dirname, "../dist/index.js");

/**
* Ensure scripts are built, using package.json version from src and dist to
* compare. Could be replaced in future with nx caching
*/
exports.ensureBuild = () => {
// skip build if workspace and dist package.json version numbers match
if (existsSync(execPath)) {
const srcPackageJsonPath = resolve(__dirname, "../package.json");
const distPackageJsonPath = resolve(__dirname, "../dist/package.json");
if (existsSync(srcPackageJsonPath) && existsSync(distPackageJsonPath)) {
const srcVersion = require(srcPackageJsonPath).version;
const distVersion = require(distPackageJsonPath).version;
if (srcVersion === distVersion) {
return;
}
}
}
console.log(`\nBuilding scripts v${scriptsVersion}...\n`);
spawnSync("yarn build", { cwd: resolve(__dirname, "../"), shell: true, stdio: "inherit" });
};
82 changes: 82 additions & 0 deletions packages/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { spawnSync } from "child_process";
import { copyFileSync } from "fs";
import { resolve } from "path";
import * as tsup from "tsup";

import pkgJson from "./package.json";

/**
* Compile Typescript to JS
* Whilst this can be done automatically via tsup there seem to be some issues
* with module formats, so just manually compile (for now)
*/
function compileScriptsTs() {
return spawnSync("tsc --project tsconfig.build.json", { shell: true, stdio: "inherit" });
}

/**
* Create a single bundle using esbuild
* By default this will bundle all src code and node_modules into single file (with tree shaking)
* This is required to allow execution of JS with references to workspace packages (e.g. shared),
* which would otherwise be unresolved
*/
function createBuildBundle() {
// Use tsup which wraps esbuild and adds enhancements such as cleaning dist folder
const options: tsup.Options = {
name: "scripts",
splitting: false,
sourcemap: true,
clean: true,
entry: ["build/commands/index.js"],
format: ["cjs"],
target: "node18",

// NOTE - this is the default outDir, but important to ensure it sits
// at the same level of nesting as 'src' so file paths relative to __dirname
// still calculate correctly from compiled code (dist/index.js) as src (src/paths.ts)
outDir: "dist",

// This is additional tree-shaking via rollup on top of standard esbuild
// It appears prone to memory leaks/issues so disabled for now
treeshake: false,

// HACK - by default tsup leaves all imports as node_modules import,
// however as we want a single executable and to avoid esm/cjs issues
// include all external dependencies inlined into build

noExternal: Object.keys(pkgJson.dependencies),

// Sharp is required by cordova-res, however used .node binary files depending on system
// This isn't compatible with single-file bundling, so leave as external
// https://github.com/evanw/esbuild/issues/1051

// NOTE - this means the associated asset action will not work unless installed globally
// TODO - test statement above and document

// Additionally exclude pnpapi as directed by build warning output
external: ["sharp", "pnpapi"],
};

// TODO - prod build changes
let production = false;
if (production) {
options.sourcemap = false;
options.minify = true;
}

return tsup.build(options);
}

/** Copy src package.json to dist folder for reference and versioning */
function copyPackageJson() {
const src = resolve(__dirname, "package.json");
const target = resolve(__dirname, "dist", "package.json");
copyFileSync(src, target);
}

async function build() {
compileScriptsTs();
await createBuildBundle();
copyPackageJson();
}
build();
Loading