add-cms
This commit is contained in:
15
source/admin/scripts/cache.js
Normal file
15
source/admin/scripts/cache.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const cache = require('cache-me-outside');
|
||||
|
||||
cache({
|
||||
cacheFolder: path.join('/', 'opt', 'build', 'cache', 'fast-cache'),
|
||||
contents: [
|
||||
{
|
||||
path: path.join(os.homedir(), '.cache', 'Cypress'),
|
||||
invalidateOn: __filename,
|
||||
command: 'echo noop',
|
||||
},
|
||||
],
|
||||
ignoreIfFolderExists: false,
|
||||
});
|
||||
109
source/admin/scripts/externals.js
Normal file
109
source/admin/scripts/externals.js
Normal file
@@ -0,0 +1,109 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* Takes a dash [-] separated name and makes it camel-cased
|
||||
* decap-cms-something to DecapCmsSomething
|
||||
* @param {} string
|
||||
*/
|
||||
function toGlobalName(name) {
|
||||
return `${name}`
|
||||
.replace(new RegExp(/[-_/]+/, 'g'), ' ')
|
||||
.replace(new RegExp(/[^\w\s]/, 'g'), '')
|
||||
.replace(
|
||||
new RegExp(/\s+(.)(\w+)/, 'g'),
|
||||
($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`,
|
||||
)
|
||||
.replace(new RegExp(/\s/, 'g'), '')
|
||||
.replace(new RegExp(/\w/), s => s.toUpperCase());
|
||||
}
|
||||
|
||||
const packages = fs.readdirSync(path.resolve(__dirname, '../packages'));
|
||||
|
||||
const packageExports = {};
|
||||
packages.map(name => {
|
||||
packageExports[name] = {
|
||||
root: `${toGlobalName(name)}`.split('.'),
|
||||
commonjs2: name,
|
||||
commonjs: name,
|
||||
amd: name,
|
||||
umd: name,
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
toGlobalName,
|
||||
externals: {
|
||||
...packageExports,
|
||||
lodash: {
|
||||
root: ['DecapCmsDefaultExports', 'Lodash'],
|
||||
commonjs2: 'lodash',
|
||||
commonjs: 'lodash',
|
||||
amd: 'lodash',
|
||||
umd: 'lodash',
|
||||
},
|
||||
'@emotion/react': {
|
||||
root: ['DecapCmsDefaultExports', 'EmotionCore'],
|
||||
commonjs2: '@emotion/react',
|
||||
commonjs: '@emotion/react',
|
||||
amd: '@emotion/react',
|
||||
umd: '@emotion/react',
|
||||
},
|
||||
'@emotion/styled': {
|
||||
root: ['DecapCmsDefaultExports', 'EmotionStyled'],
|
||||
commonjs2: '@emotion/styled',
|
||||
commonjs: '@emotion/styled',
|
||||
amd: '@emotion/styled',
|
||||
umd: '@emotion/styled',
|
||||
},
|
||||
codemirror: {
|
||||
root: 'CodeMirror',
|
||||
commonjs2: 'codemirror',
|
||||
commonjs: 'codemirror',
|
||||
amd: 'codemirror',
|
||||
umd: 'codemirror',
|
||||
},
|
||||
immutable: {
|
||||
root: ['DecapCmsDefaultExports', 'Immutable'],
|
||||
commonjs2: 'immutable',
|
||||
commonjs: 'immutable',
|
||||
amd: 'immutable',
|
||||
umd: 'immutable',
|
||||
},
|
||||
'prop-types': {
|
||||
root: ['DecapCmsDefaultExports', 'PropTypes'],
|
||||
commonjs2: 'prop-types',
|
||||
commonjs: 'prop-types',
|
||||
amd: 'prop-types',
|
||||
umd: 'prop-types',
|
||||
},
|
||||
'react-immutable-proptypes': {
|
||||
root: ['DecapCmsDefaultExports', 'ImmutablePropTypes'],
|
||||
commonjs2: 'react-immutable-proptypes',
|
||||
commonjs: 'react-immutable-proptypes',
|
||||
amd: 'react-immutable-proptypes',
|
||||
umd: 'react-immutable-proptypes',
|
||||
},
|
||||
react: {
|
||||
root: 'React',
|
||||
commonjs2: 'react',
|
||||
commonjs: 'react',
|
||||
amd: 'react',
|
||||
umd: 'react',
|
||||
},
|
||||
'react-dom': {
|
||||
root: 'ReactDOM',
|
||||
commonjs2: 'react-dom',
|
||||
commonjs: 'react-dom',
|
||||
amd: 'react-dom',
|
||||
umd: 'react-dom',
|
||||
},
|
||||
uuid: {
|
||||
root: ['DecapCmsDefaultExports', 'UUId'],
|
||||
commonjs2: 'uuid',
|
||||
commonjs: 'uuid',
|
||||
amd: 'uuid',
|
||||
umd: 'uuid',
|
||||
},
|
||||
},
|
||||
};
|
||||
77
source/admin/scripts/pack-and-install.sh
Normal file
77
source/admin/scripts/pack-and-install.sh
Normal file
@@ -0,0 +1,77 @@
|
||||
# Script to locally pack all Decap CMS packages and install them in a test project
|
||||
|
||||
TEST_PROJECT_PATH="$1"
|
||||
|
||||
if [ -z "$TEST_PROJECT_PATH" ]; then
|
||||
echo "Usage: ./pack-and-install.sh /path/to/test/project"
|
||||
echo "Example: ./pack-and-install.sh ../my-test-app"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$TEST_PROJECT_PATH" ]; then
|
||||
echo "Error: Test project directory '$TEST_PROJECT_PATH' does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Building all packages..."
|
||||
npm run build
|
||||
|
||||
echo "Packing all required packages..."
|
||||
|
||||
PACKAGES=(
|
||||
"decap-cms-lib-util"
|
||||
"decap-cms-lib-auth"
|
||||
"decap-cms-lib-widgets"
|
||||
"decap-cms-ui-default"
|
||||
"decap-cms-backend-aws-cognito-github-proxy"
|
||||
"decap-cms-backend-azure"
|
||||
"decap-cms-backend-bitbucket"
|
||||
"decap-cms-backend-git-gateway"
|
||||
"decap-cms-backend-gitea"
|
||||
"decap-cms-backend-github"
|
||||
"decap-cms-backend-gitlab"
|
||||
"decap-cms-backend-proxy"
|
||||
"decap-cms-backend-test"
|
||||
"decap-cms-widget-boolean"
|
||||
"decap-cms-widget-code"
|
||||
"decap-cms-widget-colorstring"
|
||||
"decap-cms-widget-datetime"
|
||||
"decap-cms-widget-file"
|
||||
"decap-cms-widget-image"
|
||||
"decap-cms-widget-list"
|
||||
"decap-cms-widget-map"
|
||||
"decap-cms-widget-markdown"
|
||||
"decap-cms-widget-number"
|
||||
"decap-cms-widget-object"
|
||||
"decap-cms-widget-relation"
|
||||
"decap-cms-widget-select"
|
||||
"decap-cms-widget-string"
|
||||
"decap-cms-widget-text"
|
||||
"decap-cms-editor-component-image"
|
||||
"decap-cms-locales"
|
||||
"decap-cms-core"
|
||||
"decap-cms-app"
|
||||
)
|
||||
|
||||
for pkg in "${PACKAGES[@]}"; do
|
||||
echo "Packing $pkg..."
|
||||
cd "packages/$pkg"
|
||||
npm pack
|
||||
cd ../..
|
||||
done
|
||||
|
||||
echo "All packages packed!"
|
||||
|
||||
# Build the install command with absolute paths
|
||||
INSTALL_PATHS=""
|
||||
for pkg in "${PACKAGES[@]}"; do
|
||||
TGZ_FILE=$(find "../decap-cms/packages/$pkg/" -name "*.tgz" -type f | head -1)
|
||||
if [ -n "$TGZ_FILE" ]; then
|
||||
INSTALL_PATHS="$INSTALL_PATHS \"$TGZ_FILE\""
|
||||
else
|
||||
echo "Warning: No .tgz file found for $pkg"
|
||||
fi
|
||||
done
|
||||
|
||||
cd "$TEST_PROJECT_PATH"
|
||||
eval "npm install $INSTALL_PATHS"
|
||||
10
source/admin/scripts/revert_publish.sh
Normal file
10
source/admin/scripts/revert_publish.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
publishCommit=$(git --no-pager log -1 --pretty=format:"%H" --grep="^chore(release): publish$")
|
||||
ref=$(git tag -l --points-at $publishCommit)
|
||||
echo "reverting publish commit $publishCommit"
|
||||
echo "deleting tags $ref"
|
||||
git push --delete origin $ref
|
||||
echo "reverting commit $publishCommit"
|
||||
git revert --no-edit $publishCommit
|
||||
echo "pushing changes"
|
||||
git push origin main
|
||||
echo "done reverting publish"
|
||||
180
source/admin/scripts/webpack.js
Normal file
180
source/admin/scripts/webpack.js
Normal file
@@ -0,0 +1,180 @@
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const FriendlyErrorsWebpackPlugin = require('@soda/friendly-errors-webpack-plugin');
|
||||
const { flatMap } = require('lodash');
|
||||
|
||||
const { toGlobalName, externals } = require('./externals');
|
||||
const pkg = require(path.join(process.cwd(), 'package.json'));
|
||||
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
const isTest = process.env.NODE_ENV === 'test';
|
||||
|
||||
function moduleNameToPath(libName) {
|
||||
return path.resolve(__dirname, '..', 'node_modules', libName);
|
||||
}
|
||||
|
||||
function rules() {
|
||||
return {
|
||||
js: () => ({
|
||||
test: /\.(ts|js)x?$/,
|
||||
exclude: /node_modules/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
rootMode: 'upward',
|
||||
},
|
||||
},
|
||||
}),
|
||||
css: () => [
|
||||
{
|
||||
test: /\.css$/,
|
||||
include: ['ol', 'react-toastify', 'codemirror'].map(moduleNameToPath),
|
||||
use: ['to-string-loader', 'css-loader'],
|
||||
},
|
||||
],
|
||||
svg: () => ({
|
||||
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
|
||||
exclude: [/node_modules/],
|
||||
use: 'svg-inline-loader',
|
||||
}),
|
||||
vfile: () => ({
|
||||
test: /node_modules\/vfile\/core\.js/,
|
||||
use: [
|
||||
{
|
||||
loader: 'imports-loader',
|
||||
options: {
|
||||
type: 'commonjs',
|
||||
imports: ['single process/browser process'],
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function plugins() {
|
||||
return {
|
||||
ignoreEsprima: () =>
|
||||
new webpack.IgnorePlugin({ resourceRegExp: /^esprima$/, contextRegExp: /js-yaml/ }),
|
||||
friendlyErrors: () => new FriendlyErrorsWebpackPlugin(),
|
||||
buffer: () =>
|
||||
new webpack.ProvidePlugin({
|
||||
Buffer: ['buffer', 'Buffer'],
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function stats() {
|
||||
if (isProduction) {
|
||||
return {
|
||||
builtAt: false,
|
||||
chunks: false,
|
||||
colors: true,
|
||||
entrypoints: false,
|
||||
errorDetails: false,
|
||||
hash: false,
|
||||
modules: false,
|
||||
timings: false,
|
||||
version: false,
|
||||
warnings: false,
|
||||
};
|
||||
}
|
||||
return {
|
||||
all: false,
|
||||
};
|
||||
}
|
||||
|
||||
const umdPath = path.resolve(process.cwd(), 'dist');
|
||||
const umdDirPath = path.resolve(process.cwd(), 'dist/umd');
|
||||
const cjsPath = path.resolve(process.cwd(), 'dist/cjs');
|
||||
|
||||
function targetOutputs() {
|
||||
console.log(`Building [${pkg.name}, library: ${toGlobalName(pkg.name)}]`);
|
||||
return {
|
||||
umd: {
|
||||
path: umdPath,
|
||||
filename: `${pkg.name}.js`,
|
||||
library: toGlobalName(pkg.name),
|
||||
libraryTarget: 'umd',
|
||||
libraryExport: toGlobalName(pkg.name),
|
||||
umdNamedDefine: true,
|
||||
globalObject: 'window',
|
||||
},
|
||||
umddir: {
|
||||
path: umdDirPath,
|
||||
filename: `index.js`,
|
||||
library: toGlobalName(pkg.name),
|
||||
libraryTarget: 'umd',
|
||||
libraryExport: toGlobalName(pkg.name),
|
||||
umdNamedDefine: true,
|
||||
globalObject: 'window',
|
||||
},
|
||||
cjs: {
|
||||
path: cjsPath,
|
||||
filename: 'index.js',
|
||||
library: toGlobalName(pkg.name),
|
||||
libraryTarget: 'window',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const umdExternals = Object.keys(pkg.peerDependencies || {}).reduce((previous, key) => {
|
||||
if (!externals[key]) throw `Missing external [${key}]`;
|
||||
previous[key] = externals[key] || null;
|
||||
return previous;
|
||||
}, {});
|
||||
|
||||
/**
|
||||
* Use [getConfig({ target:'umd' }), getConfig({ target:'cjs' })] for
|
||||
* getting multiple configs and add the new output in targetOutputs if needed.
|
||||
* Default: umd
|
||||
*/
|
||||
function baseConfig({ target = isProduction ? 'umd' : 'umddir' } = {}) {
|
||||
return {
|
||||
context: process.cwd(),
|
||||
mode: isProduction ? 'production' : 'development',
|
||||
entry: './src',
|
||||
output: targetOutputs()[target],
|
||||
module: {
|
||||
rules: flatMap(Object.values(rules()), rule => rule()),
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts', '.tsx', '.js', '.json'],
|
||||
fallback: { stream: require.resolve('stream-browserify') },
|
||||
},
|
||||
plugins: Object.values(plugins()).map(plugin => plugin()),
|
||||
devtool: isTest ? '' : 'source-map',
|
||||
target: 'web',
|
||||
|
||||
/**
|
||||
* Exclude peer dependencies from package bundles.
|
||||
*/
|
||||
externals:
|
||||
target.slice(0, 3) === 'umd'
|
||||
? umdExternals
|
||||
: (context, request, cb) => {
|
||||
const externals = Object.keys(pkg.peerDependencies || {});
|
||||
|
||||
function isPeerDep(dep) {
|
||||
return new RegExp(`^${dep}($|/)`).test(request);
|
||||
}
|
||||
|
||||
return externals.some(isPeerDep) ? cb(null, request) : cb();
|
||||
},
|
||||
stats: stats(),
|
||||
};
|
||||
}
|
||||
|
||||
function getConfig({ baseOnly = false } = {}) {
|
||||
if (baseOnly) {
|
||||
// decap-cms build
|
||||
return baseConfig({ target: 'umd' });
|
||||
}
|
||||
return [baseConfig({ target: 'umd' })];
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getConfig,
|
||||
rules: rules(),
|
||||
plugins: plugins(),
|
||||
};
|
||||
Reference in New Issue
Block a user